通过分层结构提升文本转SQL的语义验证能力
Bridging Global Intent with Local Details: A Hierarchical Representation Approach for Semantic Validation in Text-to-SQL
- 用逻辑计划与抽象语法树融合全局意图与局部细节
- 在跨域测试中语义错误检测AUPRC提升9.40%
- 适合需要高可靠SQL生成的智能数据查询系统
文本转SQL将自然语言问题转化为基于目标数据库模式的SQL语句。确保系统可靠性与可执行性需验证生成的SQL,但现有方法多关注语法正确性,极少解决语义验证(检测问题与SQL之间的不一致)。为此,我们提出HEROSQL,一种分层SQL表示方法,整合逻辑计划(LPs)捕捉全局意图,结合抽象语法树(ASTs)保留局部细节。采用嵌套消息传递神经网络(NMPNN)捕获SQL内在关系,并在LP与AST间聚合受模式引导的语义。此外,提出基于AST的子SQL增强策略以生成高质量负样本,支持细粒度语义不一致的鲁棒优化。在文本转SQL验证基准(含域内与跨域设置)上的实验表明,该方法优于现有最先进方法,平均提升AUPRC 9.40%、AUROC 12.35%,显著增强对细粒度语义错误的检测能力,为大模型提供更精确反馈,提升数据查询平台的可靠性与可解释性。
原文摘要 · Abstract (English)
Text-to-SQL translates natural language questions into SQL statements grounded in a target database schema. Ensuring the reliability and executability of such systems requires validating generated SQL, but most existing approaches focus only on syntactic correctness, with few addressing semantic validation (detecting misalignments between questions and SQL). As a consequence, effective semantic validation still faces two key challenges: capturing both global user intent and SQL structural details, and constructing high-quality fine-grained sub-SQL annotations. To tackle these, we introduce HEROSQL, a hierarchical SQL representation approach that integrates global intent (via Logical Plans, LPs) and local details (via Abstract Syntax Trees, ASTs). To enable better information propagation, we employ a Nested Message Passing Neural Network (NMPNN) to capture inherent relational information in SQL and aggregate schema-guided semantics across LPs and ASTs. Additionally, to generate high-quality negative samples, we propose an AST-driven sub-SQL augmentation strategy, supporting robust optimization of fine-grained semantic inconsistencies. Extensive experiments conducted on Text-to-SQL validation benchmarks (both in-domain and out-of-domain settings) demonstrate that our approach outperforms existing state-of-the-art methods, achieving an average 9.40% improvement of AUPRC and 12.35% of AUROC in identifying semantic inconsistencies. It excels at detecting fine-grained semantic errors, provides large language models with more granular feedback, and ultimately enhances the reliability and interpretability of data querying platforms.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。