NSQL
数字站文本转SQL模型代码。
NSQL是一系列专门为SQL生成任务设计的自回归开源大型基础模型(FMs)。所有模型权重都在HuggingFace上提供。
模型名称 | 大小 | 链接 |
---|---|---|
NumbersStation/nsql-350M | 350M | 链接 |
NumbersStation/nsql-2B | 2.7B | 链接 |
NumbersStation/nsql-6B | 6B | 链接 |
NumbersStation/nsql-llama-2-7B | 7B | 链接 |
设置
安装时,运行
pip install -r requirements.txt
使用方法
查看examples/
中的示例,了解如何连接到Postgres或SQLite以直接对您的数据提问。以下是来自examples/
目录的一个简短代码片段。
在单独的屏幕或窗口中运行
python3 -m manifest.api.app \
--model_type huggingface \
--model_generation_type text-generation \
--model_name_or_path NumbersStation/nsql-350M \
--device 0
然后运行
from db_connectors import PostgresConnector
from prompt_formatters import RajkumarFormatter
from manifest import Manifest
postgres_connector = PostgresConnector(
user=USER, password=PASSWORD, dbname=DATABASE, host=HOST, port=PORT
)
postgres_connector.connect()
db_schema = [postgres_connector.get_schema(table) for table in postgres_connector.get_tables()]
formatter = RajkumarFormatter(db_schema)
manifest_client = Manifest(client_name="huggingface", client_connection="http://127.0.0.1:5000")
def get_sql(instruction: str, max_tokens: int = 300) -> str:
prompt = formatter.format_prompt(instruction)
res = manifest_client.run(prompt, max_tokens=max_tokens)
return formatter.format_model_output(res)
print(get_sql("表中的行数是多少?"))
数据准备
在data_prep
文件夹中,我们提供了数据准备脚本,用于生成NSText2SQL来训练NSQL模型。
许可证
本仓库中的代码采用Apache 2.0许可证。除非另有说明,
版权所有 2023 Numbers Station
根据Apache许可证2.0版("许可证")获得许可;
除非遵守许可证,否则您不得使用此文件。
您可以在以下位置获取许可证副本:
http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则根据许可证分发的软件
是基于"按原样"分发的,不附带任何明示或暗示的担保或条件。
有关许可证下的特定语言管理权限和限制,请参阅许可证。
生成NSText2SQL的数据来自具有各种许可证的仓库。使用NSText2SQL中收集的全部或部分数据必须遵守原始许可证的条款,包括相关的归属条款。我们感谢所有提供这些数据集的作者。我们在下面提供了每个数据集的来源信息。
有关完整条款,请参阅LICENSE文件。如果您对许可有任何问题、意见或疑虑,请联系我们。
引用本作品
如果您在工作中使用了这些数据,请引用我们的工作并引用适当的原始来源:
引用NSText2SQL时,请使用:
@software{numbersstation2023NSText2SQL,
author = {Numbers Station Labs},
title = {NSText2SQL: An Open Source Text-to-SQL Dataset for Foundation Model Training},
month = {July},
year = {2023},
url = {https://github.com/NumbersStationAI/NSQL},
}
引用本作品中使用的数据集时,请使用:
数据集 | 引用 |
---|---|
academic | \cite{data-advising,data-academic} |
advising | \cite{data-advising} |
atis | \cite{data-advising,data-atis-original,data-atis-geography-scholar} |
restaurants | \cite{data-advising,data-restaurants-logic,data-restaurants-original,data-restaurants} |
scholar | \cite{data-advising,data-atis-geography-scholar} |
imdb | \cite{data-advising,data-imdb-yelp} |
yelp | \cite{data-advising,data-imdb-yelp} |
criteria2sql | \cite{Criteria-to-SQL} |
css | \cite{zhang2023css} |
eICU | \cite{lee2022ehrsql} |
mimic_iii | \cite{lee2022ehrsql} |
geonucleardata | \cite{lee-2021-kaggle-dbqa} |
greatermanchestercrime | \cite{lee-2021-kaggle-dbqa} |
studentmathscore | \cite{lee-2021-kaggle-dbqa} |
thehistoryofbaseball | \cite{lee-2021-kaggle-dbqa} |
uswildfires | \cite{lee-2021-kaggle-dbqa} |
whatcdhiphop | \cite{lee-2021-kaggle-dbqa} |
worldsoccerdatabase | \cite{lee-2021-kaggle-dbqa} |
pesticide | \cite{lee-2021-kaggle-dbqa} |
mimicsql_data | \cite{wang2020text} |
nvbench | \cite{nvBench_SIGMOD21} |
sede | \cite{hazoom2021text} |
spider | \cite{data-spider} |
sql_create_context | 未找到 |
squall | \cite{squall} |
wikisql | \cite{data-wikisql} |
@InProceedings{data-advising,
dataset = {Advising},
author = {Catherine Finegan-Dollak, Jonathan K. Kummerfeld, Li Zhang, Karthik Ramanathan, Sesh Sadasivam, Rui Zhang, 和 Dragomir Radev},
title = {改进文本到SQL评估方法},
booktitle = {第56届计算语言学协会年会论文集(第1卷:长文)},
month = {7月},
year = {2018},
location = {澳大利亚维多利亚州墨尔本},
pages = {351--360},
url = {http://aclweb.org/anthology/P18-1033},
}
@InProceedings{data-imdb-yelp,
dataset = {IMDB和Yelp},
author = {Navid Yaghmazadeh, Yuepeng Wang, Isil Dillig, 和 Thomas Dillig},
title = {SQLizer: 从自然语言合成查询},
booktitle = {面向对象编程、系统、语言和应用国际会议, ACM},
month = {10月},
year = {2017},
pages = {63:1--63:26},
url = {http://doi.org/10.1145/3133887},
}
@article{data-academic,
dataset = {Academic},
author = {Fei Li 和 H. V. Jagadish},
title = {为关系数据库构建交互式自然语言界面},
journal = {VLDB基金会会报},
volume = {8},
number = {1},
month = {9月},
year = {2014},
pages = {73--84},
url = {http://dx.doi.org/10.14778/2735461.2735468},
}
@InProceedings{data-atis-geography-scholar,
dataset = {Scholar, 以及更新的ATIS和Geography},
author = {Srinivasan Iyer, Ioannis Konstas, Alvin Cheung, Jayant Krishnamurthy, 和 Luke Zettlemoyer},
title = {从用户反馈中学习神经语义解析器},
booktitle = {第55届计算语言学协会年会论文集(第1卷:长文)},
year = {2017},
pages = {963--973},
location = {加拿大温哥华},
url = {http://www.aclweb.org/anthology/P17-1089},
}
@article{data-atis-original,
dataset = {ATIS, 原始},
author = {Deborah A. Dahl, Madeleine Bates, Michael Brown, William Fisher, Kate Hunicke-Smith, David Pallett, Christine Pao, Alexander Rudnicky, 和 Elizabeth Shriber},
title = {{扩展ATIS任务范围:ATIS-3语料库}},
journal = {人类语言技术研讨会论文集},
year = {1994},
pages = {43--48},
url = {http://dl.acm.org/citation.cfm?id=1075823},
}
@inproceedings{data-restaurants-logic,
author = {Lappoon R. Tang 和 Raymond J. Mooney},
title = {数据库界面的自动构建:整合统计和关系学习进行语义解析},
booktitle = {2000年SIGDAT联合会议:自然语言处理实证方法和大规模语料库},
year = {2000},
pages = {133--141},
location = {中国香港},
url = {http://www.aclweb.org/anthology/W00-1317},
}
@inproceedings{data-restaurants-original,
author = {Ana-Maria Popescu, Oren Etzioni, 和 Henry Kautz},
title = {走向数据库自然语言界面理论},
booktitle = {第8届智能用户界面国际会议论文集},
year = {2003},
location = {美国佛罗里达州迈阿密},
pages = {149--157},
url = {http://doi.acm.org/10.1145/604045.604070},
}
@inproceedings{data-restaurants,
author = {Alessandra Giordani 和 Alessandro Moschitti},
title = {自动生成和重新排序SQL衍生的自然语言问题答案},
booktitle = {第二届通过软件、数据和知识演化的可信永恒系统国际会议论文集},
year = {2012},
location = {法国蒙彼利埃},
pages = {59--76},
url = {https://doi.org/10.1007/978-3-642-45260-4_5},
}
@InProceedings{data-spider,
author = {Tao Yu, Rui Zhang, Kai Yang, Michihiro Yasunaga, Dongxu Wang, Zifan Li, James Ma, Irene Li, Qingning Yao, Shanelle Roman, Zilin Zhang, 和 Dragomir Radev},
title = {Spider:一个大规模的人工标注数据集,用于复杂和跨域语义解析及文本到SQL任务},
booktitle = {2018年自然语言处理实证方法会议论文集},
year = {2018},
location = {比利时布鲁塞尔},
pages = {3911--3921},
url = {http://aclweb.org/anthology/D18-1425},
}
@article{data-wikisql,
author = {Victor Zhong, Caiming Xiong, 和 Richard Socher},
title = {Seq2SQL:使用强化学习从自然语言生成结构化查询},
year = {2017},
journal = {CoRR},
volume = {abs/1709.00103},
}
@InProceedings{Criteria-to-SQL,
author = {Yu, Xiaojing 和 Chen, Tianlong 和 Yu, Zhengjie 和 Li, Huiyu 和 Yang, Yang 和 Jiang, Xiaoqian 和 Jiang, Anxiao},
title = {资格标准到SQL语义解析的数据集和增强模型},
booktitle = {第12届语言资源与评估会议论文集},
month = {5月},
year = {2020},
address = {法国马赛},
publisher = {欧洲语言资源协会},
pages = {5831--5839},
}
@misc{zhang2023css,
title = {CSS:一个大规模跨模式中文文本到SQL医疗数据集},
author = {Hanchong Zhang 和 Jieyu Li 和 Lu Chen 和 Ruisheng Cao 和 Yunyan Zhang 和 Yu Huang 和 Yefeng Zheng 和 Kai Yu},
year = {2023},
}
@article{lee2022ehrsql,
title = {EHRSQL:一个面向电子健康记录的实用文本到SQL基准},
author = {Lee, Gyubok 和 Hwang, Hyeonji 和 Bae, Seongsu 和 Kwon, Yeonsu 和 Shin, Woncheol 和 Yang, Seongjun 和 Seo, Minjoon 和 Kim, Jong-Yeup 和 Choi, Edward},
journal = {神经信息处理系统进展},
volume = {35},
pages = {15589--15601},
year = {2022},
}
@inproceedings{lee-2021-kaggle-dbqa,
title = {KaggleDBQA:文本到SQL解析器的现实评估},
author = {Lee, Chia-Hsuan 和 Polozov, Oleksandr 和 Richardson, Matthew},
booktitle = {第59届计算语言学协会年会暨第11届国际自然语言处理联合会议论文集(第1卷:长文)},
pages = {2261--2273},
year = {2021},
}
@inproceedings{squall, title = {论词汇-逻辑对齐对语义解析SQL查询的潜力}, author = {Tianze Shi and Chen Zhao and Jordan Boyd-Graber and Hal {Daum'{e} III} and Lillian Lee}, booktitle = {EMNLP发现}, year = {2020}, }
@article{hazoom2021text, title = {自然环境中的文本到SQL:基于Stack Exchange数据的自然数据集}, author = {Hazoom, Moshe and Malik, Vibhor and Bogin, Ben}, journal = {arXiv预印本 arXiv:2106.05006}, year = {2021}, }
@inproceedings{wang2020text, title = {用于电子病历问答的文本到SQL生成}, author = {Wang, Ping and Shi, Tian and Reddy, Chandan K}, booktitle = {2020年万维网会议论文集}, pages = {350--361}, year = {2020}, }
@inproceedings{nvBench_SIGMOD21, title = {从NL2SQL基准合成自然语言到可视化(NL2VIS)基准}, author = {罗瑜瑜 and 唐楠 and 李国梁 and 柴成梁 and 李文博 and 秦雪笛}, booktitle = {2021年数据管理国际会议论文集,{SIGMOD}会议2021,2021年6月20-25日,中国虚拟活动}, publisher = {ACM}, year = {2021}, }
致谢
我们感谢所有作者为这些数据集所做的工作,使本项目成为可能。