Computer Science > Software Engineering
[Submitted on 30 Mar 2020 (v1), revised 21 May 2020 (this version, v2), latest version 8 Mar 2021 (v4)]
Title:Code Prediction by Feeding Trees to Transformers
View PDFAbstract:We advance the state-of-the-art in the accuracy of code prediction (next token prediction) used in autocomplete systems.
First, we report that using the recently proposed Transformer architecture even out-of-the-box outperforms previous neural and non-neural systems for code prediction. We then show that by making the Transformer architecture aware of the syntactic structure of code, we further increase the margin by which a Transformer-based system outperforms previous state-of-the-art systems. With this, it outperforms the accuracy of an RNN-based system by 37.0\%, the decision-tree based Deep3 system by 29.7\%, and an adaptation of Code2Seq for code prediction by 30.0\%. These are significant margins.
We present in the paper several ways of communicating the code structure to the Transformer, which is fundamentally built for processing sequence data. The most effective of these is when we enrich the self-attention mechanism of the Transformer. We enable the mechanism to learn weights---that is, how much to focus on each preceding token in the input---not only on the basis of a token's value, but also on the basis of the spatial relationships, as in their positions in the abstract syntax tree, between each pair of tokens.
We provide a comprehensive experimental evaluation of our proposal, along with alternative design choices, on a standard Python dataset, as well as on a company internal Python corpus. Our code and data preparation pipeline are available in open source.
Submission history
From: Satish Chandra [view email][v1] Mon, 30 Mar 2020 22:38:28 UTC (1,130 KB)
[v2] Thu, 21 May 2020 17:25:21 UTC (3,212 KB)
[v3] Thu, 2 Jul 2020 23:45:37 UTC (3,773 KB)
[v4] Mon, 8 Mar 2021 22:02:09 UTC (3,939 KB)
References & Citations
Bibliographic and Citation Tools
Bibliographic Explorer (What is the Explorer?)
Litmaps (What is Litmaps?)
scite Smart Citations (What are Smart Citations?)
Code, Data and Media Associated with this Article
CatalyzeX Code Finder for Papers (What is CatalyzeX?)
DagsHub (What is DagsHub?)
Gotit.pub (What is GotitPub?)
Papers with Code (What is Papers with Code?)
ScienceCast (What is ScienceCast?)
Demos
Recommenders and Search Tools
Influence Flower (What are Influence Flowers?)
Connected Papers (What is Connected Papers?)
CORE Recommender (What is CORE?)
arXivLabs: experimental projects with community collaborators
arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.
Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.
Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs.