Text Generation
PEFT
Safetensors
Turkish
English
text-to-sql
turkish
banking
risk-management
lora
distillation
small-language-model
slm-rd
Eval Results (legacy)
Instructions to use eqlx-ai/tr-risk-sql-gemma-e4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use eqlx-ai/tr-risk-sql-gemma-e4b with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("google/gemma-4-E4B-it") model = PeftModel.from_pretrained(base_model, "eqlx-ai/tr-risk-sql-gemma-e4b") - Notebooks
- Google Colab
- Kaggle
slm-rd release
Browse files
README.md
CHANGED
|
@@ -17,13 +17,113 @@ model-index:
|
|
| 17 |
|
| 18 |
# tr-risk-sql-gemma-e4b
|
| 19 |
|
| 20 |
-
**
|
| 21 |
|
| 22 |
Can Demir · [eqlx.ai](https://eqlx.ai) · 2026-11
|
| 23 |
|
| 24 |
-
> **
|
| 25 |
-
>
|
| 26 |
-
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
---
|
| 29 |
|
|
@@ -146,74 +246,3 @@ uyumlu herhangi bir sunucuyla (ör. vLLM) çalışır.
|
|
| 146 |
**Kapsam.** Bu sürüm bir araştırma çalışmasıdır ve sentetik veri ambarlarında geliştirilip ölçülmüştür. Analistin
|
| 147 |
yardımcısı olarak tasarlanmıştır: sorguyu ve sonucu analist görür ve onaylar. Lisans CC BY-NC 4.0'dır; ticari kullanım
|
| 148 |
için [eqlx.ai](https://eqlx.ai) ile iletişime geçin.
|
| 149 |
-
|
| 150 |
-
---
|
| 151 |
-
|
| 152 |
-
## English
|
| 153 |
-
|
| 154 |
-
### Why this work
|
| 155 |
-
|
| 156 |
-
In sectors that cannot send data outside the organisation (banking, insurance, healthcare), the common assumption is that
|
| 157 |
-
expert tasks need the largest models, and that running them in-house needs a large GPU investment. This work shows the
|
| 158 |
-
opposite: **on a narrow, well-defined expert task, a small model can be brought close to large ones with the right
|
| 159 |
-
engineering.** The large model is needed once, as a teacher; the model that runs every day can be small.
|
| 160 |
-
|
| 161 |
-
### What it does
|
| 162 |
-
|
| 163 |
-
A risk analyst asks a question in Turkish about the bank's risk data mart. The model reads the schema, writes a short plan
|
| 164 |
-
and one `SELECT` portable to Oracle and PostgreSQL; a second call summarises the result in Turkish and proposes a chart.
|
| 165 |
-
Domains covered include IFRS 9 expected credit loss, liquidity (LCR, HQLA), collateral, market risk (VaR, backtesting),
|
| 166 |
-
operational risk, credit portfolio, non-performing loans and counterparty risk.
|
| 167 |
-
|
| 168 |
-
### Results
|
| 169 |
-
|
| 170 |
-
A query counts as correct only when it is **executed on three databases** and returns exactly the reference result.
|
| 171 |
-
|
| 172 |
-
| Model (same 160 questions, 6 risk data marts) | Parameters | Accuracy |
|
| 173 |
-
|---|---|---|
|
| 174 |
-
| Frontier-class large model (teacher) | – | 99.4% |
|
| 175 |
-
| Gemma 4 31B (larger sibling) | 31B | 93.1% |
|
| 176 |
-
| **This model + verify-and-vote loop** | **8B** | **88.8%** |
|
| 177 |
-
| This model, single answer | 8B | 79.7% |
|
| 178 |
-
| Gemma 4 E4B, untuned (start) | 8B | 57.3% |
|
| 179 |
-
|
| 180 |
-
The small model closed **88%** of the gap to its 4x larger sibling and **75%** of the gap to the frontier model.
|
| 181 |
-
|
| 182 |
-
On a sealed test set of 125 questions over five risk domains absent from training, the second-generation model of this
|
| 183 |
-
pipeline (v2) with the loop went from **56.0% to 86.8%** against the untuned model: +30.8 points, 95% confidence interval
|
| 184 |
-
+21.6 to +37.2 (bootstrap over schema families). SQL accuracy rose from 53% to 91% on plain questions and from 44.5% to
|
| 185 |
-
81% on banking-jargon questions; queries that ran but returned a wrong number fell from 62 cases to 25. The model in this
|
| 186 |
-
repository (v3) adds one round of self-distillation on top of v2: single-answer accuracy rose from 77.7% to 79.7% (a
|
| 187 |
-
confirmed gain) and general ability stayed at the untuned model's level (85.0% vs 86.7%).
|
| 188 |
-
|
| 189 |
-
**Total cost: 15.72 USD** (one rented GPU plus teacher API calls), about 14 hours.
|
| 190 |
-
|
| 191 |
-
### How it was built
|
| 192 |
-
|
| 193 |
-
1. **Measurement first.** A frozen execution verifier: every query runs on three seeded databases, results are compared
|
| 194 |
-
cell by cell regardless of row and column order, and each query is transpiled to Oracle and PostgreSQL. Test sets are
|
| 195 |
-
split by schema family; the noise floor (±3 points) and paired confidence intervals decide every comparison.
|
| 196 |
-
2. **Synthetic risk worlds.** 53 training and 15 test data marts with Turkish column comments, coded fields and the traps
|
| 197 |
-
of real data. No real bank data at any stage.
|
| 198 |
-
3. **Cross-verified teacher data.** One large model writes the question and SQL, a second independent model answers from
|
| 199 |
-
the schema alone; a pair is kept only when both return the same result on all three databases. Four question styles,
|
| 200 |
-
seven query patterns, 2,236 verified pairs, 2,935 training rows.
|
| 201 |
-
4. **LoRA fine-tuning** of the text decoder only (rank 64, 139.5M trainable parameters). → 72.2%
|
| 202 |
-
5. **Logit distillation** from Gemma 4 31B: the larger sibling's token distributions as a second target (0.5 CE + 0.5 KL,
|
| 203 |
-
top-64 plus remainder). → 75.2%
|
| 204 |
-
6. **Self-distillation (RFT):** eight sampled answers per training question, executed, the verified ones trained on. → 78.6%
|
| 205 |
-
7. **Plan before SQL:** a 3-7 line plan in Turkish precedes every query.
|
| 206 |
-
8. **Structural diversity:** hand-designed schema shapes (hierarchies, restructuring history, syndication shares,
|
| 207 |
-
multi-currency positions) under the same blind verification.
|
| 208 |
-
9. **Verify-and-vote loop at inference:** five candidates, executed, failures repaired from the error message, the result
|
| 209 |
-
most candidates agree on wins. The largest single gain, with no training. → 86.6%, 88.1% with the second generation
|
| 210 |
-
10. **Second self-distillation (this release):** the loop's consistency moved into the weights; a single greedy answer with
|
| 211 |
-
repair reaches 86.3% in 1-3 calls. → **88.8%** with the loop
|
| 212 |
-
11. **Reinforcement learning study:** GRPO with execution reward, training and rollouts sharing one GPU. Finding: at this
|
| 213 |
-
scale, self-distillation on verified answers delivers the same idea at a sixth of the cost with a confirmed gain.
|
| 214 |
-
|
| 215 |
-
### Scope and licence
|
| 216 |
-
|
| 217 |
-
A research release, developed and measured on synthetic data marts, designed as an analyst's assistant: the analyst sees
|
| 218 |
-
and approves the query and its result. Base model `google/gemma-4-E4B-it` (Apache 2.0). This adapter: **CC BY-NC 4.0**;
|
| 219 |
-
for commercial use contact [eqlx.ai](https://eqlx.ai).
|
|
|
|
| 17 |
|
| 18 |
# tr-risk-sql-gemma-e4b
|
| 19 |
|
| 20 |
+
**A small model that turns Turkish risk questions into SQL · Türkçe risk sorularını SQL'e çeviren küçük model**
|
| 21 |
|
| 22 |
Can Demir · [eqlx.ai](https://eqlx.ai) · 2026-11
|
| 23 |
|
| 24 |
+
> **A 16-dollar R&D study:** an open 8-billion-parameter model that fits on a single GPU was brought close to large
|
| 25 |
+
> models on an expert task, bank risk management. On data marts it had never seen, accuracy rose **from 56% to 87%**.
|
| 26 |
+
>
|
| 27 |
+
> **16 dolarlık bir Ar-Ge çalışması:** tek GPU'ya sığan 8 milyar parametreli açık bir model, bankacılık risk yönetimi
|
| 28 |
+
> gibi uzmanlık isteyen bir işte büyük modellere yaklaştırıldı. Hiç görmediği veri ambarlarında doğruluk **%56'dan
|
| 29 |
+
> %87'ye** çıktı.
|
| 30 |
+
|
| 31 |
+
---
|
| 32 |
+
|
| 33 |
+
## English
|
| 34 |
+
|
| 35 |
+
### Why this work
|
| 36 |
+
|
| 37 |
+
In sectors that cannot send data outside the organisation (banking, insurance, healthcare), the common assumption is that
|
| 38 |
+
expert tasks need the largest models, and that running them in-house needs a large GPU investment. This work shows the
|
| 39 |
+
opposite: **on a narrow, well-defined expert task, a small model can be brought close to large ones with the right
|
| 40 |
+
engineering.** The large model is needed once, as a teacher; the model that runs every day can be small.
|
| 41 |
+
|
| 42 |
+
### What it does
|
| 43 |
+
|
| 44 |
+
A risk analyst asks a question in Turkish about the bank's risk data mart. The model reads the schema, writes a short plan
|
| 45 |
+
and one `SELECT` portable to Oracle and PostgreSQL; a second call summarises the result in Turkish and proposes a chart.
|
| 46 |
+
Domains covered include IFRS 9 expected credit loss, liquidity (LCR, HQLA), collateral, market risk (VaR, backtesting),
|
| 47 |
+
operational risk, credit portfolio, non-performing loans and counterparty risk.
|
| 48 |
+
|
| 49 |
+
### Results
|
| 50 |
+
|
| 51 |
+
A query counts as correct only when it is **executed on three databases** and returns exactly the reference result.
|
| 52 |
+
|
| 53 |
+
| Model (same 160 questions, 6 risk data marts) | Parameters | Accuracy |
|
| 54 |
+
|---|---|---|
|
| 55 |
+
| Frontier-class large model (teacher) | – | 99.4% |
|
| 56 |
+
| Gemma 4 31B (larger sibling) | 31B | 93.1% |
|
| 57 |
+
| **This model + verify-and-vote loop** | **8B** | **88.8%** |
|
| 58 |
+
| This model, single answer | 8B | 79.7% |
|
| 59 |
+
| Gemma 4 E4B, untuned (start) | 8B | 57.3% |
|
| 60 |
+
|
| 61 |
+
The small model closed **88%** of the gap to its 4x larger sibling and **75%** of the gap to the frontier model.
|
| 62 |
+
|
| 63 |
+
**Unseen data marts** (sealed test set: 125 questions, five risk domains absent from training), second-generation
|
| 64 |
+
model (v2) with the loop against the untuned model:
|
| 65 |
+
|
| 66 |
+
| | Untuned | Trained + loop |
|
| 67 |
+
|---|---|---|
|
| 68 |
+
| Overall accuracy | 56.0% | **86.8%** |
|
| 69 |
+
| SQL, plain questions | 53.0% | 91.0% |
|
| 70 |
+
| SQL, banking-jargon questions | 44.5% | 81.0% |
|
| 71 |
+
| Hard questions | 35.6% | 74.5% |
|
| 72 |
+
| Turkish summary | 71.2% | 80.8% |
|
| 73 |
+
|
| 74 |
+
On a sealed test set of 125 questions over five risk domains absent from training, the second-generation model of this
|
| 75 |
+
pipeline (v2) with the loop went from **56.0% to 86.8%** against the untuned model: +30.8 points, 95% confidence interval
|
| 76 |
+
+21.6 to +37.2 (bootstrap over schema families). SQL accuracy rose from 53% to 91% on plain questions and from 44.5% to
|
| 77 |
+
81% on banking-jargon questions; queries that ran but returned a wrong number fell from 62 cases to 25. The model in this
|
| 78 |
+
repository (v3) adds one round of self-distillation on top of v2: single-answer accuracy rose from 77.7% to 79.7% (a
|
| 79 |
+
confirmed gain) and general ability stayed at the untuned model's level (85.0% vs 86.7%).
|
| 80 |
+
|
| 81 |
+
**Total cost: 15.72 USD** (one rented GPU plus teacher API calls), about 14 hours.
|
| 82 |
+
|
| 83 |
+
### How it was built
|
| 84 |
+
|
| 85 |
+
1. **Measurement first.** A frozen execution verifier: every query runs on three seeded databases, results are compared
|
| 86 |
+
cell by cell regardless of row and column order, and each query is transpiled to Oracle and PostgreSQL. Test sets are
|
| 87 |
+
split by schema family; the noise floor (±3 points) and paired confidence intervals decide every comparison.
|
| 88 |
+
2. **Synthetic risk worlds.** 53 training and 15 test data marts with Turkish column comments, coded fields and the traps
|
| 89 |
+
of real data. No real bank data at any stage.
|
| 90 |
+
3. **Cross-verified teacher data.** One large model writes the question and SQL, a second independent model answers from
|
| 91 |
+
the schema alone; a pair is kept only when both return the same result on all three databases. Four question styles,
|
| 92 |
+
seven query patterns, 2,236 verified pairs, 2,935 training rows.
|
| 93 |
+
4. **LoRA fine-tuning** of the text decoder only (rank 64, 139.5M trainable parameters). → 72.2%
|
| 94 |
+
5. **Logit distillation** from Gemma 4 31B: the larger sibling's token distributions as a second target (0.5 CE + 0.5 KL,
|
| 95 |
+
top-64 plus remainder). → 75.2%
|
| 96 |
+
6. **Self-distillation (RFT):** eight sampled answers per training question, executed, the verified ones trained on. → 78.6%
|
| 97 |
+
7. **Plan before SQL:** a 3-7 line plan in Turkish precedes every query.
|
| 98 |
+
8. **Structural diversity:** hand-designed schema shapes (hierarchies, restructuring history, syndication shares,
|
| 99 |
+
multi-currency positions) under the same blind verification.
|
| 100 |
+
9. **Verify-and-vote loop at inference:** five candidates, executed, failures repaired from the error message, the result
|
| 101 |
+
most candidates agree on wins. The largest single gain, with no training. → 86.6%, 88.1% with the second generation
|
| 102 |
+
10. **Second self-distillation (this release):** the loop's consistency moved into the weights; a single greedy answer with
|
| 103 |
+
repair reaches 86.3% in 1-3 calls. → **88.8%** with the loop
|
| 104 |
+
11. **Reinforcement learning study:** GRPO with execution reward, training and rollouts sharing one GPU. Finding: at this
|
| 105 |
+
scale, self-distillation on verified answers delivers the same idea at a sixth of the cost with a confirmed gain.
|
| 106 |
+
|
| 107 |
+
### Usage
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
from peft import PeftModel
|
| 111 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 112 |
+
|
| 113 |
+
base = AutoModelForCausalLM.from_pretrained("google/gemma-4-E4B-it", torch_dtype="auto", device_map="auto")
|
| 114 |
+
model = PeftModel.from_pretrained(base, "eqlx-ai/tr-risk-sql-gemma-e4b", subfolder="adapter")
|
| 115 |
+
tok = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
Prompt format: the system message is `code/system_sql.txt`; the user message carries the table definitions (with
|
| 119 |
+
column comments) under `### Şema` and the Turkish question under `### Soru`. The verify-and-vote loop is in
|
| 120 |
+
`code/infer_loop.py` and works with any OpenAI-compatible server (for example vLLM).
|
| 121 |
+
|
| 122 |
+
### Scope and licence
|
| 123 |
+
|
| 124 |
+
A research release, developed and measured on synthetic data marts, designed as an analyst's assistant: the analyst sees
|
| 125 |
+
and approves the query and its result. Base model `google/gemma-4-E4B-it` (Apache 2.0). This adapter: **CC BY-NC 4.0**;
|
| 126 |
+
for commercial use contact [eqlx.ai](https://eqlx.ai).
|
| 127 |
|
| 128 |
---
|
| 129 |
|
|
|
|
| 246 |
**Kapsam.** Bu sürüm bir araştırma çalışmasıdır ve sentetik veri ambarlarında geliştirilip ölçülmüştür. Analistin
|
| 247 |
yardımcısı olarak tasarlanmıştır: sorguyu ve sonucu analist görür ve onaylar. Lisans CC BY-NC 4.0'dır; ticari kullanım
|
| 248 |
için [eqlx.ai](https://eqlx.ai) ile iletişime geçin.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|