Downloads · 30 days
56
25% of all-time downloads
vindows/qwen2.5-7b-text-to-sql
qwen2.5-7b-text-to-sql is a machine learning model from vindows. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as apache-2.0.
This is a LoRA adapter for Qwen/Qwen2.5-7B-Instruct fine-tuned on natural language to SQL conversion.
Downloads · 30 days
56
25% of all-time downloads
All-time downloads
228
Public
Repo size
173 MB
Likes
0
Public
Click a slice to open those files.
.safetensors162 MB · 91%
From the Hugging Face model README
This is a LoRA adapter for Qwen/Qwen2.5-7B-Instruct fine-tuned on natural language to SQL conversion.
| 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% |
Note: The model shows strong component understanding but tends to append explanatory text after SQL queries, affecting exact match scores. See limitations below.
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-7B-Instruct",
device_map="auto",
torch_dtype=torch.bfloat16,
trust_remote_code=True
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "vindows/qwen2.5-7b-text-to-sql")
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-7B-Instruct", trust_remote_code=True)
# Generate SQL
prompt = "Convert the following natural language question to SQL:\n\nDatabase: concert_singer\nQuestion: How many singers do we have?\n\nSQL:"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128, temperature=0.1)
sql = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sql)
For easier usage without loading base + adapter separately, use the merged model:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"vindows/qwen2.5-7b-text-to-sql-merged",
device_map="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained("vindows/qwen2.5-7b-text-to-sql-merged")
def extract_sql(generated_text):
# Extract SQL after the "SQL:" marker
if "SQL:" in generated_text:
sql = generated_text.split("SQL:")[-1].strip()
else:
sql = generated_text
# Take only the first SQL statement (before extra text)
if '\n\n' in sql:
sql = sql.split('\n\n')[0].strip()
# Remove trailing semicolon if present
sql = sql.rstrip(';').strip()
return sql
adapter_config.json - LoRA configurationadapter_model.safetensors - LoRA weightsREADME.md - This file@misc{qwen2.5-7b-text-to-sql,
title = {Qwen2.5-7B LoRA Fine-tuned for Text-to-SQL},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/vindows/qwen2.5-7b-text-to-sql}
}
Apache 2.0 (inherits from base Qwen2.5 model)