Skip to main content
QUICK REVIEW

[Paper Review] Probing Pretrained Models of Source Code

Sergey Troshin, Nadezhda Chirkova|arXiv (Cornell University)|Feb 16, 2022
Software Engineering ResearchComputer Science8 citations
TL;DR

This paper introduces a comprehensive probing framework to diagnose how well pretrained code models understand syntactic and semantic properties of source code. Using linear probes on hidden representations, it finds that models capture syntax, naming, and namespace structure but struggle with semantic equivalence, especially after fine-tuning, and that code-specific pretraining objectives improve understanding of targeted code aspects.

ABSTRACT

Deep learning models are widely used for solving challenging code processing tasks, such as code generation or code summarization. Traditionally, a specific model architecture was carefully built to solve a particular code processing task. However, recently general pretrained models such as CodeBERT or CodeT5 have been shown to outperform task-specific models in many applications. While pretrained models are known to learn complex patterns from data, they may fail to understand some properties of source code. To test diverse aspects of code understanding, we introduce a set of diagnosting probing tasks. We show that pretrained models of code indeed contain information about code syntactic structure and correctness, the notions of identifiers, data flow and namespaces, and natural language naming. We also investigate how probing results are affected by using code-specific pretraining objectives, varying the model size, or finetuning.

Motivation & Objective

  • To develop a diagnostic toolkit to assess the extent to which pretrained code models understand diverse code properties.
  • To evaluate how model architecture, pretraining objectives, and fine-tuning affect code understanding capabilities.
  • To identify which code properties—syntactic, semantic, or structural—are preserved in model representations.
  • To guide practitioners in selecting or adapting models based on task-specific requirements.

Proposed method

  • Design a suite of 10 probing tasks targeting syntactic structure, data flow, namespaces, naming, semantic equivalence, and readability.
  • Use linear classifiers and regressors on layer-wise hidden representations without fine-tuning the base model.
  • For token-level tasks, predict AST path types using subtoken embeddings; for snippet-level tasks, predict AST depth or semantic similarity.
  • Train probes on synthetic or borrowed data with strong baselines (e.g., constant prediction or linear regression).
  • Evaluate performance using accuracy for classification and mean absolute error for regression.
  • Compare models across sizes, pretraining objectives (e.g., masked language modeling, code-specific objectives), and fine-tuning effects.

Experimental results

Research questions

  • RQ1To what extent do pretrained code models encode syntactic structure, such as AST paths and depth?
  • RQ2Can models distinguish between semantically equivalent code snippets, indicating semantic understanding?
  • RQ3How do code-specific pretraining objectives (e.g., CodeT5, GraphCodeBERT) affect the model’s ability to capture specific code properties?
  • RQ4Does fine-tuning degrade or improve the model’s representation of code structure and semantics?
  • RQ5How does model size influence the retention of code-related information in hidden representations?

Key findings

  • Pretrained code models effectively capture syntactic structure, including AST path types and depth, with high accuracy on probing tasks.
  • Models show strong performance on naming and namespace-related tasks, indicating awareness of identifier scope and context.
  • Semantic equivalence detection remains a challenge, with models achieving only modest performance, suggesting limited semantic understanding.
  • Fine-tuning often degrades performance on probing tasks, particularly in classification, indicating potential loss of structural knowledge.
  • Models pre-trained with code-specific objectives (e.g., CodeT5, GraphCodeBERT) show improved performance on tasks aligned with those objectives.
  • The results hold when using a 3-layer MLP instead of linear probes, confirming robustness of the findings.

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.