Query
Query databases in plain English
The Query (aka, Ask) model empowers developers to query databases in plain English. At its core is a fine-tuned FLAN-T5-base model that translates user questions into optimized PostgreSQL queries. Retrieved results are combined with the original input to generate clear, conversational responses.
Architecture
Base Model: FLAN-T5-base (sequence-to-sequence transformer)
Fine-Tuning Objective: Natural language → SQL translation
Tokenizer: T5 tokenizer with custom prefix handling
Training Pipeline
Dataset Preparation
Curated pairs of questions and SQL statements
Normalization: lowercase, remove commas, strip trailing punctuation
Data Split
90% training | 10% validation
Input Formatting
Prefix: Translate the following text to PGSQL:
Hyperparameters
Learning rate: 3e-5
Batch size: 4 (×4 gradient-accumulation)
Epochs: 10
Weight decay: 0.01
Scheduler: Cosine decay with 10% warmup
Label smoothing: 0.1
Evaluation
Metric: SacreBLEU on validation set
Inference Workflow
Integration Guide
A: Installation
B: Model & Tokenizer
C: Query Execution
Sanitize generated SQL
Execute securely against your PostgreSQL database
D: Response Formatting
Post-process database output into readable text
Dataset
The training dataset comprises custom-curated pairs of natural language questions and SQL queries, designed to align with the target database schema. Its diversity enhances the model's applicability to varied use cases.
Evaluation Metrics
Model performance is assessed using the SacreBLEU metric, which measures the similarity between generated and reference SQL queries. This metric ensures high accuracy and fluency in query generation.
API & Web Interface
Considerations
Optimized for a specific schema; may require adaptation for others.
Implement error handling for unexpected inputs.
Last updated
Was this helpful?