Views
No views yet
Qwen/Qwen2.5-Coder-1.5B-Instruct
to translate natural-language questions into SQL, trained on the
Spider dataset.| Execution accuracy | Crashing queries | |
|---|---|---|
| Base Qwen2.5-Coder-1.5B (zero-shot) | 57.45% | 228 |
| + this adapter | 65.57% | 148 |
| +8.1 pts | −35% |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
5model = AutoModelForCausalLM.from_pretrained(base, device_map="auto")
6model = PeftModel.from_pretrained(model, "Abdullahkousa2/sqlforge-qwen2.5-coder-1.5b")
7tok = AutoTokenizer.from_pretrained(base)
8
9messages = [
10 {"role": "system", "content": "You are an expert data analyst. Given a SQLite "
11 "database schema and a question, write a single valid SQLite SQL query that "
12 "answers it. Respond with only the SQL query and nothing else."},
13 {"role": "user", "content": 'Database schema:\nCREATE TABLE singer ("Name" text, "Age" int);\n\nQuestion: How many singers are there?'},
14]
15prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16out = model.generate(**tok(prompt, return_tensors="pt").to(model.device), max_new_tokens=128)
17print(tok.decode(out[0], skip_special_tokens=True).split("assistant")[-1].strip())
18# -> SELECT count(*) FROM singersqlforge package:1pip install sqlforge
2sqlforge -q "How many singers are there?" --db mydata.sqlite --run