Downloads · 30 days
19
22% of all-time downloads
mohamedelmadany/Qwen2.5-Arabic-to-SQL-Coder
Qwen2.5-Arabic-to-SQL-Coder is a text generation model from mohamedelmadany. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
A bilingual Arabic + English text-to-SQL model. Give it a database schema and a question — in either language — and it returns a SQL query.
Downloads · 30 days
19
22% of all-time downloads
All-time downloads
88
Public
Parameters
3.1B
6.2 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors6.2 GB · 100%
From the Hugging Face model README
A bilingual Arabic + English text-to-SQL model. Give it a database schema and a question — in either language — and it returns a SQL query.
Fine-tuned from Qwen/Qwen2.5-Coder-3B-Instruct
on a translated subset of gretelai/synthetic_text_to_sql,
with English questions translated to Modern Standard Arabic via
Helsinki-NLP/opus-mt-en-ar.
SELECT, WHERE, JOIN, GROUP BY, HAVING,
subqueries, LEFT JOIN ... IS NULL, LIKE, DISTINCT, date filtering,
ORDER BY, aggregationsTrained for 2 epochs on ~100K bilingual samples; eval loss converged smoothly:

The cosine learning-rate schedule with 5% warmup:

Evaluated on a hand-crafted held-out test suite covering 12 SQL skill categories (basic SELECT, JOIN, GROUP BY, HAVING, subqueries, LEFT JOIN with NULL, date filtering, DISTINCT COUNT, LIKE, ORDER BY + LIMIT, single + multi-table aggregations) with real execution against an in-memory SQLite database
Each test case includes seeded data, so accuracy is verified by running both the predicted SQL and the gold reference SQL and comparing result rows — not by string matching.
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
REPO = "mohamedelmadany/Qwen2.5-Arabic-to-SQL-Coder"
tokenizer = AutoTokenizer.from_pretrained(REPO)
model = AutoModelForCausalLM.from_pretrained(
REPO,
torch_dtype=torch.bfloat16,
device_map="auto",
)
SYSTEM_PROMPT = (
"أنت مساعد ذكي متخصص في كتابة استعلامات SQL.\n"
"بناءً على السياق (schema) والسؤال المقدم، اكتب استعلام SQL صحيح ودقيق.\n"
"اكتب أبسط استعلام يجيب على السؤال. "
)
schema = (
"CREATE TABLE employees ("
" id INT, name VARCHAR(100), department VARCHAR(50), salary INT"
");"
)
question = "اعرض أعلى 5 موظفين في الراتب" # "Show the top 5 employees by salary"
user_msg = f"### Schema:\n{schema}\n\n### Question:\n{question}"
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_msg},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(
**inputs,
max_new_tokens=200,
temperature=0.1,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
sql = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(sql.strip())
| Base model | Qwen/Qwen2.5-Coder-3B-Instruct |
| Method | QLoRA (4-bit NF4 + double-quant base, bf16 LoRA) |
| LoRA rank / alpha / dropout | 64 / 128 / 0.05 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Training data | ~100K bilingual samples (50K English + 50K MSA Arabic) |
| Sequence length | 1,024 |
| Epochs | 2 |
| Effective batch size | 32 (8 per device × 4 grad accum) |
| Learning rate | 2e-4, cosine schedule, 5% warmup |
| Optimizer | paged AdamW 8-bit |
| Gradient checkpointing | Enabled |
| Hardware | 1× NVIDIA A100 40 GB |
| Wall time | ~7 hours |
| Best checkpoint selected by | minimum eval loss |
| Final eval loss | 0.247 |
gretelai/synthetic_text_to_sql.sql_prompt to Modern Standard Arabic via
Helsinki-NLP/opus-mt-en-ar (GPU batched, beam search width 4).This model builds on:
@misc{qwen2.5-coder,
title={Qwen2.5-Coder Technical Report},
author={Qwen Team},
year={2024},
url={https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct}
}
@dataset{gretelai_synthetic_sql,
title={gretelai/synthetic_text_to_sql},
author={Gretel AI},
year={2024},
url={https://huggingface.co/datasets/gretelai/synthetic_text_to_sql}
}
Apache 2.0.