Views
No views yet
| Metric | Base Model | Fine-tuned | Improvement |
|---|---|---|---|
| Loss | 2.1301 | 0.4098 | 80.76% ⬆️ |
| Perplexity | 8.4155 | 1.5064 | 82.10% ⬆️ |
| Metric | Score |
|---|---|
| Exact Match | 0.00% |
| Normalized Match | 0.50% |
| Component Accuracy | 92.60% |
| Average Similarity | 25.47% |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Load base model
6base_model = AutoModelForCausalLM.from_pretrained(
7 "Qwen/Qwen2.5-7B-Instruct",
8 device_map="auto",
9 torch_dtype=torch.bfloat16,
10 trust_remote_code=True
11)
12
13# Load LoRA adapter
14model = PeftModel.from_pretrained(base_model, "vindows/qwen2.5-7b-text-to-sql")
15tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct", trust_remote_code=True)
16
17# Generate SQL
18prompt = "Convert the following natural language question to SQL:\n\nDatabase: concert_singer\nQuestion: How many singers do we have?\n\nSQL:"
19inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
20outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
21sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
22print(sql)1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained(
4 "vindows/qwen2.5-7b-text-to-sql-merged",
5 device_map="auto",
6 trust_remote_code=True
7)
8tokenizer = AutoTokenizer.from_pretrained("vindows/qwen2.5-7b-text-to-sql-merged")1def extract_sql(generated_text):
2 # Extract SQL after the "SQL:" marker
3 if "SQL:" in generated_text:
4 sql = generated_text.split("SQL:")[-1].strip()
5 else:
6 sql = generated_text
7
8 # Take only the first SQL statement (before extra text)
9 if '\n\n' in sql:
10 sql = sql.split('\n\n')[0].strip()
11
12 # Remove trailing semicolon if present
13 sql = sql.rstrip(';').strip()
14
15 return sqladapter_config.json - LoRA configurationadapter_model.safetensors - LoRA weightsREADME.md - This file1@misc{qwen2.5-7b-text-to-sql,
2 title = {Qwen2.5-7B LoRA Fine-tuned for Text-to-SQL},
3 year = {2024},
4 publisher = {Hugging Face},
5 url = {https://huggingface.co/vindows/qwen2.5-7b-text-to-sql}
6}