A LoRA adapter that turns Qwen2.5-0.5B-Instruct into a classifier for bank customer messages. It sorts
each message into one of the 77 Banking77 intents
and replies with JSON:
"my card still hasn't arrived" → {"intent": "card_arrival"}
Code, evaluation, guardrails and write-up: github.com/muzammilahmad01/llm-finetune-banking77
Full Banking77 test set (3,080 messages). Both models use the same prompt and are quantized to Q4_K_M and served by Ollama.
| Model | Accuracy | Valid JSON | Invented labels | Latency |
|---|---|---|---|---|
| Qwen2.5-0.5B-Instruct, zero-shot | 25.2% | 97.1% | 25.2% | 0.146 s |
| + this adapter | 90.7% | 99.2% | 0.2% | 0.143 s |
No intent scores 0%; the zero-shot model had 20 at 0%.
The model was trained with the full list of 77 labels in the system prompt, and needs the same prompt at
inference. labels.json in this repo holds the labels in the right order.
import json
import torch
from huggingface_hub import hf_hub_download
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
REPO = "MuzammilAhmad/banking77-qwen2.5-0.5b-lora"
BASE = "Qwen/Qwen2.5-0.5B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(BASE)
model = AutoModelForCausalLM.from_pretrained(BASE, dtype=torch.float32)
model = PeftModel.from_pretrained(model, REPO).merge_and_unload().eval()
labels = json.load(open(hf_hub_download(REPO, "labels.json")))
SYSTEM_PROMPT = (
"You are an intent classifier for a banking customer-support assistant.\n"
"Classify the user's message into exactly one of these intents:\n\n"
+ "\n".join(labels)
+ "\n\nRespond with JSON only, no other text, in this exact format:\n"
'{"intent": "<one intent from the list above>"}'
)
def classify(text: str) -> str:
messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": text}]
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True,
return_tensors="pt", return_dict=True)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=30, do_sample=False)
return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(classify("my card still hasn't arrived")) # {"intent": "card_arrival"}
banking77-qwen-q4_k_m.gguf (380 MB) is the adapter merged into the base model and quantized to Q4_K_M.
This is the exact model behind the results above. The Modelfile adds the chat template and the
classifier prompt:
hf download MuzammilAhmad/banking77-qwen2.5-0.5b-lora banking77-qwen-q4_k_m.gguf --local-dir models
curl -O https://raw.githubusercontent.com/muzammilahmad01/llm-finetune-banking77/main/Modelfile
ollama create banking77-qwen -f Modelfile
ollama run banking77-qwen "my card still hasn't arrived" # {"intent": "card_arrival"}
The GitHub repo builds one 457 MB image with CPU-only Ollama, this model, the guardrails, a FastAPI API and a demo page:
git clone https://github.com/muzammilahmad01/llm-finetune-banking77 && cd llm-finetune-banking77
docker build -t bankingllm . && docker run -p 7860:7860 bankingllm # http://localhost:7860
| Method | QLoRA with Unsloth (base loaded in 4-bit during training) |
| LoRA | r = 16, alpha = 32, dropout 0.05, on q/k/v/o/gate/up/down projections |
| Trainable parameters | 8.8M (1.75%) |
| Data | 8,997 training and 1,002 validation messages (stratified split of the Banking77 train set, seed 42) |
| Schedule | 2 epochs, effective batch 16, learning rate 2e-4 cosine, max sequence length 576 |
| Loss | on the assistant answer only (prompt tokens masked) |
| Hardware | 1× T4 (Colab), 35 minutes |
| Final validation loss | 0.026 (no overfitting) |
The adapter was trained against Unsloth's 4-bit copy of the base model. The reported results come from
merging it into the full-precision Qwen/Qwen2.5-0.5B-Instruct, which is what adapter_config.json
points to.
unknown below a confidence threshold. They
catch 82.7% of off-topic messages and halve confident mistakes, from 9.3% to 4.4%.{"intent": "automatic_top_up}.
The label is almost always correct, so a strict parser should repair it rather than discard it.The adapter is released under Apache 2.0, the same license as the base model. It was trained on Banking77 (Casanueva et al., 2020, CC BY 4.0).
Qwen/Qwen2.5-0.5B-Instruct