计算机科学 ›› 2026, Vol. 53 ›› Issue (6A): 250900107-7.doi: 10.11896/jsjkx.250900107
胥亚飞1, 刘传有2, 刘少华1
XU Yafei1, LIU Chuanyou2, LIU Shaohua1
摘要: Text-to-SQL技术可将自然语言自动转换为SQL,大幅降低非专业人员使用数据库的门槛,但在财务等垂直领域仍面临查询意图复杂、表述模糊两大难题。为此,提出“思维链+检索增强”协同框架。首先设计迭代蒸馏算法,利用3B小模型在Spider,BIRD,BookSQL上自动生成并验证2万余条含详细推理步骤的高质量思维链种子数据,显著弥补小模型复杂推理短板;其次,创新提出“问题骨架+SQL骨架”双向量检索机制,剔除表名列名干扰,将历史相似查询及隐含语义作为示例动态拼入提示,实现领域模糊表述精准对齐。实验表明,仅3B参数的Qwen2.5-Coder在Spider-dev达86.5%执行准确率,达到GPT-4等强模型的效果;在更复杂的BIRD-dev达59.6%,超越众多大模型;在自建Financial财务数据集达81.2%,领先现有方法超1个百分点。该方法以低成本、小参数实现了复杂且模糊自然语言查询的高精度SQL生成。
中图分类号:
| [1] LIU X Y,SHEN S Y,LI B Y,et al.A Survey of NL2SQL with Large Language Models:Where are we,and where are we going?[J].arXiv:2408.05109,2024. [2] GEORGE K,GEORGIA K.A survey on deep learning approaches for text-to-SQL[J].The VLDB Journal,2023,32(4):905-936. [3] JOSH A,ADLER S,AGARWAL S,et al.Gpt-4 technical report [J].arXiv:2303.08774,2023. [4] HUGO T,LAVRIL T,LZACARD G,et al.Llama:Open and efficient foundation language models [J].arXiv:2302.13971,2023. [5] GAN,Y J,CHEN X Y,XIE J X,et al.Natural SQL:Making SQL easier to infer from natural language specifications [C]//Findings of the Association for Computational Linguistics.2021:2030-2042. [6] TORSTEN S,NATHAN S,DZMITRY B.PICARD:Parsing incrementally for constrained auto-regressive decoding from language models [C]//Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing.2021:0895-9901. [7] ILYA S,ORIOL V,QUOC V L.Sequence to sequence learning with neural networks [C]//Advances in Neural Information Processing.2014:1-9. [8] DONG Q X,LI L,DAI D M,et al.A survey on in-context lear-ning[C]//Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing.2024:1107-1128. [9] WANG B,REN C Y,YANG J,et al.Mac-sql:A multi-agent collaborative framework for text-to-sql [C]//Proceedings of the 31st International Conference on Computational Linguistics.2025:540-557. [10] POURREZA M,DAVOOD R.Din-sql:Decomposed in-contextlearning of text-to-sql with self-correction [C]//Advances in Neural Information Processing Systems.2023:36339-36348. [11] JACOB D,CHANG M W,LEE K,et al.Bert:Pre-training of deep bidirectional transformers for language understanding [C]//Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics:Human Language Technologies.2019:4171-4186. [12] TAO Y,ZHANG R,YANG K,et al.Spider:A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task [C]//2018 Conference on Empirical Methods in Natural Language Processing.EMNLP,2018:3911-3921. [13] WANG B,SHIN R,LIU X D,et al.Rat-sql:Relation-awareschema encoding and linking for text-to-sql parsers [C]//Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics.2020:7567-7578. [14] FRANCO S,GORI M,TSOI A C,et al.The graph neural network model [J].IEEE Transactions on Neural Networks,2008,20(1):61-80. [15] LI H Y,ZHANG J,LIU H B,et al.Codes:Towards buildingopen-source language models for text-to-sql [C]//Proceedings of the ACM on Management of Data.2024:1-28. [16] LI R,LOUBNA B A,ZI Y T,et al.Starcoder:may the source be with you![J].arXiv:2305.06161,2023. [17] GAO D W,WANG H B,LI Y L,et al.Text-to-sql empowered by large language models:A benchmark evaluation [C]//Proceedings of the VLDB Endowment.2024:1132-1145. [18] DONG X M,ZHANG C,GE Y H,et al.C3:Zero-shot text-to-sql with chatgpt[J].arXiv:2307.07306,2023. [19] CUI Y M,CHE W X,LIU T,et al.Pre-training with wholeword masking for chinesebert[J].IEEE/ACM Transactions on Audio,Speech,and Language Processing,2021(29):3504-3514. [20] GAN Y J,CHEN X Y,HUANG Q P,et al.Towards robustness of text-to-SQL models against synonym substitution[J].arXiv:2106.01065,2021. [21] DENG X,AHMED H A,CHRISTOPHER M,et al,Structure-grounded pretraining for text-to-sql[J].arXiv:2010.12773,2020. [22] GAO D W,WANG H B,LI Y L,et al.Text-to-sql empowered by large language models:A benchmark evaluation[J].arXiv:2308.15363,2023. [23] WEI J,WANG X Z,DALE S,et al.Chain-of-thought prompting elicits reasoning in large language models[C]//Advances in Neural Information Processing Systems.2022:24824-24837. [24] KUMAR R,AMAR R D,SHRUTENDRA H,et al.Booksql:A large scale text-to-sql dataset for accounting domain[J].arXiv:2406.07860,2024. [25] LI H Y,WU S,ZHANG X K,et al.Omnisql:Synthesizing high-quality text-to-sql data at scale[J].arXiv:2503.02240,2025. [26] POURREZA M,DAVOOD R.Dts-sql:Decomposed text-to-sql with small large language models[J].arXiv:2402.01117,2024. [27] YANG J X,HUI B Y,YANG M,et al.Synthesizing text-to-SQL data from weak and strong LLMs[C]//Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics.2024:7864-7875. |
|
||