Code Representation Pre-training with Complements from Program Executions

Jiabo Huang, Jianyu Zhao, Yuyang Rong, Yiwen Guo, Yifeng He, Hao Chen

Introduction

Traditional code representation models like CodeBERT or UniXcoder primarily treat programming languages as sequences of text. While some incorporate static features such as Abstract Syntax Trees (ASTs), they often fail to capture dynamic semantics—the actual behavior of code during execution. Two snippets may appear syntactically similar but behave differently, or vice versa. To address this, researchers proposed FuzzPretrain, a framework that integrates dynamic execution information into the pre-training phase, allowing models to understand what code does rather than just how it looks.

Methodology: FuzzPretrain

FuzzPretrain bridges the gap between static text and dynamic behavior through four key components:

  1. Automated Fuzzing: The researchers used a fuzzer to generate high-quality input-output (I/O) pairs for 1.2 million code snippets from the CodeNet dataset. These pairs serve as the ground truth for program behavior.
  2. Static Info Modeling (SIM): Standard Masked Language Modeling (MLM) is retained to maintain the model's grasp of basic syntax and keywords.
  3. Dynamic Information Matching (DIM): The model is trained to predict whether a given test case (I/O pair) matches a specific code snippet, forcing it to correlate syntax with logic.
  4. Dynamic Information Distillation (DID): To ensure the model remains useful in real-world scenarios where test cases are unavailable, DID uses self-distillation. The model learns to align its "code-only" representation with its "code + test case" representation, effectively learning to "imagine" execution behavior from source code alone.
Figure 1: Overview of the FuzzPretrain architecture, illustrating the integration of static modeling, dynamic matching, and information distillation.

Experimental Setup

The framework was pre-trained on the CodeNet dataset (C++, Python, Java) and evaluated on several CodeXGLUE benchmarks:

  • Code Search: Retrieving equivalent functions.
  • Clone Detection (POJ-104): Identifying different implementations of the same logic.
  • Defect Detection (Devign): Identifying bugs in code.
  • Natural Language Search (CosQA): Text-to-code retrieval.

Results and Key Insights

FuzzPretrain demonstrated substantial improvements over static-only baselines. In code search tasks, it achieved a 6% improvement in Mean Average Precision (mAP) over standard CodeBERT. For clone detection, FuzzCodeBERT reached an mAP of 93.0%, significantly outperforming specialized models like GraphCodeBERT (85.2%).

Figure 5: Performance comparison of FuzzPretrain variants against state-of-the-art models across Clone Detection, Defect Detection, and Text-to-Code Search tasks.

A critical insight from this work is the effectiveness of Dynamic Information Distillation. By decoupling the requirement for test cases at inference time, the model gains the benefits of execution-aware representations without the computational overhead of runtime fuzzing. Furthermore, qualitative analysis via t-SNE visualizations indicated that FuzzPretrain creates tighter clusters for functionally equivalent code, effectively ignoring "syntactic noise" like variable renaming or loop restructuring.

Conclusion and Future Work

FuzzPretrain proves that program execution is a powerful signal for learning code semantics. While highly effective for short, self-contained functions, future research is needed to adapt this approach to complex enterprise codebases with external dependencies. Additionally, extending the framework to include natural language documentation (tri-modal pre-training) could further enhance its utility in software engineering tasks.

Summary updated

BibTeX
@inproceedings{huang2024code,
  author = {Jiabo Huang and Jianyu Zhao and Yuyang Rong and Yiwen Guo and Yifeng He and Hao Chen},
  title = {{Code Representation Pre-training with Complements from Program Executions}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-industry.21},
}
Figure