text-to-sql / README.md
fghcol30's picture
Upload README.md with huggingface_hub
ed8588d verified
|
raw
history blame
3.53 kB
---
tags:
- text2sql
- natural-language-to-sql
- transformers
- t5
- spider-dataset
license: apache-2.0
---

# 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](https://huggingface.co/datasets/spider), a benchmark dataset for text-to-SQL tasks.

- **Developed by:** [Your Name]
- **Shared by:** [Your Organization (optional)]
- **Model type:** Text-to-SQL (Sequence-to-Sequence)
- **Language(s):** English
- **License:** Apache 2.0
- **Finetuned from:** [t5-small](https://huggingface.co/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

```python
from transformers import T5Tokenizer, T5ForConditionalGeneration

# Load the fine-tuned model
model = T5ForConditionalGeneration.from_pretrained("your-huggingface-username/your-model-name")
tokenizer = T5Tokenizer.from_pretrained("your-huggingface-username/your-model-name")

# 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]

Citation

If you use this model, please cite the following:

@misc{your-model-name,
  author = {Your Name},
  title = {Fine-Tuned T5 for Text-to-SQL},
  year = {2023},
  publisher = {Hugging Face},
  howpublished = {\url{https://huggingface.co/your-huggingface-username/your-model-name}}
}

Model Card Authors

[Your Name]

Model Card Contact

[Your Email or Contact Information]


---