Summarizing source code into natural language descriptions (code summarization) helps developers better understand program functionality and reduce the burden of software maintenance. Abstract Syntax Trees (ASTs), as opposed to source code, have been shown to improve summarization quality in traditional encoder-decoder-based code summarization models. However, most large language model (LLM)-based code summarization methods rely on raw code or only incorporate partial AST signals, meaning that the potential of complete AST representation has not been fully explored for LLMs. This paper presents AST(NIT), an AST augmentation and serialization method that preserves lexical details and encodes structural information into LLM-compatible sequences. Experiments with the LLaMA-3.1-8B model on the CodeXGLUE Python dataset show that the proposed serialized ASTs reduce the length of LLM inputs, require shorter training times, and achieve summarization quality comparable to existing approaches.
翻译:将源代码概括为自然语言描述(代码摘要)有助于开发者更好地理解程序功能并减轻软件维护负担。与传统基于编码器-解码器的代码摘要模型相比,抽象语法树(AST)已被证明能提升摘要质量。然而,当前大多数基于大语言模型(LLM)的代码摘要方法仍依赖原始代码或仅融入部分AST特征,这意味着完整的AST表征在LLM中的潜力尚未得到充分探索。本文提出AST(NIT)——一种保留词法细节并将结构信息编码为LLM兼容序列的AST增强与序列化方法。基于LLaMA-3.1-8B模型在CodeXGLUE Python数据集上的实验表明,所提出的序列化AST能缩短LLM输入长度,减少训练时间,同时获得与现有方法相当的摘要质量。