Views
No views yet
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, aggregations

1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4REPO = "mohamedelmadany/Qwen2.5-Arabic-to-SQL-Coder"
5
6tokenizer = AutoTokenizer.from_pretrained(REPO)
7model = AutoModelForCausalLM.from_pretrained(
8 REPO,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13SYSTEM_PROMPT = (
14 "أنت مساعد ذكي متخصص في كتابة استعلامات SQL.\n"
15 "بناءً على السياق (schema) والسؤال المقدم، اكتب استعلام SQL صحيح ودقيق.\n"
16 "اكتب أبسط استعلام يجيب على السؤال. "
17)
18
19schema = (
20 "CREATE TABLE employees ("
21 " id INT, name VARCHAR(100), department VARCHAR(50), salary INT"
22 ");"
23)
24question = "اعرض أعلى 5 موظفين في الراتب" # "Show the top 5 employees by salary"
25
26user_msg = f"### Schema:\n{schema}\n\n### Question:\n{question}"
27messages = [
28 {"role": "system", "content": SYSTEM_PROMPT},
29 {"role": "user", "content": user_msg},
30]
31text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
32inputs = tokenizer(text, return_tensors="pt").to(model.device)
33
34with torch.no_grad():
35 out = model.generate(
36 **inputs,
37 max_new_tokens=200,
38 temperature=0.1,
39 do_sample=True,
40 pad_token_id=tokenizer.eos_token_id,
41 )
42
43sql = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
44print(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).1@misc{qwen2.5-coder,
2 title={Qwen2.5-Coder Technical Report},
3 author={Qwen Team},
4 year={2024},
5 url={https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct}
6}
7
8@dataset{gretelai_synthetic_sql,
9 title={gretelai/synthetic_text_to_sql},
10 author={Gretel AI},
11 year={2024},
12 url={https://huggingface.co/datasets/gretelai/synthetic_text_to_sql}
13}