Views
No views yet
| Metric | DeepSeek-V3 (Teacher) | Qwen3-4B (Base) | This Model |
|---|---|---|---|
| LLM-as-a-Judge | 80% | 62% | 80% |
| Exact Match | 48% | 16% | 60% |
| ROUGE | 87.6% | 84.2% | 89.5% |
| METEOR | 85.1% | 87.3% | 86.1% |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("distil-labs/distil-qwen3-4b-text2sql")
4tokenizer = AutoTokenizer.from_pretrained("distil-labs/distil-qwen3-4b-text2sql")
5
6schema = """CREATE TABLE employees (
7 id INTEGER PRIMARY KEY,
8 name TEXT NOT NULL,
9 department TEXT,
10 salary INTEGER
11);"""
12
13question = "How many employees earn more than 50000?"
14
15messages = [
16 {
17 "role": "system",
18 "content": """You are a problem solving model working on task_description XML block:
19<task_description>You are given a database schema and a natural language question. Generate the SQL query that answers the question.
20
21Input:
22- Schema: One or two table definitions in SQL DDL format
23- Question: Natural language question about the data
24
25Output:
26- A single SQL query that answers the question
27- No explanations, comments, or additional text
28
29Rules:
30- Use only tables and columns from the provided schema
31- Use uppercase SQL keywords (SELECT, FROM, WHERE, etc.)
32- Use SQLite-compatible syntax</task_description>
33You will be given a single task in the question XML block
34Solve only the task in question block.
35Generate only the answer, do not generate anything else"""
36 },
37 {
38 "role": "user",
39 "content": f"""Now for the real task, solve the task in question block.
40Generate only the solution, do not generate anything else
41<question>Schema:
42{schema}
43
44Question: {question}</question>"""
45 }
46]
47
48text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
49inputs = tokenizer(text, return_tensors="pt")
50outputs = model.generate(**inputs, max_new_tokens=256, temperature=0)
51print(tokenizer.decode(outputs[0], skip_special_tokens=True))1# Download and create Ollama model
2ollama create distil-qwen3-4b-text2sql -f Modelfile
3
4# Run inference
5ollama run distil-qwen3-4b-text2sql| Property | Value |
|---|---|
| Base Model | Qwen/Qwen3-4B |
| Parameters | 4 billion |
| Architecture | Qwen3ForCausalLM |
| Context Length | 262,144 tokens |
| Precision | bfloat16 |
| Training Data | ~10,000 synthetic examples |
| Teacher Model | DeepSeek-V3 |
Schema:
CREATE TABLE table_name (
column_name DATA_TYPE [CONSTRAINTS],
...
);
Question: Natural language question about the data1@misc{distil-qwen3-4b-text2sql,
2 author = {Distil Labs},
3 title = {Distil-Qwen3-4B-Text2SQL: A Fine-tuned Model for Natural Language to SQL},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql}
7}