aryachakraborty commited on
Commit
5ba44f5
Β·
verified Β·
1 Parent(s): 2932e85

updated readme

Browse files
Files changed (1) hide show
  1. README.md +224 -134
README.md CHANGED
@@ -1,202 +1,292 @@
1
- ---
2
- base_model: Qwen/Qwen2.5-7B-Instruct
3
- library_name: peft
4
- ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
- ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
75
 
76
- ## Training Details
77
 
78
- ### Training Data
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
 
 
 
 
 
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
89
 
90
- [More Information Needed]
 
91
 
 
 
 
 
 
 
 
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
 
 
 
 
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
 
 
 
 
 
 
 
 
 
 
112
 
113
- [More Information Needed]
114
 
115
- #### Factors
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
 
121
- #### Metrics
 
 
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
126
 
127
- ### Results
128
 
129
- [More Information Needed]
130
 
131
- #### Summary
132
 
 
 
133
 
 
134
 
135
- ## Model Examination [optional]
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
 
 
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
 
 
 
 
 
154
 
155
- ### Model Architecture and Objective
156
 
157
- [More Information Needed]
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
 
 
 
 
 
 
 
162
 
163
- #### Hardware
164
 
165
- [More Information Needed]
166
 
167
- #### Software
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
- [More Information Needed]
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
 
 
 
 
 
 
174
 
175
- **BibTeX:**
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
 
 
 
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
200
- ### Framework versions
201
 
202
- - PEFT 0.12.0
 
 
 
 
 
1
+ # Qwen2.5-7B-Instruct β€” CFPB Banking Complaint Categorisation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ A domain-adapted large language model fine-tuned on the CFPB Consumer Complaint Database to automatically convert unstructured customer complaint narratives into structured ticket metadata for banking operations teams.
4
 
5
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ ## The Problem
8
 
9
+ Financial institutions process thousands of customer complaints daily across mobile apps, websites, contact centres, email, and regulatory portals. These complaints arrive as free-form text β€” often incomplete, ambiguous, or written by customers who do not know which banking product or issue category applies to their situation.
10
 
11
+ The result is predictable: complaints get routed to the wrong team, require manual review and reassignment, and take longer to resolve than they should. Traditional classification models handle one label at a time and struggle with the nuanced language of consumer finance. A rule-based keyword system breaks down the moment a customer phrases something slightly differently.
12
 
13
+ This model addresses that by treating complaint categorisation as a **structured generation task** β€” the model reads the complaint narrative and produces all four required ticket fields in a single inference step.
14
 
15
+ ---
16
 
17
+ ## What the Model Does
18
 
19
+ Given a customer complaint narrative, the model outputs a structured JSON object containing:
20
 
21
+ ```json
22
+ {
23
+ "product": "Checking or savings account",
24
+ "sub_product": "Checking account",
25
+ "issue": "Unauthorized transactions or other transaction problem",
26
+ "sub_issue": "Debit card issue"
27
+ }
28
+ ```
29
 
30
+ These four fields map directly to the CFPB Consumer Complaint taxonomy and can be consumed directly by complaint management systems, business rule engines, and routing workflows β€” no manual classification required.
31
 
32
+ ### Example
33
 
34
+ **Input complaint:**
35
+ > *"I reported fraudulent transactions on my debit card and the bank reversed my provisional credit without explaining the investigation outcome. I have been trying to reach someone for three weeks and keep getting transferred."*
36
 
37
+ **Model output:**
38
+ ```json
39
+ {
40
+ "product": "Checking or savings account",
41
+ "sub_product": "Checking account",
42
+ "issue": "Unauthorized transactions or other transaction problem",
43
+ "sub_issue": "Debit card issue"
44
+ }
45
+ ```
46
 
47
+ ---
48
 
49
+ ## Model Details
50
 
51
+ | Property | Value |
52
+ |----------|-------|
53
+ | Base model | `Qwen/Qwen2.5-7B-Instruct` |
54
+ | Fine-tuning method | LoRA (Low-Rank Adaptation) via PEFT |
55
+ | Training hardware | AMD Instinct MI300X (192 GB VRAM) |
56
+ | Training backend | ROCm 7.2.4 / HIP |
57
+ | Model precision | bfloat16 |
58
+ | Task type | Structured JSON generation (causal LM) |
59
+ | Output format | JSON with 4 fields: product, sub_product, issue, sub_issue |
60
 
61
+ ---
62
 
63
+ ## Training Configuration
64
 
65
+ ### LoRA Adapter
66
 
67
+ | Parameter | Value |
68
+ |-----------|-------|
69
+ | Rank (`r`) | 16 |
70
+ | Alpha | 32 |
71
+ | Dropout | 0.05 |
72
+ | Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj` |
73
+ | Trainable parameters | ~1% of total model parameters |
74
 
75
+ The base model weights are fully frozen. Only the LoRA adapter matrices are updated during training, making this efficient both in compute and storage β€” the saved adapter is significantly smaller than the full model.
76
 
77
+ ### Training Hyperparameters
78
 
79
+ | Parameter | Value |
80
+ |-----------|-------|
81
+ | Epochs | 5 (with early stopping, patience=3) |
82
+ | Batch size per device | 8 |
83
+ | Gradient accumulation steps | 4 |
84
+ | Effective batch size | 32 |
85
+ | Learning rate | 1e-4 |
86
+ | Optimiser | AdamW (PyTorch native) |
87
+ | LR scheduler | Linear |
88
+ | Precision | bf16 |
89
+ | Max sequence length | 1024 tokens |
90
 
91
+ Early stopping was applied with a patience of 3 evaluation checkpoints. Prior experiments on smaller model variants showed validation loss plateauing around epoch 2–3, so early stopping prevents wasted compute without sacrificing quality.
92
 
93
+ ### Dataset
94
 
95
+ **Source:** CFPB Consumer Complaint Database (formatted as multi-turn chat JSONL)
96
 
97
+ **Splits used:**
98
 
99
+ | Split | Size |
100
+ |-------|------|
101
+ | Train | Full dataset (no cap) |
102
+ | Validation | 500 |
103
+ | Test | 500 |
104
 
105
+ **Sampling strategy:** Training data was sampled using proportional stratification by `product Γ— issue` combination. This ensures that long-tail complaint categories β€” which would appear only once or twice in a random 500-sample draw β€” receive proportional representation. Without this, the model sees most issue labels fewer than 3 times, which is insufficient for reliable generation.
106
 
107
+ **Chat template:** Qwen's built-in `apply_chat_template` was used to format each example into a single training string with `<|im_start|>` / `<|im_end|>` special tokens. The assistant turn (the JSON output) was included in full β€” no generation prompt was added at training time.
108
 
109
+ ---
110
 
111
+ ## Inference with Constrained Decoding
112
 
113
+ At inference time, this model uses a **two-pass constrained decoding** approach:
114
 
115
+ 1. **Pass 1** β€” Standard greedy decoding generates the JSON output.
116
+ 2. **Pass 2** β€” Each field value is snapped to the nearest canonical CFPB label using TF-IDF cosine similarity (unigram + bigram features).
117
 
118
+ This matters because the CFPB taxonomy contains 80+ canonical issue strings with very similar phrasing. A model that generates *"unauthorized transaction"* when the canonical label is *"unauthorized transactions or other transaction problem"* would score zero on exact match β€” but is semantically correct. The constrained decoder corrects these surface-level mismatches without changing the underlying prediction.
119
 
120
+ Jaccard similarity was evaluated as an alternative snapping strategy but proved insufficient for near-duplicate labels (e.g., *"problem with fees"* vs *"other fee"*) where single-word differences produce high Jaccard overlap. TF-IDF on bigrams separates these reliably.
121
 
122
+ ---
123
 
124
+ ## Evaluation Results
125
 
126
+ Evaluated on 500 held-out test examples from the CFPB dataset. Baseline is the unmodified `Qwen2.5-7B-Instruct` base model with no fine-tuning.
127
 
128
+ ### Primary Metrics β€” Structured JSON Extraction
129
 
130
+ | Metric | Baseline | Fine-tuned | Ξ” |
131
+ |--------|----------|------------|---|
132
+ | Exact JSON Match | 0.0000 | 0.2280 | +0.2280 |
133
+ | Avg Field Accuracy | 0.0030 | 0.5925 | +0.5895 |
134
+ | Micro F1 | 0.0030 | 0.5925 | +0.5895 |
135
+ | Macro F1 | 0.0008 | 0.2395 | +0.2387 |
136
+ | Weighted F1 | 0.0059 | 0.5814 | +0.5755 |
137
 
138
+ **Per-field accuracy:**
 
 
 
 
139
 
140
+ | Field | Baseline | Fine-tuned | Ξ” |
141
+ |-------|----------|------------|---|
142
+ | product | 0.010 | **0.910** | +0.900 |
143
+ | sub_product | 0.002 | **0.628** | +0.626 |
144
+ | issue | 0.000 | **0.336** | +0.336 |
145
+ | sub_issue | 0.000 | **0.496** | +0.496 |
146
 
147
+ `product` accuracy of 91% is expected β€” the CFPB product taxonomy has around a dozen top-level categories and the model learns them well. `issue` at 33.6% reflects the genuine difficulty of the field: 80+ canonical strings with overlapping phrasing, many appearing infrequently even in the full training set.
148
 
149
+ ### Secondary Metrics β€” Generative Quality
150
 
151
+ These metrics measure output fluency and n-gram overlap. They are secondary to the structured metrics above, but confirm the model is generating coherent, well-formed text.
152
 
153
+ | Metric | Baseline | Fine-tuned | Ξ” |
154
+ |--------|----------|------------|---|
155
+ | ROUGE-1 | 0.4592 | 0.7035 | +0.2443 |
156
+ | ROUGE-2 | 0.2523 | 0.6049 | +0.3526 |
157
+ | ROUGE-L | 0.4258 | 0.6915 | +0.2657 |
158
+ | BLEU | 0.0003 | 0.1905 | +0.1902 |
159
+ | SacreBLEU | 19.77 | 65.07 | +45.30 |
160
+ | METEOR | 0.1133 | 0.6309 | +0.5176 |
161
 
162
+ The SacreBLEU jump from 19.77 to 65.07 and METEOR from 0.11 to 0.63 indicate the fine-tuned model is generating outputs that are not just structurally similar to references, but lexically aligned β€” which for this task means using the correct canonical CFPB terminology consistently.
163
 
164
+ ---
165
 
166
+ ## How to Use
167
+
168
+ ### Load the adapter
169
+
170
+ ```python
171
+ from peft import PeftModel
172
+ from transformers import AutoModelForCausalLM, AutoTokenizer
173
+ import torch
174
+
175
+ base_model_name = "Qwen/Qwen2.5-7B-Instruct"
176
+ adapter_path = "your-hf-username/qwen2.5-7b-cfpb-complaint-categorisation"
177
+
178
+ tokenizer = AutoTokenizer.from_pretrained(adapter_path)
179
+ base = AutoModelForCausalLM.from_pretrained(
180
+ base_model_name,
181
+ torch_dtype=torch.bfloat16,
182
+ device_map="auto",
183
+ )
184
+ model = PeftModel.from_pretrained(base, adapter_path)
185
+ model.eval()
186
+ ```
187
+
188
+ ### Run inference
189
+
190
+ ```python
191
+ def categorise_complaint(complaint_text: str, model, tokenizer) -> dict:
192
+ messages = [
193
+ {
194
+ "role": "system",
195
+ "content": (
196
+ "You are a banking complaint classification assistant. "
197
+ "Given a consumer complaint narrative, extract the CFPB ticket fields "
198
+ "as a JSON object with keys: product, sub_product, issue, sub_issue."
199
+ ),
200
+ },
201
+ {
202
+ "role": "user",
203
+ "content": complaint_text,
204
+ },
205
+ ]
206
+
207
+ prompt = tokenizer.apply_chat_template(
208
+ messages,
209
+ tokenize=False,
210
+ add_generation_prompt=True,
211
+ )
212
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
213
+
214
+ with torch.no_grad():
215
+ output = model.generate(
216
+ **inputs,
217
+ max_new_tokens=128,
218
+ do_sample=False,
219
+ pad_token_id=tokenizer.eos_token_id,
220
+ )
221
+
222
+ prompt_len = inputs["input_ids"].shape[1]
223
+ generated = tokenizer.decode(output[0][prompt_len:], skip_special_tokens=True)
224
+ return generated
225
+
226
+
227
+ complaint = """
228
+ I reported fraudulent transactions on my debit card and the bank reversed
229
+ my provisional credit without explaining the investigation outcome.
230
+ """
231
+
232
+ result = categorise_complaint(complaint, model, tokenizer)
233
+ print(result)
234
+ # {"product": "Checking or savings account", "sub_product": "Checking account",
235
+ # "issue": "Unauthorized transactions or other transaction problem",
236
+ # "sub_issue": "Debit card issue"}
237
+ ```
238
 
239
+ ---
240
 
241
+ ## Dependencies
242
 
243
+ ```
244
+ transformers==4.44.0
245
+ peft==0.12.0
246
+ accelerate==0.34.0
247
+ datasets==2.21.0
248
+ torch (ROCm-compatible build for AMD, or standard CUDA build)
249
+ scikit-learn
250
+ rouge-score
251
+ sacrebleu
252
+ nltk
253
+ ```
254
 
255
+ ---
256
 
257
+ ## Limitations
258
 
259
+ - **CFPB taxonomy only.** The model is trained on and constrained to CFPB Consumer Complaint Database labels. It is not a general-purpose complaint classifier and should not be used with complaint taxonomies from other regulatory bodies or internal systems without retraining.
260
+ - **Issue field accuracy.** The `issue` field (33.6% accuracy) is the weakest link. The CFPB issue taxonomy contains 80+ canonical strings with overlapping phrasing. Expanding training data and further tuning the constrained decoder are the most direct paths to improvement.
261
+ - **English language only.** All training data is in English. Performance on non-English complaints is untested and likely poor.
262
+ - **Context length.** Complaints longer than 1024 tokens will be truncated. Most CFPB complaints are well within this limit, but very long narratives may lose relevant context.
263
 
264
+ ---
265
 
266
+ ## Intended Use
267
 
268
+ This model is intended for use by:
269
+ - Banking operations teams automating first-touch complaint categorisation
270
+ - Compliance teams processing regulatory complaint filings
271
+ - Contact centre platforms routing incoming complaints before agent assignment
272
+ - Research teams studying LLM adaptation for financial NLP tasks
273
 
274
+ It is not intended for consumer-facing deployment without human review of outputs, or for use in jurisdictions where automated complaint classification decisions have legal or regulatory implications without appropriate oversight.
275
 
276
+ ---
277
 
278
+ ## Training Infrastructure
279
 
280
+ Trained on an AMD Instinct MI300X GPU (192 GB HBM3 VRAM) running ROCm 7.2.4. The training stack is fully ROCm-native β€” `bitsandbytes` (CUDA-only) is not used. Model precision is bfloat16, which is the native compute type for the CDNA3 architecture.
281
 
282
+ ---
283
 
284
+ ## Citation
285
 
286
+ If you use this model in research or production, please cite the CFPB Consumer Complaint Database as the data source:
 
287
 
288
+ ```
289
+ Consumer Financial Protection Bureau (CFPB)
290
+ Consumer Complaint Database
291
+ https://www.consumerfinance.gov/data-research/consumer-complaints/
292
+ ```