NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Multi-task Learning based Pre-trained Language Model for Code Completion

Fang Liu, Ge Li, Yunfei Zhao, Zhi Jin

Introduction

Code completion is an essential feature in modern Integrated Development Environments (IDEs), aiding developers by suggesting the next likely tokens. However, traditional models often struggle with the semantic nuances of code and the prediction of specific identifiers. This paper, presented at ASE 2020, introduces CugLM (Code Understanding and Generation pre-trained Language Model), a Transformer-based approach designed to enhance code completion by integrating structural understanding with generative capabilities.

The Challenges of Modern Code Completion

Existing deep learning models for code completion face two primary hurdles:

  1. Context Blindness: Static embeddings often fail to capture the context-dependent meaning of tokens. For instance, the token get might represent a simple list accessor or a complex network request, but static models treat them identically.
  2. The Identifier Gap: While models are proficient at predicting frequent syntax like semicolons or braces, they often fail at predicting identifiers—the variable and method names that carry the most semantic weight for developers. Furthermore, these models typically overlook type information, which is a critical constraint used by human developers to narrow down possibilities.

Methodology: The CugLM Framework

CugLM employs a multi-task learning framework divided into two distinct phases: pre-training for understanding and fine-tuning for completion.

1. Pre-training (The "Understanding" Phase)

The model is pre-trained on a vast corpus using three concurrent objectives to capture both local and global code structures:

  • Masked Bidirectional LM (MLM): Similar to BERT, the model predicts masked identifiers using bidirectional context.
  • Next Code Segment Prediction (NCP): The model determines if two code blocks are logically sequential, fostering long-range coherence.
  • Unidirectional LM (ULM): A standard left-to-right prediction task that aligns the model with the generative requirements of code completion.
CugLM Architecture and Multi-task Pre-training Objectives

2. Fine-tuning (The "Completion" Phase)

During the completion phase, CugLM introduces a novel two-step prediction process. Instead of predicting a token directly, the model first predicts the data type of the expected token. This predicted type then acts as a constraint, significantly narrowing the search space for the final token prediction. This approach mirrors human cognitive processes, where a developer first identifies the necessary type (e.g., a String) before selecting the specific variable.

Two-step prediction process: Type prediction followed by Token prediction

Datasets and Evaluation

The researchers evaluated CugLM using two extensive datasets harvested from GitHub:

  • Java: Comprising 9,708 projects and approximately 54 million lines of code.
  • TypeScript: Comprising 8,446 projects and approximately 8.8 million lines of code. Static analysis and type annotations were used to provide the ground-truth type information necessary for training.

Key Results and Insights

CugLM demonstrated superior performance against state-of-the-art models like Transformer-XL and Pointer Mixture Networks.

  • Overall Accuracy: The model achieved 84.06% accuracy on Java and 82.14% on TypeScript.
  • Identifier Prediction: The most significant gains were observed in identifier completion, with relative improvements of 29% in Java and 34% in TypeScript over Pointer Mixture Networks.
  • Type Prediction Accuracy: The model correctly predicted identifier types 69-79% of the time, validating the effectiveness of the two-step prediction strategy.
  • Efficiency: Despite its complexity, CugLM uses fewer parameters (104M) than some LSTM-based predecessors (up to 177M), demonstrating that sophisticated training objectives can be more effective than sheer model size.

Conclusion

CugLM proves that integrating type information and multi-task pre-training can drastically improve the utility of code completion tools. By focusing on the "hard" problem of identifier prediction through a structured two-step process, CugLM offers a more intelligent assistant for developers. Future work aims to explore dynamic evaluation settings and extend this multi-task approach to other software engineering domains like bug detection.

Summary updated

BibTeX
@inproceedings{liu2020multi,
  author = {Fang Liu and Ge Li and Yunfei Zhao and Zhi Jin},
  title = {{Multi-task Learning based Pre-trained Language Model for Code Completion}},
  booktitle = {ASE},
  year = {2020},
  doi = {10.1145/3324884.3416591},
}
Figure