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

CV4Code:通过可视化代码表示理解源代码

CV4Code: Sourcecode Understanding via Visual Code Representations

JP Morgan Chase(摩根大通)

Ruibo Shi, Lili Tao, Rohan Saphal, Fran Silavong, Sean J. Moran

摘要:

我们提出了CV4码,一个紧凑的和有效的计算机视觉的源代码理解方法。我们的方法通过将每个片段视为二维图像来利用代码片段中的上下文和结构信息,该二维图像自然地编码上下文并通过显式空间表示保留底层结构信息。为了将片段编码为图像,我们提出了一种基于ASCII码点的图像表示方法,该方法有助于快速生成源代码图像,并消除了RGB像素表示所产生的编码冗余。此外,由于源代码被视为图像,因此既不需要词法分析(标记化)也不需要语法树解析,这使得所提出的方法对于任何特定的程序设计语言是不可知的,并且从应用流水线的角度来看是轻量级的。CV4Code甚至可以对语法错误的代码进行特征化,这在依赖于抽象树(AST)的方法中是不可能的。我们通过学习卷积和Transformer网络来预测功能任务,即它解决的问题,直接从其二维表示的源代码,并使用嵌入从其潜在空间中获得检索设置中的两个代码片段的相似性得分,从而证明了CV4Code的有效性。实验结果表明,我们的方法实现了国家的最先进的性能相比,具有相同的任务和数据配置的其他方法。我们第一次展示了将源代码理解作为图像处理任务的一种形式的好处。

英文摘要:

We present CV4Code, a compact and effective computer vision method for sourcecode understanding. Our method leverages the contextual and the structural information available from the code snippet by treating each snippet as a two-dimensional image, which naturally encodes the context and retains the underlying structural information through an explicit spatial representation. To codify snippets as images, we propose an ASCII codepoint-based image representation that facilitates fast generation of sourcecode images and eliminates redundancy in the encoding that would arise from an RGB pixel representation. Furthermore, as sourcecode is treated as images, neither lexical analysis (tokenisation) nor syntax tree parsing is required, which makes the proposed method agnostic to any particular programming language and lightweight from the application pipeline point of view. CV4Code can even featurise syntactically incorrect code which is not possible from methods that depend on the Abstract Syntax Tree (AST). We demonstrate the effectiveness of CV4Code by learning Convolutional and Transformer networks to predict the functional task, i.e. the problem it solves, of the source code directly from its two-dimensional representation, and using an embedding from its latent space to derive a similarity score of two code snippets in a retrieval setup. Experimental results show that our approach achieves state-of-the-art performance in comparison to other methods with the same task and data configurations. For the first time we show the benefits of treating sourcecode understanding as a form of image processing task.

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

↑