Code based Language Models (LMs) have shown very promising results in the field of software engineering with applications such as code refinement, code completion and generation. However, the task of time and space complexity classification from code has not been extensively explored due to a lack of datasets, with prior endeavors being limited to Java. In this project, we aim to address these gaps by creating a labelled dataset of code snippets spanning multiple languages (Python and C++ datasets currently, with C, C#, and JavaScript datasets being released shortly). We find that existing time complexity calculation libraries and tools only apply to a limited number of use-cases. The lack of a well-defined rule based system motivates the application of several recently proposed code-based LMs. We demonstrate the effectiveness of dead code elimination and increasing the maximum sequence length of LMs. In addition to time complexity, we propose to use LMs to find space complexities from code, and to the best of our knowledge, this is the first attempt to do so. Furthermore, we introduce a novel code comprehension task, called cross-language transfer, where we fine-tune the LM on one language and run inference on another. Finally, we visualize the activation of the attention fed classification head of our LMs using Non-negative Matrix Factorization (NMF) to interpret our results.
翻译:基于代码的语言模型已在软件工程领域展现出十分 promising 的结果,应用于代码精炼、代码补全和生成等场景。然而,由于缺乏数据集,从代码中进行时间与空间复杂度分类的任务尚未得到广泛探索,且先前的尝试仅限于Java语言。在本项目中,我们旨在通过创建一个涵盖多种语言(目前包括Python和C++数据集,C、C#和JavaScript数据集即将发布)的代码片段标注数据集来填补这些空白。我们发现,现有的时间复杂度计算库和工具仅适用于有限的使用场景。缺乏明确定义的基于规则的系统促使我们应用了近期提出的多种基于代码的语言模型。我们证明了死代码消除以及增加语言模型最大序列长度的有效性。除了时间复杂度,我们提出使用语言模型从代码中找出空间复杂度,据我们所知,这是首次尝试。此外,我们引入了一项新颖的代码理解任务——跨语言迁移,即在一个语言上微调语言模型,并在另一个语言上进行推理。最后,我们利用非负矩阵分解(NMF)可视化语言模型中注意力驱动的分类头的激活情况,以解释我们的结果。