Time-Efficient Code Completion Model for the R Programming Language (2021)

Abstract: In this paper we present a deep learning code completion model for the R language. We introduce several techniques to utilize language modeling based architecture in the code completion task. With these techniques, the model requires low resources, but still achieves high quality. We also present an evaluation dataset for the R language completion task. Our dataset contains multiple autocompletion usage contexts that provides robust validation results. The dataset is publicly available.

## introduction code completion feature (for simplicity we will refer to it as autocompletion) is used in an integrated development environment (ide) to suggest the next pieces of code during typing. code completion engines can accelerate software development and help to reduce errors by eliminating typos. in recent years quality improvements in the code completion task have been achieved with the transformer language models. models with a huge amount of parameters usually demonstrate better performance @xcite , but in practice code completion is executed on a user laptop with limited computational resources. at the same time code completion should run as fast as possible to be considered as a convenient development tool. in this paper, we show that the autocompletion task can be solved with a fairly good quality even with a small transformer-based model. we propose several techniques to adapt the model which was originally designed for nlp tasks to our task. it is hard to build a good autocompletion system for dynamically typed languages without machine learning methods @xcite . let us consider an autocompletion of a function argument scenario. in static languages, an argument type is determined in the function definition. we can collect variables of this type from the scope in which the function is called. these variables may be used as an autocompletion output. however, in dynamic languages the argument type information is omitted. since all dynamic languages are interpreted, variable types can not be obtained without running a program or special tools usage. we choose a dynamic r programming language for our experiments. to the best of our knowledge, there are no papers about code completion based on deep learning for the r programming language specifically. we also propose an evaluation dataset for the r programming language collected from the opensource github projects foot_0 . our dataset is divided into several groups specific for different code usage contexts. for example, there is a separate group containing package imports and another one containing function calls. ## related work there are many ways to design code completion models. one of the methods is a frequency-based system. the statistical language model is used to rank a set of possible completions extracted by the rule-based methods @xcite . @xcite proposed proposed a ranking machine learning model, which additionally takes a feature vector describing completion context as an input. lately, deep learning approaches have gained popularity. completions are generated by autoregressive models such as lstm or transformerbased language models @xcite trained on a large source unlabeled code corpora. some large models such as gpt3 @xcite can even perform a full-line autocompletion with promising quality. @xcite suggest to predict the next node of the abstract syntax tree (ast) of the program to get completions. @xcite propose to predict the token and its type jointly to improve completion performance for identifiers. ## experiments the code completion task may be considered a ranking problem. we use mean reciprocal rank score (mrr) and mean recall@5 score for evaluation in our experiments. there is only one relevant element a in the autocompletion task and with search results denoted as s the formulas can be written as follows. ## conclusions in this work, we present a model for the r programming language completion. we introduced simple but effective techniques, which can improve a code completion quality, while not affecting the model architecture or the training objective. thus, these techniques can be easily combined with other works in the field and any dynamic programming language. we also present an evaluation dataset for the r programming language containing different autocompletion contexts. the diversity of our dataset provides a robust estimation.