b-mc2/sql-create-context
Viewer โข Updated โข 78.6k โข 12.3k โข 507
A fine-tuned version of Qwen/Qwen2.5-Coder-3B-Instruct specialized for converting natural language questions and CREATE TABLE database schemas into executable SQLite queries.
Evaluated on 500 unseen examples from b-mc2/sql-create-context (seed=42, indices 30000:30500) by executing generated queries against an in-memory SQLite database and comparing returned rows against ground truth:
| Model | Execution Accuracy | Syntax Error Rate |
|---|---|---|
| Qwen2.5-Coder-3B-Instruct (Base) | 83.8% | 5.6% |
| Qwen2.5-Coder-3B-Text2SQL (Fine-Tuned) | 94.6% | 2.4% |
b-mc2/sql-create-contextr=16, lora_alpha=16, all linear projections) with response-only loss masking via Unsloth2e-4), adamw_8bit0.0361from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "holygrimm/qwen2.5-coder-3b-text2sql"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
schema = "CREATE TABLE employees (id INT, name TEXT, department TEXT, salary INT);"
question = "What is the average salary in the Engineering department?"
messages = [
{"role": "system", "content": "You are a SQL expert. Convert the question into a valid SQLite query using the provided schema. Output ONLY the raw SQL query without markdown formatting or explanation."},
{"role": "user", "content": f"### Schema:\n{schema}\n\n### Question:\n{question}"}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))