Model Card for Fine-Tuned T5 for Text-to-SQL
Model Details
Model Description
This is a fine-tuned T5-small model for generating SQL queries from natural language. It was trained on the Spider dataset, a benchmark dataset for text-to-SQL tasks.
- Developed by: OSLLM.ai
- Shared by: OSLLM.ai
- Model type: Text-to-SQL (Sequence-to-Sequence)
- Language(s): English
- License: Apache 2.0
- Finetuned from: t5-small
Uses
Direct Use
This model can be used to generate SQL queries from natural language questions. It is particularly useful for developers building natural language interfaces to databases.
Downstream Use
The model can be fine-tuned further on domain-specific datasets for improved performance.
Out-of-Scope Use
This model is not suitable for generating SQL queries for databases with highly specialized schemas or non-standard SQL dialects.
Bias, Risks, and Limitations
The model may generate incorrect or unsafe SQL queries if the input question is ambiguous or outside the scope of the training data. Always validate the generated SQL before executing it on a production database.
How to Get Started with the Model
from transformers import T5Tokenizer, T5ForConditionalGeneration
# Load the fine-tuned model
model = T5ForConditionalGeneration.from_pretrained("osllmai/text-to-sql")
tokenizer = T5Tokenizer.from_pretrained("osllmai/text-to-sql")
# Generate SQL query
def generate_sql_query(question):
input_text = f"translate English to SQL: {question}"
input_ids = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True, padding="max_length").input_ids
outputs = model.generate(input_ids)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Example usage
question = "Find all the customers who live in New York."
sql_query = generate_sql_query(question)
print(sql_query)
Training Details
Training Data
The model was trained on the Spider dataset, which contains 10,181 questions and 5,693 unique complex SQL queries across 200 databases.
Training Procedure
- Preprocessing: Questions were prefixed with "translate English to SQL:" and tokenized using the T5 tokenizer.
- Training Hyperparameters:
- Learning Rate: 2e-5
- Batch Size: 8
- Epochs: 3
- Mixed Precision: FP16
Evaluation
The model was evaluated on the Spider validation set. Metrics such as exact match accuracy and execution accuracy can be used to assess performance.
Environmental Impact
- Hardware: 1x NVIDIA T4 GPU (Google Colab)
- Hours Used: ~3 hours
- Carbon Emitted: [Estimate using the ML CO2 Impact Calculator]
Model Card Authors
Fateme Ghasemi
- Downloads last month
- 92