小型Transformer中用于对比代码表示学习的合成语义监督:一项实证研究
文章背景与核心概要
通用代码嵌入对于代码搜索、分类和检索等高级工具至关重要。然而,面向代码的轻量级Transformer编码器传统上一直面临一个瓶颈:它们要么依赖人工编写的文档字符串(耗时且经常不一致),要么依赖挖掘出的结构信号(如执行轨迹),这些信号具有高度的场景特定性且收集成本高昂。
本文对一种可扩展的替代方案进行了实证研究:使用合成生成的自然语言描述对小型编码器进行对比预训练。这些描述强调了代码的功能和意图,在训练期间通过双编码器框架与代码配对(并在推理时丢弃)。实验结果表明,该方法在多个基准测试中取得了显著成效,为高效、轻量级的代码表征学习提供了一种可扩展且高效的新范式。
元数据
- arXiv ID: arXiv:2609.03702 [cs.AI]
- 作者: Kenneth Paulsen, Florian Tambon, Mike Papadakis, Shin Yoo
- 提交时间: 2026年9月3日
- 状态: 已被 Findings of EMNLP 2026 接收
- 主要学科: 人工智能 (
cs.AI)
Metadata
- arXiv ID: arXiv:2609.03702 [cs.AI]
- Authors: Kenneth Paulsen, Florian Tambon, Mike Papadakis, Shin Yoo
- Submitted: September 3, 2026
- Status: Accepted in Findings of EMNLP 2026
- Primary Subject: Artificial Intelligence (
cs.AI)
执行摘要
通用代码嵌入对于代码搜索、分类和检索等高级工具至关重要。然而,面向代码的紧凑型Transformer编码器传统上面临着一个瓶颈:它们要么依赖人工编写的文档字符串——这既费时又经常不一致;要么依赖挖掘出的结构信号(如执行轨迹),这些信号具有场景特定性且收集成本高昂。
本文对一种可扩展的替代方案进行了实证研究:使用合成生成的自然语言描述对小型编码器进行对比预训练。这些描述强调了代码的功能和意图,在训练期间通过双编码器框架与代码配对(并在推理时丢弃)。
Executive Summary
General-purpose code embeddings are essential for power tools used in code search, classification, and retrieval. However, compact transformer encoders for code traditionally face a bottleneck: they rely either on human-written docstrings—which are labor-intensive and frequently inconsistent—or mined structural signals like execution traces, which are setting-specific and costly to collect.
This paper empirically investigates a scalable alternative: contrastive pretraining of small encoders using synthetically generated natural-language descriptions. These descriptions emphasize code functionality and intent, and are paired with code in a dual-encoder framework during training (and discarded at inference).
核心发现与结果
- 强劲性能: 评估涵盖了跨越 C、C++ 和 Java 的八项检索、分类和生成任务。
- 统计学改进: 在八项任务中的五项上,合成语义监督带来了具备统计学显着性的提升,超越了具有相同推理时规模的预训练基线,并在其余两项任务上达到了相当的水平。
- 越级挑战: 微调后,该方法在分类任务上的表现匹配甚至超过了规模大出两个数量级的零样本模型。
- 竞争优势: 当使用匹配的预训练数据时,它保持了与感知执行(execution-aware)监督相当的性能,这证实了合成语义监督是用于代码表示学习的一种可扩展且高效的范式。
Key Findings & Results
- Strong Performance: Evaluated across eight retrieval, classification, and generation tasks spanning C, C++, and Java.
- Statistical Improvements: Synthetic semantic supervision yields statistically significant gains over pretraining baselines of the exact same inference-time size on five out of eight tasks, achieving parity on the remaining two.
- Punching Above Its Weight Class: Once fine-tuned, the approach matches or even exceeds zero-shot models that are two orders of magnitude larger on classification tasks.
- Competitive Edge: It maintains performance on par with execution-aware supervision when utilizing matched pretraining data, confirming that synthetic semantic supervision is a scalable and highly effective paradigm for code representation learning.
链接与资源
- 访问论文:
- 查看 PDF
- HTML 版本(实验性)
- TeX 源码
- 外部引用与工具:
- 谷歌学术
- Semantic Scholar
- NASA ADS
Links & Resources
- Access Paper:
- View PDF
- HTML Version (Experimental)
- TeX Source
- External Citations & Tools:
- Google Scholar
- Semantic Scholar
- NASA ADS