nl-sql-t5-small / README.md
Solayman-Sameh's picture
Update pipeline_tag to text-generation
dcd5761 verified
|
Raw History Blame Contribute Delete
2.37 kB
metadata
language:
  - en
license: mit
tags:
  - text-to-sql
  - t5
  - wikisql
  - natural-language-processing
  - code-generation
datasets:
  - salesforce/wikisql
pipeline_tag: text-generation
widget:
  - text: >-
      translate to SQL: What is the average score? | columns: player (text),
      score (real), team (text)
    example_title: Average Score Example
  - text: >-
      translate to SQL: Who won the championship in 2020? | columns: year
      (real), champion (text), runner_up (text)
    example_title: Filtered Query Example

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.