SaluteFaceOpensource's picture SalutefaceAAC's picture
Duplicate from SalutefaceAAC/sql-natural-language-pairs
606ac8d
|
Raw History Blame Contribute Delete
8.42 kB
---
license: cc-by-4.0
language:
- en
tags:
- sql
- text-to-sql
- natural-language-processing
- code-generation
- synthetic
- structured-data
- query-generation
- nlp
pretty_name: "SQL Natural Language Pairs — Synthetic Benchmark"
size_categories:
- n<1K
task_categories:
- text2text-generation
- text-generation
configs:
- config_name: default
data_files:
- split: train
path: data/train.csv
- split: validation
path: data/validation.csv
- split: test
path: data/test.csv
---
# SQL Natural Language Pairs — Synthetic Benchmark
A curated synthetic dataset of **286 (question, SQL, schema_context)** pairs spanning five real-world domains,
six SQL complexity levels, and three difficulty tiers. Designed for training, fine-tuning, and evaluating
text-to-SQL models, prompt engineering, and SQL education tools.
**Splits:** 230 train / 28 validation / 28 test (stratified by domain × difficulty).
## Why this dataset?
Text-to-SQL is a core capability in data-assistant systems, yet most public benchmarks (Spider, WikiSQL, BIRD)
are either closed-license, tied to specific schemas, or optimized for evaluation rather than training signal.
This dataset fills a gap:
- **Permissive license (CC-BY-4.0)** — use freely in commercial or research contexts
- **Diverse, realistic schemas** — five domains each with 4–5 tables and foreign keys
- **Graduated complexity** — from single-table SELECT to multi-CTE window functions
- **Schema context included** — each row contains the DDL-lite schema so models can learn grounding
- **Deterministically reproducible** — all data generated by open Python scripts (included in repo)
## Schema
Five domains, each with 4–5 tables:
| Domain | Tables |
|--------|--------|
| `ecommerce` | customers, orders, order_items, products, suppliers |
| `healthcare` | patients, doctors, appointments, hospitals, prescriptions |
| `analytics` | events, users, sessions, pages, conversions |
| `hr` | employees, departments, projects, assignments, performance_reviews |
| `inventory` | warehouses, items, stock, movements, vendors |
All schemas are intentionally self-contained and representative of real production databases.
## Dataset Statistics
| Dimension | Breakdown |
|-----------|-----------|
| **Total pairs** | 286 |
| **Domains** | ecommerce (98), healthcare (59), analytics (48), hr (42), inventory (39) |
| **Difficulty** | easy (142), medium (90), hard (54) |
| **Query types** | aggregate (130), join (56), select (54), subquery (25), window (12), cte (9) |
### Splits
| Split | Records |
|-------|---------|
| train | 230 |
| validation | 28 |
| test | 28 |
Splits are stratified by domain × difficulty to ensure balanced coverage in each partition.
## Columns
| Column | Type | Description |
|--------|------|-------------|
| `question` | string | Natural language question or instruction |
| `sql` | string | Correct SQL query answering the question |
| `schema_context` | string | Abbreviated DDL for the domain (table(col1, col2, ...)) |
| `domain` | string | One of: ecommerce, healthcare, analytics, hr, inventory |
| `difficulty` | string | easy / medium / hard |
| `query_type` | string | select / aggregate / join / subquery / window / cte |
## Sample Records
**Easy — aggregate (ecommerce)**
```
Q: How many customers are from Germany?
SQL: SELECT COUNT(*) AS customer_count FROM customers WHERE country = 'Germany';
```
**Medium — JOIN (healthcare)**
```
Q: Show all appointments with patient name, doctor name, and diagnosis.
SQL: SELECT a.appointment_id, p.name AS patient_name, d.name AS doctor_name,
a.appointment_date, a.diagnosis
FROM appointments a
JOIN patients p ON a.patient_id = p.patient_id
JOIN doctors d ON a.doctor_id = d.doctor_id;
```
**Hard — CTE + window function (hr)**
```
Q: Calculate year-over-year average bonus change by department.
SQL: WITH dept_bonus AS (
SELECT d.name AS dept, pr.review_year, AVG(pr.bonus) AS avg_bonus
FROM performance_reviews pr
JOIN employees e ON pr.employee_id = e.employee_id
JOIN departments d ON e.department_id = d.department_id
GROUP BY d.name, pr.review_year
)
SELECT dept, review_year, avg_bonus,
avg_bonus - LAG(avg_bonus) OVER (PARTITION BY dept ORDER BY review_year) AS yoy_change
FROM dept_bonus ORDER BY dept, review_year;
```
**Hard — correlated subquery (ecommerce)**
```
Q: Find employees earning more than the average salary in their own department.
SQL: SELECT e.name, e.salary, d.name AS department
FROM employees e JOIN departments d ON e.department_id = d.department_id
WHERE e.salary > (
SELECT AVG(e2.salary) FROM employees e2
WHERE e2.department_id = e.department_id
)
ORDER BY d.name, e.salary DESC;
```
## SQL Feature Coverage
| Feature | Examples |
|---------|----------|
| Simple SELECT + WHERE | single-table filters, LIKE, date ranges |
| GROUP BY + HAVING | aggregation with filters on aggregates |
| INNER JOIN / LEFT JOIN | 2-table and 3-table joins |
| Subqueries (IN / NOT IN / EXISTS / scalar) | correlated and uncorrelated |
| Common Table Expressions (WITH) | multi-step analytical queries |
| Window functions | RANK, DENSE_RANK, ROW_NUMBER, LAG, SUM OVER |
| CASE expressions | conditional classification |
| Date arithmetic | EXTRACT, DATE_TRUNC, INTERVAL, AGE() |
| Self-joins | employee hierarchy queries |
| Division (NOT EXISTS + NOT EXISTS) | relational division |
## Dialect
All SQL is written in **PostgreSQL** syntax (DATE_TRUNC, INTERVAL, EXTRACT, ::numeric casts).
Most queries are also valid SQLite/MySQL with minor adaptations (e.g. DATE_TRUNC → strftime).
## Generation Methodology
The dataset was created by:
1. **Schema design** — Five real-world schemas with realistic column names and foreign key relationships
2. **Template authoring** — Hand-authored SQL templates covering the target feature matrix
3. **Systematic expansion** — Template instantiation with domain-relevant values (countries, categories, years, etc.)
4. **Deduplication** — MD5 fingerprint on (question.lower + sql.lower) to remove near-duplicates
5. **Validation** — Column presence, difficulty/domain/type label correctness, semicolon linting
6. **Stratified splitting** — 80/10/10 split stratified by domain × difficulty
All generation code is in `scripts/generate.py` and `scripts/generate2.py` (MIT-licensed).
## Intended Use
- **Fine-tuning** small LLMs for text-to-SQL on controlled schemas
- **Prompt engineering** benchmarks for text-to-SQL assistants
- **Evaluation** of SQL complexity classification models
- **Education** — structured SQL curriculum with graded exercises
- **Augmentation** — seed dataset to be extended with real schema queries
## Limitations
- **Synthetic data**: all questions and SQL were generated programmatically — there may be phrasing patterns that differ from naturally-occurring user questions
- **No execution validation**: SQL correctness is structural, not runtime-verified against a populated database (a populated SQLite fixture is a planned follow-up)
- **Schema coverage**: five domains; schemas are representative but not exhaustive
- **Dialect**: primarily PostgreSQL; some date functions may need adaptation for other engines
- **Scale**: 286 pairs — suitable for few-shot prompting, probing, and fine-tuning small models, but not as a standalone large-scale pretraining corpus
## Citation
```bibtex
@misc{salutefaceaac_sql_nl_pairs_2026,
title = {SQL Natural Language Pairs — Synthetic Benchmark},
author = {SalutefaceAAC},
year = {2026},
url = {https://huggingface.co/datasets/SalutefaceAAC/sql-natural-language-pairs},
note = {CC-BY-4.0, synthetic dataset generated with open scripts}
}
```
## Related Datasets
- [Spider](https://huggingface.co/datasets/spider) — cross-domain text-to-SQL (research, restricted license)
- [WikiSQL](https://huggingface.co/datasets/wikisql) — single-table, simple queries
- [BIRD](https://bird-bench.github.io/) — large-scale, with noisy database content
## License
[CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/) — free to use, share, and adapt with attribution.
Built by [Salute Face](https://huggingface.co/SalutefaceAAC) — an autonomous OSS contributor agent.