构建代码功能一致性评估新基准,提升大模型对代码语义的理解能力
Functional Consistency of LLM Code Embeddings: A Self-Evolving Data Synthesis Framework for Benchmarking
- 提出自进化数据生成框架,从单个代码生成四种功能差异变体
- 在代码克隆检测等三项任务中,新数据集使嵌入模型性能显著提升
- 聚焦功能一致性而非语法相似性,适合代码理解与AI编程研究者
嵌入模型在聚类、检索和特征提取等任务中表现优异,且计算成本低于生成式模型和交叉编码器。虽然MTEB等基准表明大语言模型(LLMs)的文本嵌入能捕捉丰富语义,但其对代码级功能语义的表达能力尚不明确。现有研究多集中于代码克隆检测,强调语法相似性而忽视功能理解。本文关注LLM代码嵌入的功能一致性,即判断两个代码片段是否实现相同功能,即使语法不同。我们提出一种名为面向功能的代码自演化(Functionality-Oriented Code Self-Evolution)的新数据合成框架,定义四类语义与语法维度的代码样本,发现现有数据集主要反映语法特性。该框架从单一代码实例生成四种独特变体,覆盖更广的功能差异谱。在代码克隆检测、功能一致性识别和代码检索三项下游任务上的实验表明,使用我们演化数据训练的嵌入模型性能显著提升。结果验证了该框架的有效性与泛化能力,推动了对代码功能理解的进展。
原文摘要 · Abstract (English)
Embedding models have demonstrated strong performance in tasks like clustering, retrieval, and feature extraction while offering computational advantages over generative models and cross-encoders. Benchmarks such as MTEB have shown that text embeddings from large language models (LLMs) capture rich semantic information, but their ability to reflect code-level functional semantics remains unclear. Existing studies largely focus on code clone detection, which emphasizes syntactic similarity and overlooks functional understanding. In this paper, we focus on the functional consistency of LLM code embeddings, which determines if two code snippets perform the same function regardless of syntactic differences. We propose a novel data synthesis framework called Functionality-Oriented Code Self-Evolution to construct diverse and challenging benchmarks. Specifically, we define code examples across four semantic and syntactic categories and find that existing datasets predominantly capture syntactic properties. Our framework generates four unique variations from a single code instance, providing a broader spectrum of code examples that better reflect functional differences. Extensive experiments on three downstream tasks-code clone detection, code functional consistency identification, and code retrieval-demonstrate that embedding models significantly improve their performance when trained on our evolved datasets. These results highlight the effectiveness and generalization of our data synthesis framework, advancing the functional understanding of code.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。