文章背景与核心概要
随着AI代码助手得到广泛应用,确保生成代码的正确性依然是一项重大挑战。代码大语言模型(LLM)极易产生幻觉,从而导致错误的解决方案甚至严重的安全性漏洞。
本文引入了 CodeTD,这是首个利用拓扑数据分析(TDA)对代码LLM的注意力图进行分析,从而在执行前评估代码正确性的方法。通过利用注意力的拓扑模式量化提示词与生成内容之间的不匹配,CodeTD能够在代码执行前有效检测潜在错误。经过对5种编程语言、10个代码大模型(参数量高达34B)以及标准基准(HumanEval、MBPP、BigCodeBench和MultiPL-E)的测试,CodeTD的性能超越了最近的基线方法,并展现出强大的跨基准泛化能力。
CodeTD:注意力拓扑检测代码大语言模型中的幻觉
摘要 (Summary)
As AI-powered code assistants become widely adopted, ensuring the correctness of generated code remains a major challenge. Code Large Language Models (LLMs) are prone to hallucinations, which can result in incorrect solutions or severe security vulnerabilities.
This paper introduces CodeTD, the first pre-execution approach for assessing code correctness using Topological Data Analysis (TDA) on Code LLM attention maps. By quantifying prompt-generation mismatches through the topological patterns of attention, CodeTD effectively detects potential errors before execution. Tested across 5 programming languages, 10 Code LLMs (up to 34B parameters), and standard benchmarks (HumanEval, MBPP, BigCodeBench, and MultiPL-E), CodeTD outperforms recent baselines while demonstrating strong cross-benchmark transferability.
随着人工智能驱动的代码助手得到广泛应用,确保生成代码的正确性仍然是一个重大挑战。代码大语言模型(LLM)极易产生幻觉,这可能导致错误的解决方案,甚至带来严重的安全性漏洞。
本文引入了 CodeTD,这是首个基于拓扑数据分析(TDA)对代码LLM的注意力图进行分析,并在执行前评估代码正确性的方法。通过利用注意力图的拓扑模式来量化提示词与生成内容之间的不匹配,CodeTD在执行前有效地检测出了潜在错误。在5种编程语言、10个代码LLM(参数量达34B)以及标准基准(HumanEval、MBPP、BigCodeBench和MultiPL-E)上进行的测试表明,CodeTD超越了近期的基线方法,同时展现出强大的跨基准可迁移性。
论文元数据 (Paper Metadata)
- arXiv ID: arXiv:2609.07779 [cs.SE]
- Primary Subject: Software Engineering (
cs.SE)- Other Subjects: Artificial Intelligence (
cs.AI), Computation and Language (cs.CL), Machine Learning (cs.LG)- Submission Date: September 7, 2026
- Authors: Daria Voronkova, Ilya Trofimov, Anton Dmitriev, Eduard Tulchinskii, Evgeny Burnaev, Serguei Barannikov
- License: Creative Commons Attribution 4.0 International
- arXiv ID: arXiv:2609.07779 [cs.SE]
- 主要学科: 软件工程 (
cs.SE) - 其他学科: 人工智能 (
cs.AI)、计算与语言 (cs.CL)、机器学习 (cs.LG) - 提交日期: 2026年9月7日
- 作者: Daria Voronkova, Ilya Trofimov, Anton Dmitriev, Eduard Tulchinskii, Evgeny Burnaev, Serguei Barannikov
- 许可协议: 知识共享署名 4.0 国际版

摘要原文 (Abstract)
As AI-code assistant tools become widespread, automatic assessment of the correctness of generated code becomes a significant challenge. Code LLMs are prone to hallucinations, which may lead to code that does not solve the required problem, or even to code with severe security vulnerabilities. In this paper, we introduce CodeTD -- the first approach to pre-execution assessment of code correctness based on topological data analysis (TDA) of Code LLMs' attention maps. Our method quantifies prompt-generation mismatch using topological patterns of attention maps. We carry out experiments with common benchmarks (HumanEval, MBPP, BigCodeBench, MultiPL-E), 5 programming languages and 10 Code LLMs of size up to 34B parameters. The experimental results show that the proposed method outperforms recent baselines. Moreover, CodeTD is transferable between coding benchmarks.
随着AI代码辅助工具的普及,自动评估生成代码的正确性成为一项重大挑战。代码大语言模型容易产生幻觉,这可能导致代码无法解决所需的问题,甚至产生具有严重安全漏洞的代码。在本文中,我们推出了 CodeTD —— 这是首个基于代码大语言模型注意力图的拓扑数据分析(TDA)来进行代码正确性预执行评估的方法。我们的方法通过注意力图的拓扑模式来量化提示词与生成内容之间的不匹配。我们在常用基准(HumanEval、MBPP、BigCodeBench、MultiPL-E)、5种编程语言以及10个参数量高达34B的代码大语言模型上进行了实验。实验结果表明,该方法优于近期的基线模型。此外,CodeTD在不同的编码基准之间具有良好的可迁移性。
访问与资源 (Access & Resources)
- Full-Text Links:
- View PDF
- HTML Version (Experimental)
- TeX Source
- DOI: 10.48550/arXiv.2609.07779
- External References & Tools:
- Google Scholar
- Semantic Scholar
- NASA ADS
- 全文链接:
- 查看 PDF
- HTML 版本(实验性)
- TeX 源码
- DOI: 10.48550/arXiv.2609.07779
- 外部参考与工具:
- 谷歌学术
- Semantic Scholar
- NASA ADS