Skip to content

sudhir13s/Mistral-7B-Instruct-v0.2-CustomerSupport

Repository files navigation

Customer Support Auto-Resolution Model (Fine-Tuning)

This project demonstrates an end-to-end industry-grade workflow for fine-tuning a Large Language Model (LLM) to act as a Customer Support Specialist. By leveraging QLoRA (4-bit Quantization), we transform a general-purpose model into a policy-aware agent capable of generating structured JSON responses (Intent, Response, Action) for E-commerce and SaaS support workflows.


Interactive Demo & Model Hub


System Architecture

graph TD
    A(["Bitext Dataset<br/>Hugging Face"]):::data
    A -->|"Fetch & Format"| B(["src/data_prep.py<br/>Instruction Formatting"]):::process
    B -->|"INST JSONL"| C(["Instruction Tuning<br/>Chat Template"]):::process
    C -->|"QLoRA 4-bit"| D(["src/train.py<br/>SFTTrainer"]):::train
    D -->|"LoRA Adapter ~150MB"| E(["src/push_to_hub.py<br/>Model Card + Weights"]):::deploy
    E -->|"Push"| F(["Hugging Face Hub<br/>sudhir13s/mistral-7b-support-adapter"]):::hub
    F -->|"Load Adapter"| G(["app.py<br/>Gradio Demo"]):::demo

    classDef data fill:#7D5A2C,stroke:#6D4A1C,color:#fff,font-weight:bold
    classDef process fill:#3A6B96,stroke:#2A5B86,color:#fff
    classDef train fill:#5D4A8A,stroke:#4D3A7A,color:#fff,font-weight:bold
    classDef deploy fill:#2E7A5A,stroke:#1E6A4A,color:#fff
    classDef hub fill:#7A6528,stroke:#6A5518,color:#fff,font-weight:bold
    classDef demo fill:#8B3B4A,stroke:#7B2B3A,color:#fff
Loading

Key Technologies

  • Base Model: Mistral-7B-Instruct-v0.2 (Best-in-class 7B efficiency).
  • Optimization: QLoRA (NF4 Quantization + LoRA) to fit training into 16GB VRAM.
  • Library Stack: transformers, peft, trl (SFTTrainer), bitsandbytes.
  • Metrics: ROUGE-L (Structure) and BERTScore (Semantics).

Step-by-Step Implementation Guide

1. Environment Setup (Google Colab / Local)

Ensure you set your environment variables for secure authentication:

export HF_TOKEN="your_hf_write_token_here"
export HF_USER_NAME="your_hf_username"

Install dependencies:

pip install -r requirements.txt

2. Data Preparation

Fetch the dataset, apply Mistral templates, and inject synthetic resolution logic:

python src/data_prep.py

Output: data/processed/train.jsonl containing [INST] formatted instructions.

3. Fine-Tuning (The Heart of the Project)

Run the QLoRA training loop using parameters defined in configs/config.yaml.

python src/train.py

Tip

This script uses Paged AdamW and Gradient Checkpointing to ensure it runs on a single T4 GPU (free Colab tier).

4. Evaluation

Quantify the model's accuracy on the test set:

python src/evaluate.py

5. Deployment to Hugging Face

Push your adapters and a professionally generated Model Card to the Hub:

python src/push_to_hub.py

6. Interactive Demo

Launch the Gradio UI tailored for HF Spaces:

python app.py --hf_user $HF_USER_NAME

Project Structure

  • configs/config.yaml: Single Source of Truth for all hyperparameters.
  • src/data_prep.py: Data collection and instruction formatting logic.
  • src/train.py: The QLoRA training engine.
  • src/evaluate.py: ROUGE-L and BERTScore evaluation against the test split.
  • src/push_to_hub.py: Secure deployment utility.
  • app.py: Gradio web demo.
  • notebooks/Customer_Support_FineTuning_Colab.ipynb: Self-contained Colab notebook for end-to-end training.
  • Tech_notes.md: Quick-reference engineering notes on VRAM, LoRA, and hyperparameters.
  • Tech_notes_deep_dive.md: Researcher's deep-dive with detailed Mermaid diagrams on VRAM physics, QKV attention, QLoRA math, and evaluation metrics.

Note

Tech_notes_deep_dive.md uses Mermaid diagrams. To render them in VS Code, install the Markdown Preview Mermaid Support extension.

About

Mistral-7B-Instruct-v0.2-CustomerSupport

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors