Downloads · 30 days
22
9% of all-time downloads
chrisjcc/Llama-3.1-8B-Instruct-text-to-sql-adapter
Llama-3.1-8B-Instruct-text-to-sql-adapter is a text generation model from chrisjcc. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
This is a LoRA Adapter fine-tuned from meta-llama/Llama-3.1-8B-Instruct for text-to-SQL generation tasks.
Downloads · 30 days
22
9% of all-time downloads
All-time downloads
238
Public
Repo size
185 MB
Likes
2
Public
Click a slice to open those files.
.safetensors168 MB · 91%
From the Hugging Face model README
This is a LoRA Adapter fine-tuned from meta-llama/Llama-3.1-8B-Instruct for text-to-SQL generation tasks.
This model is designed to translate natural language questions into SQL queries for database interaction. It works best when provided with:
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
from peft import PeftModel
# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.1-8B-Instruct",
device_map="auto",
torch_dtype="auto"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "chrisjcc/Llama-3.1-8B-Instruct-text-to-sql-adapter")
tokenizer = AutoTokenizer.from_pretrained("chrisjcc/Llama-3.1-8B-Instruct-text-to-sql-adapter")
# For inference, merge adapter for better performance (optional)
model = model.merge_and_unload()
# Create text generation pipeline
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=256,
do_sample=False,
)
# Example usage
schema = """
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP
);
"""
question = "Show me all users who registered in the last 7 days"
messages = [
{
"role": "system",
"content": f"You are a text to SQL translator.\n\nSCHEMA:\n{schema}"
},
{"role": "user", "content": question}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
outputs = pipe(prompt)
sql_query = outputs[0]['generated_text'][len(prompt):].strip()
print("Generated SQL:", sql_query)
The model was fine-tuned using Supervised Fine-Tuning (SFT) with the following approach:
{
"messages": [
{
"role": "system",
"content": "You are a text to SQL translator...\n\nSCHEMA:\nCREATE TABLE..."
},
{
"role": "user",
"content": "Show me all customers from New York"
},
{
"role": "assistant",
"content": "SELECT * FROM customers WHERE city = 'New York';"
}
]
}
The model has been trained to generate syntactically correct SQL queries for various database schemas. Performance may vary based on:
If you use this model in your research or application, please cite:
@misc{chrisjcc_Llama_3.1_8B_Instruct_text_to_sql_adapter,
author = {Christian Contreras Campana},
title = {Llama-3.1-8B-Instruct-text-to-sql-adapter: Fine-tuned Text-to-SQL Model},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/chrisjcc/Llama-3.1-8B-Instruct-text-to-sql-adapter}}
}
This model is released under the APACHE-2.0 license. The base model meta-llama/Llama-3.1-8B-Instruct has its own license terms.
For questions or feedback, please open an issue on the model repository.
Model Type: LoRA adapter weights Training Date: 2025 Model Size: ~8B parameters