Views
No views yet
| Metric | Baseline | Fine-tuned |
|---|---|---|
| Exact match | 0.401 | 0.843 |
| Normalized match | 0.414 | 0.848 |
1from unsloth import FastLanguageModel
2from peft import PeftModel
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="unsloth/Llama-3.2-1B-Instruct-bnb-4bit",
6 max_seq_length=1024,
7 load_in_4bit=True,
8)
9model = PeftModel.from_pretrained(model, "ssnym/llama-3.2-1b-text-to-sql")
10FastLanguageModel.for_inference(model)
11
12SYSTEM_PROMPT = "You are a text-to-SQL assistant. Given a table schema and a question, output only the SQL Query"
13
14messages = [
15 {"role": "system", "content": SYSTEM_PROMPT},
16 {"role": "user", "content": "Context (schema):\nCREATE TABLE head (age INTEGER)\n\nQuestion: How many heads of the departments are older than 56 ?"}
17]
18
19inputs = tokenizer.apply_chat_template(
20 messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
21).to("cuda")
22
23outputs = model.generate(inputs, max_new_tokens=128, temperature=0.1)
24print(tokenizer.decode(outputs[0], skip_special_tokens=True))