NL-SQL-T5-Small: Fine-Tuned Text-to-SQL Transformer

This model is a fine-tuned version of google-t5/t5-small specialized for translating English natural language questions into executable SQL queries based on table schemas.

Developed as part of the Natural Language Data Analysis Agent project by Solayman Sameh Solayman & Habiba Ayman Ahmed.


πŸ“Š Model Details & Performance

  • Base Architecture: T5-small (Encoder-Decoder Transformer, 60M parameters)
  • Training Dataset: WikiSQL (56,355 training queries, 8,421 validation, 15,878 test)
  • Exact Match Accuracy: 61.8% on the WikiSQL test split (BLEU: 0.824)
  • Input Format: translate to SQL: {question} | columns: {col1} ({type1}), {col2} ({type2})

πŸš€ How to Use

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load model and tokenizer
model_id = "Solayman-Sameh/nl-sql-t5-small"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)

# Prepare schema-aware prompt
question = "What is the average salary of engineers?"
columns = ["name (text)", "role (text)", "salary (real)"]
prompt = f"translate to SQL: {question} | columns: {', '.join(columns)}"

inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=64)

sql_query = tokenizer.decode(outputs[0], skip_special_tokens=True)
print("Generated SQL:", sql_query)
# Output: SELECT AVG salary FROM table WHERE role = engineer

πŸ‘₯ Authors & Acknowledgments

Developed as part of the NL Data Analysis Agent project.

Downloads last month
35
Safetensors
Model size
60.5M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Space using Solayman-Sameh/nl-sql-t5-small 1