Views
No views yet
Qwen/Qwen2.5-Coder-1.5B designed to convert natural language questions into strict, executable SQL queries based on a provided database schema.b-mc2/sql-create-context (25,000 highly curated schema/question/query pairs)1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base_model_id = "Qwen/Qwen2.5-Coder-1.5B"
5adapter_id = "your-username/Qwen-1.5B-Text-to-SQL-LoRA"
6
7# Load the base model and tokenizer
8tokenizer = AutoTokenizer.from_pretrained(base_model_id)
9base_model = AutoModelForCausalLM.from_pretrained(base_model_id)
10
11# Apply the LoRA adapter
12model = PeftModel.from_pretrained(base_model, adapter_id)
13
14# Format your prompt using the strict schema template
15prompt = """Schema:
16CREATE TABLE employees (id VARCHAR, name VARCHAR, department VARCHAR, salary INTEGER)
17
18Question:
19How many employees in the engineering department make more than 100000?
20
21SQL:
22"""
23inputs = tokenizer(prompt, return_tensors="pt")
24outputs = model.generate(**inputs, max_new_tokens=150, do_sample=False)
25print(tokenizer.decode(outputs[0], skip_special_tokens=True))