arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2512.07666cs.CLcs.SE
收藏

连接代码图与大型语言模型以实现更好的代码理解

Bridging Code Graphs and Large Language Models for Better Code Understanding

Beijing University of Posts and Telecommunications(北京邮电大学);Huazhong University of Science and Technology(华中科技大学)

Zeqi Chen, Zhaoyang Chu, Yi Gui, Feng Guo, Yao Wan, Chuan Shi

AI总结:

CGBridge通过引入外部Bridge模块,提升LLMs对代码结构语义的理解,显著提高代码生成和翻译任务的性能。

摘要:

大型语言模型(LLMs)在代码智能任务如代码生成、总结和翻译中表现出色。然而,它们对线性化令牌序列的依赖限制了它们理解程序结构语义的能力。尽管先前研究探索了图增强提示和结构感知预训练,但这些方法要么受到提示长度限制,要么需要特定任务的架构更改,这与大规模指令遵循LLMs不兼容。为了解决这些限制,本文提出了CGBridge,一种新颖的即插即用方法,通过外部可训练的Bridge模块增强LLMs,以代码图信息。CGBridge首先通过在包含27万代码图的大型数据集上进行自监督学习,预训练代码图编码器以学习结构代码语义。然后训练一个外部模块,通过跨模态注意力机制对代码、图和文本进行语义对齐,以弥合模态差距。最后,Bridge模块生成结构感知的提示,将其注入冻结的LLM中,并针对下游代码智能任务进行微调。实验表明,CGBridge在原始模型和图增强提示方法上均取得了显著改进。具体而言,在代码总结的LLM-as-a-Judge任务中,其相对提升分别为16.19%和9.12%,在代码翻译的执行准确性任务中,其相对提升分别为9.84%和38.87%。此外,CGBridge的推理速度比LoRA微调模型快超过4倍,展示了在结构感知代码理解中的有效性和效率。

英文摘要:

Large Language Models (LLMs) have demonstrated remarkable performance in code intelligence tasks such as code generation, summarization, and translation. However, their reliance on linearized token sequences limits their ability to understand the structural semantics of programs. While prior studies have explored graphaugmented prompting and structure-aware pretraining, they either suffer from prompt length constraints or require task-specific architectural changes that are incompatible with large-scale instructionfollowing LLMs. To address these limitations, this paper proposes CGBridge, a novel plug-and-play method that enhances LLMs with Code Graph information through an external, trainable Bridge module. CGBridge first pre-trains a code graph encoder via selfsupervised learning on a large-scale dataset of 270K code graphs to learn structural code semantics. It then trains an external module to bridge the modality gap among code, graph, and text by aligning their semantics through cross-modal attention mechanisms. Finally, the bridge module generates structure-informed prompts, which are injected into a frozen LLM, and is fine-tuned for downstream code intelligence tasks. Experiments show that CGBridge achieves notable improvements over both the original model and the graphaugmented prompting method. Specifically, it yields a 16.19% and 9.12% relative gain in LLM-as-a-Judge on code summarization, and a 9.84% and 38.87% relative gain in Execution Accuracy on code translation. Moreover, CGBridge achieves over 4x faster inference than LoRA-tuned models, demonstrating both effectiveness and efficiency in structure-aware code understanding.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑