qwen2.5-0.5b-text-to-sql
Compact text-to-SQL parser
2 min readupdated
This lightweight adapter (LoRA, a small add-on on top of a base model) turns natural language questions into ready-to-run SQL queries. Built on the tiny Qwen/Qwen2.5-0.5B-Instruct language model, it specializes in working with DDL database schemas. At an ultra-compact 0.5 billion parameters, it is well suited for fast local deployment, microservices, and low-end hardware—ideal for developers and analysts who want to embed SQL generation into their apps without calling heavy cloud APIs.
Key features
- Parsing accuracy: significantly lower perplexity and fewer errors compared to the base model.
- Low latency: lightweight architecture delivers fast query generation.
- Cross-domain generalization: tested on previously unseen database types.
- Compatibility: seamlessly integrates with standard Hugging Face libraries such as transformers and peft.
What you can do
- Text-to-SQL generation: embed the model into local bots and applications to query databases effortlessly.
- Pipeline integration: plug it into RAG (retrieval-augmented generation) systems to accurately extract structured data.
- Edge deployment: run the parser on local devices or servers with minimal VRAM requirements.
Example
An example of generating an SQL query from a table schema and a question:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
base_model_id = "Qwen/Qwen2.5-0.5B-Instruct"
adapter_id = "vennyvirtuoso/qwen2.5-0.5b-text-to-sql"
tokenizer = AutoTokenizer.from_pretrained(adapter_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
model = PeftModel.from_pretrained(base_model, adapter_id)
model.eval()Read more
DetailsBenchmarks: perplexity dropped from 7.45 to 1.62 (-78.2%)
Requirements: minimal, thanks to the 0.5B-parameter base model
License: Apache 2.0 for commercial and educational use
Dataset: gretelai/synthetic_text_to_sql










Comments