Defective Task Descriptions in LLM-Based Code Generation: Detection and Analysis
作者: Amal Akli, Mike Papadakis, Maxime Cordy, Yves Le Traon
分类: cs.SE, cs.AI
发布日期: 2026-04-27
💡 一句话要点
提出SpecValidator,用于检测LLM代码生成中任务描述的缺陷。
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码生成 大型语言模型 任务描述缺陷检测 缺陷分类 参数高效微调
📋 核心要点
- 现有LLM代码生成依赖于高质量的任务描述,但实际应用中用户提供的描述可能存在词汇模糊、欠规范等缺陷,影响代码质量。
- 论文提出SpecValidator,一个轻量级分类器,通过参数高效微调小型模型,自动检测任务描述中的缺陷。
- 实验结果表明,SpecValidator在缺陷检测方面显著优于GPT-3.5-turbo和Claude Sonnet 3,并能泛化到未知的欠规范缺陷。
📝 摘要(中文)
大型语言模型(LLM)被广泛应用于代码生成,但它们依赖于一个隐含的假设,即任务描述足够详细且形式良好。然而,在实践中,用户可能提供有缺陷的描述,这会对代码的正确性产生很大影响。为了解决这个问题,我们开发了SpecValidator,这是一个基于小型模型的轻量级分类器,通过参数高效的微调来自动检测任务描述缺陷。我们在三个基准测试上评估了SpecValidator在三种类型的缺陷(词汇模糊、欠规范和语法格式)上的表现,这些基准测试具有不同结构和复杂性的任务描述。结果表明,SpecValidator实现了F1 = 0.804和MCC = 0.745的缺陷检测性能,显著优于GPT-3.5-turbo(原文应为GPT-3.5-turbo,摘要误写为GPT-5-mini,此处已更正)和Claude Sonnet 3。更重要的是,我们的分析表明SpecValidator可以推广到未见过的问题,并检测到基准测试原始(真实)描述中未知的欠规范缺陷。我们的结果还表明,LLM在任务描述缺陷方面的鲁棒性主要取决于缺陷的类型和任务描述的特征,而不是模型的能力,其中欠规范缺陷最为严重。我们进一步发现,具有更丰富上下文基础的基准测试(如LiveCodeBench)表现出更高的弹性,突出了结构化任务描述对于可靠的基于LLM的代码生成的重要性。
🔬 方法详解
问题定义:论文旨在解决LLM代码生成中由于任务描述缺陷导致的代码质量下降问题。现有方法通常假设任务描述是完善的,忽略了实际应用中用户可能提供不完整、模糊或格式错误的描述,从而影响LLM生成代码的正确性和可靠性。
核心思路:论文的核心思路是训练一个专门用于检测任务描述缺陷的轻量级分类器SpecValidator。通过对小型模型进行参数高效的微调,使其能够识别不同类型的缺陷,从而在代码生成之前过滤掉不良的任务描述。
技术框架:SpecValidator的整体框架包括以下步骤:1)收集包含各种类型缺陷的任务描述数据集;2)选择一个小型预训练语言模型作为基础模型;3)使用参数高效的微调技术(具体技术未知)对模型进行训练,使其能够区分有缺陷和无缺陷的任务描述;4)使用训练好的SpecValidator对新的任务描述进行缺陷检测。
关键创新:SpecValidator的关键创新在于其轻量级和高效性。通过使用小型模型和参数高效的微调技术,SpecValidator能够在保持较高检测精度的同时,降低计算成本和部署难度。此外,SpecValidator还能够泛化到未知的欠规范缺陷,表明其具有较强的鲁棒性。
关键设计:论文中没有详细说明SpecValidator的关键设计细节,例如具体的参数设置、损失函数或网络结构。但是,可以推断出,该模型可能使用了某种形式的序列分类器,并针对任务描述缺陷检测进行了优化。参数高效的微调技术可能是LoRA或Adapter等方法(具体未知)。
🖼️ 关键图片
📊 实验亮点
SpecValidator在缺陷检测方面取得了显著的性能提升,F1值达到0.804,MCC值达到0.745,显著优于GPT-3.5-turbo(F1 = 0.469,MCC = 0.281)和Claude Sonnet 3(F1 = 0.518,MCC = 0.359)。更重要的是,SpecValidator能够泛化到未知的欠规范缺陷,表明其具有较强的鲁棒性。
🎯 应用场景
该研究成果可应用于各种基于LLM的代码生成场景,例如自动化软件开发、代码补全、智能编程助手等。通过在代码生成流程中加入SpecValidator,可以有效过滤掉有缺陷的任务描述,提高生成代码的质量和可靠性,降低开发成本,并提升用户体验。未来,该技术还可以扩展到其他自然语言处理任务,例如文本摘要、机器翻译等。
📄 摘要(原文)
Large language models are widely used for code generation, yet they rely on an implicit assumption that the task descriptions are sufficiently detailed and well-formed. However, in practice, users may provide defective descriptions, which can have a strong effect on code correctness. To address this issue, we develop SpecValidator, a lightweight classifier based on a small model that has been parameter-efficiently finetuned, to automatically detect task description defects. We evaluate SpecValidator on three types of defects, Lexical Vagueness, Under-Specification and Syntax-Formatting on 3 benchmarks with task descriptions of varying structure and complexity. Our results show that SpecValidator achieves defect detection of F1 = 0.804 and MCC = 0.745, significantly outperforming GPT-5-mini (F1 = 0.469 and MCC = 0.281) and Claude Sonnet 4 (F1 = 0.518 and MCC = 0.359). Perhaps more importantly, our analysis indicates that SpecValidator can generalize to unseen issues and detect unknown Under-Specification defects in the original (real) descriptions of the benchmarks used. Our results also show that the robustness of LLMs in task description defects depends primarily on the type of defect and the characteristics of the task description, rather than the capacity of the model, with Under-Specification defects being the most severe. We further found that benchmarks with richer contextual grounding, such as LiveCodeBench, exhibit substantially greater resilience, highlighting the importance of structured task descriptions for reliable LLM-based code generation.