Qwen2.5-Coder-3B-Text2SQL

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.

Benchmark (500 Held-Out 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%

Training Details

  • Dataset: 30,000 training examples from b-mc2/sql-create-context
  • Method: QLoRA (r=16, lora_alpha=16, all linear projections) with response-only loss masking via Unsloth
  • Hyperparameters: 1 epoch, effective batch size 16, cosine LR schedule (2e-4), adamw_8bit
  • Final Training Loss: 0.0361

Quickstart Usage

from 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))
Downloads last month
-
Safetensors
Model size
3B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for holygrimm/qwen2.5-coder-3b-text2sql

Base model

Qwen/Qwen2.5-3B
Finetuned
(174)
this model

Dataset used to train holygrimm/qwen2.5-coder-3b-text2sql