MwSpace commited on
Commit
53e6b54
Β·
verified Β·
1 Parent(s): 2e472f0

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +276 -0
README.md ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - it
4
+ - en
5
+ license: apache-2.0
6
+ library_name: transformers
7
+ base_model: Qwen/Qwen3-4B-Instruct-2507
8
+ tags:
9
+ - lora
10
+ - fine-tuned
11
+ - banking
12
+ - regtech
13
+ - compliance
14
+ - rag
15
+ - tool-calling
16
+ - italian
17
+ - qwen3
18
+ pipeline_tag: text-generation
19
+ ---
20
+
21
+ # 🏦 RegTech-4B-Instruct
22
+
23
+ > **Fine-tuned for RAG-powered banking compliance β€” not general knowledge.**
24
+
25
+ A specialized [Qwen3-4B-Instruct](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) model fine-tuned to excel within a **Retrieval-Augmented Generation (RAG) pipeline** for Italian banking regulatory compliance.
26
+
27
+ This model doesn't try to memorize regulations β€” it's trained to **work with retrieved context**: follow instructions precisely, produce structured outputs, call compliance tools, and maintain the right tone and terminology when grounded on regulatory documents.
28
+
29
+ ---
30
+
31
+ ## 🎯 What This Model Does
32
+
33
+ This fine-tuning optimizes the model's **behavior within a RAG system**, not its factual knowledge. Specifically:
34
+
35
+ | Task | Description |
36
+ |---|---|
37
+ | πŸ“‹ **RAG Q&A** | Answer regulatory questions grounded on retrieved documents |
38
+ | πŸ”§ **Tool Calling** | KYC verification, risk scoring, PEP checks, SOS reporting |
39
+ | πŸ” **Query Expansion** | Rewrite user queries with regulatory terminology for better retrieval |
40
+ | 🧠 **Intent Detection** | Classify if a message needs document search or is conversational |
41
+ | πŸ“Š **Document Reranking** | Score candidate documents by relevance |
42
+ | πŸ“ **Structured JSON** | Topic extraction, metadata, impact analysis in JSON format |
43
+ | βš–οΈ **Impact Analysis** | Cross-reference external regulations against internal bank procedures |
44
+
45
+ ---
46
+
47
+ ## πŸ“ˆ Evaluation β€” LLM-as-Judge
48
+
49
+ Evaluated by **Claude Opus 4.6** (Anthropic) across 11 blind test scenarios. The judge compared base vs fine-tuned model outputs without knowing which was which.
50
+
51
+ ### πŸ† Head-to-Head
52
+
53
+ ```
54
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
55
+ β”‚ 🟒 Tuned Wins 7/11 (68.2%) β”‚
56
+ β”‚ πŸ”΄ Base Wins 3/11 (31.8%) β”‚
57
+ β”‚ βšͺ Ties 1/11 β”‚
58
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
59
+ ```
60
+
61
+ ### πŸ“Š Quality Scores (1–5)
62
+
63
+ | Criterion | Base | Tuned | Delta | |
64
+ |---|:---:|:---:|:---:|---|
65
+ | 🎯 Instruction Following | 3.64 | **4.55** | +0.91 | 🟒🟒🟒 |
66
+ | πŸ“Ž Context Adherence | 4.09 | **4.82** | +0.73 | 🟒🟒 |
67
+ | βœ… Accuracy | 4.18 | **4.64** | +0.46 | 🟒 |
68
+ | πŸ“ Format | 4.09 | **4.55** | +0.46 | 🟒 |
69
+ | πŸ—£οΈ Tone | 4.55 | **4.82** | +0.27 | 🟒 |
70
+ | **πŸ“Š Overall** | **4.11** | **4.68** | **+0.57** | **🟒** |
71
+
72
+ > The biggest gains are in **instruction following** (+0.91) and **context adherence** (+0.73) β€” exactly what matters when the model must follow retrieved regulatory context faithfully.
73
+
74
+ ### πŸ“‚ Results by Category
75
+
76
+ | Category | Base | Tuned | Tie |
77
+ |---|:---:|:---:|:---:|
78
+ | πŸ”§ Tool Use | 0 | **2** | 0 |
79
+ | 🚫 Refusal Handling | 0 | **1** | 1 |
80
+ | 🎨 Style & Tone | 0 | **1** | 0 |
81
+ | πŸ“€ Data Extraction | 0 | **1** | 0 |
82
+ | πŸ“‹ JSON Output | 1 | 1 | 0 |
83
+ | πŸ“– RAG Q&A | 1 | 1 | 0 |
84
+ | ⚠️ Edge Cases | 1 | 0 | 0 |
85
+
86
+ ---
87
+
88
+ ## πŸ’‘ Usage Examples
89
+
90
+ ### πŸ“‹ RAG Q&A β€” Answering from Retrieved Context
91
+
92
+ The model is designed to receive **retrieved regulatory documents as context** and answer based on them:
93
+
94
+ ```python
95
+ messages = [
96
+ {
97
+ "role": "system",
98
+ "content": """Sei un assistente per la compliance bancaria.
99
+ Rispondi SOLO basandoti sul contesto fornito.
100
+
101
+ <contesto_recuperato>
102
+ Art. 92 CRR - Gli enti soddisfano in qualsiasi momento i seguenti
103
+ requisiti: a) CET1 del 4,5%; b) Tier 1 del 6%; c) capitale totale dell'8%.
104
+ Il coefficiente Γ¨ calcolato come rapporto tra i fondi propri e
105
+ l'importo complessivo dell'esposizione al rischio.
106
+ </contesto_recuperato>"""
107
+ },
108
+ {
109
+ "role": "user",
110
+ "content": "Quali sono i requisiti minimi di capitale secondo il CRR?"
111
+ }
112
+ ]
113
+ ```
114
+
115
+ ### πŸ” Query Expansion β€” Improving RAG Retrieval
116
+
117
+ ```python
118
+ messages = [
119
+ {
120
+ "role": "system",
121
+ "content": "Riscrivi la query dell'utente in una versione piΓΉ ricca per migliorare il recupero documentale (RAG). Aggiungi termini tecnici e riferimenti normativi. Rispondi SOLO con il JSON richiesto."
122
+ },
123
+ {
124
+ "role": "user",
125
+ "content": "## QUERY ORIGINALE: [obblighi segnalazione operazioni sospette]"
126
+ }
127
+ ]
128
+
129
+ # Expected output:
130
+ # {"query": "obblighi segnalazione operazioni sospette SOS UIF D.Lgs. 231/2007
131
+ # art. 35 riciclaggio finanziamento terrorismo portale RADAR tempistiche
132
+ # invio indicatori anomalia"}
133
+ ```
134
+
135
+ ### πŸ”§ Tool Calling β€” Compliance Workflows
136
+
137
+ ```python
138
+ messages = [
139
+ {
140
+ "role": "system",
141
+ "content": """Sei un assistente operativo per la compliance.
142
+
143
+ <tools>
144
+ {"name": "calcola_scoring_rischio", "parameters": {...}}
145
+ {"name": "controlla_liste_pep", "parameters": {...}}
146
+ {"name": "verifica_kyc", "parameters": {...}}
147
+ </tools>
148
+
149
+ <contesto_recuperato>
150
+ Procedura AML-003: L'adeguata verifica rafforzata (EDD) deve essere
151
+ applicata per PEP, paesi ad alto rischio e profili con scoring > 60.
152
+ </contesto_recuperato>"""
153
+ },
154
+ {
155
+ "role": "user",
156
+ "content": "Devo aprire un conto per una societΓ  con sede a Dubai. Il legale rappresentante Γ¨ il sig. Al-Rashid."
157
+ }
158
+ ]
159
+
160
+ # The model will:
161
+ # 1. Call controlla_liste_pep for the representative
162
+ # 2. Call calcola_scoring_rischio based on risk factors
163
+ # 3. Recommend EDD procedure per AML-003, grounded on retrieved policy
164
+ ```
165
+
166
+ ### πŸ“Š Document Reranking
167
+
168
+ ```python
169
+ messages = [
170
+ {
171
+ "role": "system",
172
+ "content": "Valuta la rilevanza di ciascun candidato rispetto alla query. Restituisci solo i candidati rilevanti con score 0-100. Rispondi SOLO con il JSON richiesto."
173
+ },
174
+ {
175
+ "role": "user",
176
+ "content": '{"query": "requisiti CET1 fondi propri", "candidates": [{"id": "doc_001", "title": "Art. 92 CRR", "content": "..."}, {"id": "doc_002", "title": "DORA Art. 5", "content": "..."}]}'
177
+ }
178
+ ]
179
+
180
+ # Expected: {"matches": [{"id": "doc_001", "relevance": 95}]}
181
+ ```
182
+
183
+ ---
184
+
185
+ ## βš™οΈ Training Details
186
+
187
+ | | |
188
+ |---|---|
189
+ | 🧬 **Method** | LoRA β€” bf16 full precision (no quantization) |
190
+ | πŸ—οΈ **Base Model** | Qwen3-4B-Instruct-2507 |
191
+ | πŸ“¦ **Dataset** | 923 train / 102 eval samples |
192
+ | ⏱️ **Duration** | 11.9 minutes |
193
+
194
+ ### Hyperparameters
195
+
196
+ | Parameter | Value |
197
+ |---|---|
198
+ | LoRA Rank / Alpha | 16 / 32 |
199
+ | LoRA Dropout | 0.10 |
200
+ | Target Modules | q, k, v, o, gate, up, down proj |
201
+ | Learning Rate | 5e-6 (cosine scheduler) |
202
+ | Epochs | 3 |
203
+ | Effective Batch Size | 4 (2 Γ— 2 accum) |
204
+ | Max Sequence Length | 4096 |
205
+ | NEFTune Alpha | 5.0 |
206
+ | Warmup Ratio | 0.05 |
207
+
208
+ ### πŸ“‰ Training Metrics
209
+
210
+ | Metric | Value |
211
+ |---|---|
212
+ | Final Train Loss | 1.241 |
213
+ | Best Eval Loss | 1.191 (step 680/693) |
214
+ | Train/Eval Gap | 0.050 βœ… |
215
+
216
+ > Gap of 0.050 indicates **stable training with no overfitting**.
217
+
218
+ ---
219
+
220
+ ## πŸ“š Dataset Coverage
221
+
222
+ The training data covers the full lifecycle of a RAG-based compliance assistant:
223
+
224
+ | Category | Purpose |
225
+ |---|---|
226
+ | 🏷️ Title Generation | Generate conversation titles from user queries |
227
+ | πŸ” Query Expansion | Enrich queries with regulatory terms for better retrieval |
228
+ | 🧠 Intent Classification | Route queries to RAG vs conversational responses |
229
+ | πŸ“Š Document Reranking | Score retrieved documents by relevance |
230
+ | πŸ“ Topic Extraction | Extract main topics from regulatory text pages |
231
+ | πŸ“– Document Summarization | Summarize multi-page regulatory documents |
232
+ | βš–οΈ Relevance Filtering | Filter regulatory text relevant to banks |
233
+ | πŸ“… Metadata Extraction | Find application dates, issuing authorities |
234
+ | πŸ”§ Impact Analysis | Cross-reference regulations vs internal procedures |
235
+ | πŸ’¬ RAG Q&A + Tool Calling | Multi-turn compliance conversations with tools |
236
+
237
+ **Regulatory sources covered:** CRR/CRR3, DORA (UE 2022/2554), D.Lgs. 231/2007 (AML), D.Lgs. 385/1993 (TUB), Circolare 285, PSD2, MiFID II/MiFIR, D.P.R. 180/1950 and related Banca d'Italia provisions.
238
+
239
+ ---
240
+
241
+ ## πŸš€ Deployment
242
+
243
+ ### With vLLM
244
+ ```bash
245
+ vllm serve ./models/RegTech-4B-Instruct --dtype bfloat16
246
+ ```
247
+
248
+ ### With Transformers
249
+ ```python
250
+ from transformers import AutoModelForCausalLM, AutoTokenizer
251
+
252
+ model = AutoModelForCausalLM.from_pretrained("YOUR_REPO_ID", torch_dtype="bfloat16", device_map="auto")
253
+ tokenizer = AutoTokenizer.from_pretrained("YOUR_REPO_ID")
254
+
255
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
256
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
257
+ outputs = model.generate(**inputs, max_new_tokens=512)
258
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
259
+ ```
260
+
261
+ ---
262
+
263
+ ## ⚠️ Important Notes
264
+
265
+ - 🎯 **RAG-optimized** β€” trained to work with retrieved context, not to memorize regulations. Always provide relevant documents in the system prompt.
266
+ - 🏦 **Domain-specific** β€” optimized for Italian banking compliance. General capabilities may differ from the base model.
267
+ - βš–οΈ **Not legal advice** β€” a tool to assist compliance professionals, not a substitute for regulatory expertise.
268
+ - πŸ”§ **Tool schemas** β€” tool calling works best with the specific function signatures used during training.
269
+
270
+ ---
271
+
272
+ <p align="center">
273
+ Built with ❀️ for banking RAG<br>
274
+ <em>Fine-tuned with LoRA β€’ Evaluated by Claude Opus 4.6 β€’ Powered by Qwen3</em>
275
+ <em>Contact For Commercial Use: https://landing.2sophia.ai</em>
276
+ </p>