Skip to main content
QUICK REVIEW

[Paper Review] TreeBERT: A Tree-Based Pre-Trained Model for Programming Language

Xue Jiang, Zhuoran Zheng|arXiv (Cornell University)|Jul 27, 2021
Software Engineering ResearchComputer Science1 citations
TL;DR

TreeBERT is a tree-based pre-trained model that leverages abstract syntax trees (ASTs) in code by representing them as composition paths and using node position embeddings. It improves programming language generation through tree masked language modeling (TMLM) and node order prediction (NOP), outperforming existing models on code summarization and documentation tasks, including zero-shot transfer to unseen programming languages.

ABSTRACT

Source code can be parsed into the abstract syntax tree (AST) based on defined syntax rules. However, in pre-training, little work has considered the incorporation of tree structure into the learning process. In this paper, we present TreeBERT, a tree-based pre-trained model for improving programming language-oriented generation tasks. To utilize tree structure, TreeBERT represents the AST corresponding to the code as a set of composition paths and introduces node position embedding. The model is trained by tree masked language modeling (TMLM) and node order prediction (NOP) with a hybrid objective. TMLM uses a novel masking strategy designed according to the tree's characteristics to help the model understand the AST and infer the missing semantics of the AST. With NOP, TreeBERT further extracts the syntactical structure by learning the order constraints of nodes in AST. We pre-trained TreeBERT on datasets covering multiple programming languages. On code summarization and code documentation tasks, TreeBERT outperforms other pre-trained models and state-of-the-art models designed for these tasks. Furthermore, TreeBERT performs well when transferred to the pre-trained unseen programming language.

Motivation & Objective

  • To improve programming language generation by incorporating tree-structured ASTs into pre-training.
  • To address the lack of tree structure utilization in existing pre-trained models for code.
  • To develop a hybrid pre-training objective that captures both semantic and syntactic structure in code ASTs.
  • To enable effective zero-shot transfer to unseen programming languages through robust structural representation.
  • To enhance code summarization and documentation generation via tree-aware representation learning.

Proposed method

  • Representing code ASTs as composition paths to preserve hierarchical structure and enable tree-aware modeling.
  • Introducing node position embeddings to encode the relative position of nodes within the AST structure.
  • Designing a tree masked language modeling (TMLM) objective with a tree-specific masking strategy to predict missing AST nodes.
  • Proposing node order prediction (NOP) to learn syntactic constraints by predicting the correct order of nodes in the AST.
  • Combining TMLM and NOP into a hybrid pre-training objective to jointly optimize semantic and structural understanding.
  • Pre-training TreeBERT on multi-language code datasets to improve generalization across programming languages.

Experimental results

Research questions

  • RQ1Can a pre-trained model that explicitly models AST structure improve code generation tasks like summarization and documentation?
  • RQ2How effective is tree masked language modeling (TMLM) with tree-specific masking in capturing AST semantics?
  • RQ3To what extent does node order prediction (NOP) enhance the model's understanding of syntactic structure in code?
  • RQ4Can TreeBERT generalize to unseen programming languages through zero-shot transfer?
  • RQ5How does TreeBERT compare to existing pre-trained models and SOTA methods on code generation benchmarks?

Key findings

  • TreeBERT outperforms existing pre-trained models on code summarization and documentation generation tasks across multiple programming languages.
  • The hybrid pre-training objective of TMLM and NOP leads to better performance than using either objective alone.
  • TreeBERT achieves strong zero-shot transfer performance on unseen programming languages, demonstrating robust structural generalization.
  • The tree-specific masking strategy in TMLM significantly improves the model's ability to infer missing semantic content in ASTs.
  • Node order prediction (NOP) effectively captures syntactic constraints, enhancing the model's structural understanding of code.
  • TreeBERT achieves state-of-the-art results on benchmark datasets for code generation, confirming the effectiveness of tree-based pre-training.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.