text-to-sql-dataset
收藏资源简介:
English Text-to-SQL with Optional Schema 是一个用于英文文本到SQL转换任务的数据集,旨在将自然语言问题映射为对应的SQL查询。其独特之处在于支持可选的数据模式:当提供模式时,它以紧凑、人类可读的格式呈现,即用逗号分隔的表名列表,后跟括号内的列名(不包含数据类型);当不提供模式时,模型需要推断表结构或生成通用SQL。数据集包含三个核心字段:text(英文用户请求)、schema(可选的简洁模式定义)和query(回答text的SQL查询)。数据规模约为2,000个样本,涵盖图书馆、电子商务、人力资源等多个领域。该数据集通过结合使用DeepSeek、ChatGPT、Gemini和Claude Sonnet等多种大型语言模型合成生成,并经过过滤和格式化以确保基本语法正确性。主要适用于微调语言模型进行文本到SQL任务、在有/无显式模式上下文的情况下进行SQL生成的基准测试,以及构建需要简洁传达数据库模式的自然语言接口。数据集采用MIT许可证,但用户需注意其合成性质可能包含错误或不一致,且规模相对较小,可能需要增强以进行大规模训练。
English Text-to-SQL with Optional Schema is a dataset for text-to-SQL conversion tasks, specifically designed to map English natural language questions to corresponding SQL queries. Its unique feature is the support for optional schema: when provided, the schema is presented in a compact, human-readable format, which is a comma-separated list of table names followed by column names in parentheses (without data types); when not provided, the model needs to infer the table structure or generate generic SQL. The dataset includes three core fields: text (English user request), schema (optional concise schema definition), and query (SQL query answering the text). The data scale is approximately 2,000 samples, covering multiple domains such as libraries, e-commerce, and human resources. The dataset is synthetically generated using a combination of large language models including DeepSeek, ChatGPT, Gemini, and Claude Sonnet, and has been filtered and formatted to ensure basic grammatical correctness. It is primarily suitable for fine-tuning language models for text-to-SQL tasks, benchmarking SQL generation with/without explicit schema context, and building natural language interfaces that require concise communication of database schemas. The dataset is under the MIT license, but users should note its synthetic nature may contain errors or inconsistencies, and its relatively small scale may require augmentation for large-scale training.
Text-to-SQL 数据集概述
该数据集为英文 Text-to-SQL 任务设计,将用户输入的英文问题映射为对应的 SQL 查询语句。数据集的核心特点是提供可选的数据库模式(Schema),让模型可以在带或不带显式模式信息的条件下进行 SQL 生成。
数据集结构
| 列名 | 类型 | 描述 |
|---|---|---|
text |
字符串 | 用户提出的英文请求。 |
schema |
字符串(可选) | 精简的数据库模式定义,格式如 books(id, name, price, author_id), author(id, name)。若未提供,则为空字符串或 null。 |
query |
字符串 | 对应上述 text 的 SQL 查询语句,在给定模式(或当 schema 缺失时默认的隐含模式)下有效。 |
关键特性
- 语言:所有
text为英文。 - Schema 格式:紧凑、易读、易解析,采用
表名(列1, 列2, ...), ...格式,聚焦于列名与表关系。 - 可选 Schema:许多样本不提供 Schema,训练模型推断表结构或生成通用 SQL。
- 规模:约 2,000 条样本(仍在扩展中)。
示例
text |
schema |
query |
|---|---|---|
| "List all books with their author names" | books(id, name, price, author_id), author(id, name) |
SELECT books.name, author.name FROM books JOIN author ON books.author_id = author.id; |
| "Show me books priced above 20" | books(id, name, price, author_id) |
SELECT * FROM books WHERE price > 20; |
| "Count how many authors we have" | (空) | SELECT COUNT(*) FROM authors; |
预期用途
- 微调语言模型以完成 Text-to-SQL 任务。
- 在带/不带显式 Schema 语境下,基准测试 SQL 生成性能。
- 构建能够简洁传达数据库模式的自然语言接口。
数据集创建
该数据集通过合成方式生成,使用了多个开源大语言模型(包括 DeepSeek、ChatGPT、Gemini、Claude Sonnet)。通过多样化的提示词生成跨领域(如图书馆、电商、人力资源)的问题-SQL 对,经筛选与格式化保证基本语法正确性。数据可能反映底层模型的偏差与局限。
许可
遵循 MIT 许可证,可自由使用、复制、修改、合并、发布、分发、再许可或销售。需附带版权声明与许可声明。注意:数据集由第三方 LLM 生成,使用者应核查各模型服务条款(OpenAI、Google、Anthropic、DeepSeek),确保商业用途合规。
局限
- 仅英文:仅包含英文自然语言查询。
- 简单模式:Schema 紧凑,可能未完整表示外键、数据类型、索引等复杂约束。
- 合成性质:AI 生成,可能包含错误、不一致或非真实查询,不可替代人工标注或真实数据。
- 规模有限:样本不足 3,000 条,大规模训练可能需要扩充。
- 隐含模式歧义:缺失
schema时,正确 SQL 基于未提供的隐含模式,限制该类样本的训练效用。




