Downloads · 30 days
31
10% of all-time downloads
ashishsahu2008/qwen2.5-3b-text2sql
qwen2.5-3b-text2sql is a text generation model from ashishsahu2008. 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 fine-tuned version of Qwen2.5-3B-Instruct that converts natural-language questions into SQL queries, given a database schema. Trained with LoRA/QLoRA on a single free GPU.
Downloads · 30 days
31
10% of all-time downloads
All-time downloads
306
Public
Parameters
3.1B
6.2 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors6.2 GB · 100%
From the Hugging Face model README
A fine-tuned version of Qwen2.5-3B-Instruct that converts natural-language questions into SQL queries, given a database schema. Trained with LoRA/QLoRA on a single free GPU.
Give it a CREATE TABLE schema and a plain-English question, and it returns only
the SQL query that answers the question — no explanations or markdown, just runnable SQL.
Evaluated on a held-out test split (n=200) the model never saw during training.
Both the base and fine-tuned models were scored with identical string normalization
(lowercase, strip ;, canonicalize quotes), so the comparison is apples-to-apples.
| Model | Exact-match accuracy |
|---|---|
| Qwen2.5-3B-Instruct (base) | 41.5% |
| This model (fine-tuned) | 72.5% |
Only 0.96% of parameters (~30M of 3.1B) were trained via LoRA. Much of the gain comes from the base model learning to emit clean, executable SQL instead of wrapping answers in prose or markdown fences.
Note on the metric: exact-match undercounts semantically-correct queries that are written differently (column order, aliases, whitespace). A stronger evaluation would use AST comparison (
sqlglot) or execution accuracy on a benchmark with populated databases (Spider / BIRD);sql-create-contextships schemas only.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "ashishsahu2008/qwen2.5-3b-text2sql"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
schema = "CREATE TABLE employees (name VARCHAR, salary INTEGER, department VARCHAR)"
question = "List the names of employees in Sales earning over 50000."
messages = [
{"role": "system", "content": "You are a SQL expert. Given a database schema "
"and a question, output only the SQL query that answers it."},
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
).to(model.device)
out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
The model expects the schema and question in a single user turn, with this system prompt:
System: You are a SQL expert. Given a database schema and a question, output only the SQL query that answers it.
User: Schema:
<CREATE TABLE ...>
Question: <your question>
b-mc2/sql-create-context (2,700 train / 300 test)SFTTrainerCREATE TABLE schemas; complex multi-join databases
are out of distribution.Fine-tuned with Unsloth and Hugging Face's TRL library.