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

基于稀疏注意力的神经网络用于代码分类

Sparse Attention-Based Neural Networks for Code Classification

Ziyang Xiang, Zaixi Zhang, Qi Liu

AI总结:

针对代码分类问题,提出基于稀疏注意力的SACC模型,结合递归神经网络编码子树序列和稀疏注意力Transformer,降低计算成本并提升性能,在标注的CodeNet数据集上验证了有效性。

摘要:

在真实的编程教育平台管理中,准确且高效地对源代码进行分类是一个具有挑战性的问题。近年来,利用抽象语法树(ASTs)的基于模型的方法已被广泛应用于代码分类任务。本文提出了一种名为基于稀疏注意力的代码分类神经网络(SACC)的方法。该方法包括两个主要步骤:第一步,源代码经过语法解析和预处理。生成的抽象语法树被分割成子树序列,然后使用递归神经网络进行编码,以获得高维表示。此步骤同时考虑了代码中包含的逻辑结构和词法层面的信息。第二步,将编码后的子树序列输入到融合了稀疏注意力机制的Transformer模型中进行分类。该方法有效降低了自注意力机制的计算成本,从而在保持效果的同时提高了训练速度。我们的工作引入了一种精心设计的稀疏注意力模式,该模式专门针对代码分类任务的独特需求而设计。这种设计有助于减少冗余信息的影响,并提升模型的整体性能。最后,我们还解决了以往相关研究中的问题,包括分类标签不完整和数据集规模较小等问题。我们为CodeNet数据集标注了与算法相关的分类标签,该数据集包含大量数据。广泛的对比实验结果表明,SACC在代码分类任务中具有有效性和高效性。

英文摘要:

Categorizing source codes accurately and efficiently is a challenging problem in real-world programming education platform management. In recent years, model-based approaches utilizing abstract syntax trees (ASTs) have been widely applied to code classification tasks. We introduce an approach named the Sparse Attention-based neural network for Code Classification (SACC) in this paper. The approach involves two main steps: In the first step, source code undergoes syntax parsing and preprocessing. The generated abstract syntax tree is split into sequences of subtrees and then encoded using a recursive neural network to obtain a high-dimensional representation. This step simultaneously considers both the logical structure and lexical level information contained within the code. In the second step, the encoded sequences of subtrees are fed into a Transformer model that incorporates sparse attention mechanisms for the purpose of classification. This method efficiently reduces the computational cost of the self-attention mechanisms, thus improving the training speed while preserving effectiveness. Our work introduces a carefully designed sparse attention pattern that is specifically designed to meet the unique needs of code classification tasks. This design helps reduce the influence of redundant information and enhances the overall performance of the model. Finally, we also deal with problems in previous related research, which include issues like incomplete classification labels and a small dataset size. We annotated the CodeNet dataset with algorithm-related labeling categories, which contains a significantly large amount of data. Extensive comparative experimental results demonstrate the effectiveness and efficiency of SACC for the code classification tasks.

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

↑