SQLoom: Set-Contrastive Learning of Syntactic, Semantic, and Logical Dependencies for Text-to-SQL
作者: Hao Fu, Degang Sun, Wan Wei, Jinxia Wei, Chun Long, Peng Gao
分类: cs.DB, cs.AI
发布日期: 2026-11-02
💡 一句话要点
提出SQLoom以解决文本到SQL转换中的依赖建模问题
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 文本到SQL 约束感知 集合对比学习 自然语言处理 数据库查询生成
📋 核心要点
- 现有的文本到SQL方法将SQL视为普通文本,未能有效建模其语法、语义和逻辑依赖,导致错误的查询未能被有效识别。
- SQLoom通过引入约束感知的微调框架,针对SQL的语法有效性、语义对齐和逻辑一致性进行三层次的监督,提升了模型的表现。
- 实验结果显示,SQLoom在Spider开发集上将Qwen3-1.7B的执行准确率从62.9%提升至88.7%,在BIRD开发集上达到73.4%的准确率。
📝 摘要(中文)
文本到SQL(Text-to-SQL)将自然语言问题转换为SQL查询,使得无需编写SQL即可访问数据库。现有方法将SQL视为普通文本,优化令牌级别的可能性,而未明确建模其语法、语义和逻辑要求。为此,本文提出SQLoom,一个约束感知的微调框架,针对SQL语法和数据库模式的语法有效性、查询决策与问题之间的语义对齐以及依赖子句决策之间的逻辑一致性提供三层次的监督。SQLoom通过统一的集合对比目标扩展了监督微调,优先考虑每个层次上正确输出的集合而非最小不同的错误输出。实验结果表明,SQLoom显著提高了执行准确性,尤其在Spider和BIRD数据集上表现优异。
🔬 方法详解
问题定义:本文旨在解决文本到SQL转换中,现有方法未能有效建模SQL的语法、语义和逻辑依赖的问题。现有方法在处理错误查询时,未能提供足够的训练损失反馈,导致模型性能下降。
核心思路:SQLoom的核心思想是引入约束感知的微调框架,通过三层次的监督来确保SQL查询的语法有效性、语义一致性和逻辑合理性,从而提高模型的生成能力。
技术框架:SQLoom的整体架构包括三个主要模块:语法有效性检查模块、语义对齐模块和逻辑一致性模块。每个模块都通过集合对比目标进行优化,确保生成的SQL查询符合预期的标准。
关键创新:SQLoom的主要创新在于引入了集合对比的监督机制,优先考虑正确输出的集合而非单个令牌的优化,这与传统的令牌级别训练方法形成了鲜明对比。
关键设计:在损失函数设计上,SQLoom采用了集合对比损失,确保在每个层次上都能有效区分正确与错误的输出。此外,SQL解析器和执行模块用于验证生成的SQL查询的有效性。
🖼️ 关键图片
📊 实验亮点
SQLoom在Spider开发集上将Qwen3-1.7B的执行准确率从62.9%提升至88.7%,在Spider测试集上达到89.2%,在BIRD开发集上达到73.4%。与基于强化学习和代理的方法相比,SQLoom在问题扰动下的准确率损失仅为0.6,而其他方法则高达12.1,显示出其优越性。
🎯 应用场景
SQLoom的研究成果在数据库查询生成、自然语言处理和人工智能助手等领域具有广泛的应用潜力。通过提高文本到SQL的转换准确性,能够使非技术用户更方便地访问和操作数据库,推动智能问答系统和数据分析工具的发展。
📄 摘要(原文)
Text-to-SQL translates natural language questions into SQL queries, enabling database access without writing SQL. Fine-tuning open-weight large language models (LLMs) is cost-effective, but existing methods treat SQL as ordinary text and optimize token-level likelihood without explicitly modeling its syntactic, semantic, and logical requirements. Thus, a single incorrect alias or comparison operator can invalidate a query while contributing little to training loss. We propose SQLoom, a constraint-aware fine-tuning framework with supervision at three levels: syntactic validity under SQL grammar and database schema, semantic alignment between query decisions and the question, and logical consistency across dependent clause decisions. SQLoom extends supervised fine-tuning with a unified set-contrastive objective favoring sets of correct outputs over minimally different incorrect ones at each level. LLM agents propose this supervision, which a SQL parser and execution on counterexample databases verify. We also release Spider-Refined, a training dataset correcting 378 flawed Spider annotations and enriching database schemas. Experiments on Spider, BIRD, and three perturbed Spider variants show that SQLoom improves execution accuracy for Qwen3-1.7B from 62.9% zero-shot to 88.7% on Spider development, reaching 89.2% on Spider test and 73.4% on BIRD development. It outperforms fine-tuning, reinforcement learning, and agent-based baselines with up to 70 billion parameters. On question perturbations, SQLoom loses at most 0.6 accuracy points versus up to 12.1 for agent-based methods. It generates SQL in a single pass at 0.42s per query, 23$\times$ faster than a GPT-4-based agent method. These results demonstrate the effectiveness of set-contrastive supervision over token-level training.