资源简介:
---
license: cc-by-4.0
task_categories:
- text-generation
- question-answering
- table-question-answering
language:
- id
tags:
- SQL
- code
- NLP
- text-to-sql
- context-sql
- spider
- wikisql
- sqlglot
pretty_name: sql-create-context-id
size_categories:
- 10K<n<100K
---
#### Overview
This dataset is a fork from [sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) <br>
This dataset builds from [WikiSQL](https://huggingface.co/datasets/wikisql) and [Spider](https://huggingface.co/datasets/spider).
There are 78,577 examples of natural language queries, SQL CREATE TABLE statements, and SQL Query answering the question using the CREATE statement as context. This dataset was built with text-to-sql LLMs in mind, intending to prevent hallucination of column and table names often seen when trained on text-to-sql datasets. The CREATE TABLE statement can often be copy and pasted from different DBMS and provides table names, column names and their data types. By providing just the CREATE TABLE statement as context, we can hopefully provide better grounding for models without having to provide actual rows of data, limiting token usage and exposure to private, sensitive, or proprietary data.
#### Cleansing and Augmentation
Cleansing and data augmentation has been done on the combined WikiSQL and Spider data. I used [SQLGlot](https://github.com/tobymao/sqlglot) on queries from Spider and WikiSQL and parsed them into different tables and columns, I then inferred column data types based on usage of `>` `<` operators as well as the use of `MIN()` `MAX()` `AVG()` `SUM()` on columns. While this isn't perfect, it increases the likelihood of inferring the correct datatype for a column, the columns otherwise default to VARCHAR type. These tables and columns are then used to generate CREATE TABLE statements using the inferred types. SQLGlot is used again to ensure both the SQL queries and CREATE TABLE statements parse without errors.
Some queries that do not have column names, e.g. SELECT * FROM table, have a default Id column added to the CREATE TABLE statement. Some other queries which use the generic `table` as the FROM table have instead been changed to a variation of `table_name_1` or some other number which is also reflected in the CREATE TABLE statement.
#### TODO
- Further augment the data by converting queries and CREATE TABLE statements into different SQL dialects, this can be done with SQLGlot. Reference to the dialect might also be added to the question.
- Support other informative contexts beyond CREATE TABLE
- Better parse datatypes to clean up things like numbers for column names and other numbers as strings
If you have any edits you'd like to see in a version 2 of this dataset, let me know.
Random sample:
```json
{
"question": "Berapa banyak kepala departemen yang lebih tua dari 56 tahun?",
"context": "CREATE TABLE head (age INTEGER)",
"answer": "SELECT COUNT(*) FROM head WHERE age > 56"
},
{
"question": "Sebutkan nama, lahir negara bagian mana dan usia kepala departemen yang dipesan berdasarkan usia.",
"context": "CREATE TABLE head (name VARCHAR, born_state VARCHAR, age VARCHAR)",
"answer": "SELECT name, born_state, age FROM head ORDER BY age"
},
```
license: CC-BY-4.0
task_categories:
- 文本生成
- 问答
- 表格问答
language:
- 印尼语(id)
tags:
- 结构化查询语言(SQL)
- 代码
- 自然语言处理(Natural Language Processing,NLP)
- 文本到SQL(text-to-sql)
- 上下文SQL(context-sql)
- Spider(spider)
- WikiSQL(wikisql)
- SQLGlot(sqlglot)
pretty_name: sql-create-context-id
size_categories:
- 10000 < 样本数量 < 100000
---
#### 数据集概览
本数据集为 [sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) 的派生分支,基于 [WikiSQL](https://huggingface.co/datasets/wikisql) 与 [Spider](https://huggingface.co/datasets/spider) 构建而成。
本数据集包含78577条样本,每条样本涵盖自然语言查询语句、SQL建表语句,以及以该建表语句为上下文来回答对应问题的SQL查询语句。本数据集专为文本到SQL的大语言模型(Large Language Model,LLM)设计,旨在避免在训练文本到SQL模型时常见的表名与列名幻觉问题。SQL建表语句通常可从不同数据库管理系统(Database Management System,DBMS)中复制粘贴,其包含了表名、列名及其数据类型。仅通过提供SQL建表语句作为上下文,我们即可在无需提供实际数据行的前提下为模型提供更优质的上下文锚定效果,同时限制词元(Token)的使用量,并避免接触私有、敏感或专有数据。
#### 数据清洗与增强
我们已对合并后的WikiSQL与Spider数据集进行了清洗与数据增强操作:针对Spider与WikiSQL中的查询语句使用了[SQLGlot](https://github.com/tobymao/sqlglot)工具,将其解析为不同的表与列;随后基于列上的`>`、`<`运算符使用情况,以及对列使用`MIN()`、`MAX()`、`AVG()`、`SUM()`聚合函数的情况,推断列的数据类型。尽管该方法并非完美无缺,但它提升了为列推断正确数据类型的概率,未被推断的列将默认采用VARCHAR类型。随后我们将这些表与列结合推断出的数据类型用于生成SQL建表语句,并再次使用SQLGlot工具确保所有SQL查询语句与建表语句均可无错误地解析。
对于未指定列名的查询语句(例如`SELECT * FROM table`),我们会在对应的建表语句中添加一个默认的Id列。部分使用通用`table`作为来源表的查询语句已被替换为`table_name_1`或其他带序号的表名,对应的建表语句也会同步更新。
#### 待办事项
- 通过将查询语句与建表语句转换为不同的SQL方言进一步增强数据集,该操作可通过SQLGlot完成,同时还可在问题中添加对应方言的相关说明。
- 支持除SQL建表语句之外的其他信息上下文。
- 优化数据类型解析逻辑,以处理列名中的数字以及以字符串形式存储的数字等场景。
若您希望为本数据集的V2版本提出修改建议,欢迎随时告知。
随机样本:
json
{
"question": "Berapa banyak kepala departemen yang lebih tua dari 56 tahun?",
"context": "CREATE TABLE head (age INTEGER)",
"answer": "SELECT COUNT(*) FROM head WHERE age > 56"
},
{
"question": "Sebutkan nama, lahir negara bagian mana dan usia kepala departemen yang dipesan berdasarkan usia.",
"context": "CREATE TABLE head (name VARCHAR, born_state VARCHAR, age VARCHAR)",
"answer": "SELECT name, born_state, age FROM head ORDER BY age"
},