Downloads · 30 days
0
Abhisek987/llama-3.2-sql-lora
llama-3.2-sql-lora is a text generation model from Abhisek987. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as llama3.2.
This model is a fine-tuned version of meta-llama/Llama-3.2-3B for text-to-SQL generation using LoRA (Low-Rank Adaptation) on the Spider dataset.
Downloads · 30 days
0
Access
Public
Updated Oct 25, 2025
Repo size
111 MB
Likes
0
Public
Click a slice to open those files.
.safetensors110 MB · 63%
From the Hugging Face model README
This model is a fine-tuned version of meta-llama/Llama-3.2-3B for text-to-SQL generation using LoRA (Low-Rank Adaptation) on the Spider dataset.
This model converts natural language questions into SQL queries for various database schemas. It's designed for:
| Metric | Value |
|---|---|
| Initial Loss | 2.50 |
| Final Loss | 0.37 |
| Trainable Parameters | 9.17M (0.51% of total) |
| Training Time | 47 minutes |
pip install transformers peft torch bitsandbytes
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "Abhisek987/llama-3.2-sql-lora"
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
torch_dtype=torch.float16
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Prepare prompt
database = "employees"
question = "What are the names of all employees who earn more than 50000?"
prompt = f"""### Instruction:
You are a SQL expert. Generate a SQL query to answer the given question for the specified database.
### Input:
Database: {database}
Question: {question}
### Response:
"""
# Generate SQL
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.1,
do_sample=True
)
sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(sql_query.split("### Response:")[-1].strip())
Output:
SELECT name FROM employees WHERE salary > 50000;
| Question | Generated SQL |
|---|---|
| "Show top 5 products by sales" | SELECT product_id, sum(sales) FROM sales GROUP BY product_id ORDER BY sum(sales) DESC LIMIT 5; |
| "Count customers by country" | SELECT count(*), country FROM customers GROUP BY country; |
| "Find orders from last 30 days" | SELECT order_id FROM orders WHERE date_order_placed BETWEEN DATE('now') - INTERVAL 30 DAY AND DATE('now') - INTERVAL 1 DAY; |
If you use this model, please cite:
@misc{llama32-sql-lora,
author = {Abhisek Behera},
title = {Llama 3.2 3B SQL Query Generator (LoRA Fine-tuned)},
year = {2025},
publisher = {HuggingFace},
url = {https://huggingface.co/Abhisek987/llama-3.2-sql-lora}
}
This model inherits the Llama 3.2 Community License from the base model.
---
## **Step 2: Add to Settings**
1. **Repository Settings** → Make it **Public**
2. **Add topics/tags:** `llama`, `sql`, `lora`, `nlp`, `text-to-sql`
---
## **Step 3: For Your Resume**
Add this to your projects section:
🔗 Text-to-SQL Generator using Llama 3.2 (LLM Fine-tuning) https://huggingface.co/Abhisek987/llama-3.2-sql-lora