Contextualized Code Pretraining for Code Generation

As code generation becomes increasingly central to improving software development efficiency, modern code models are largely trained and evaluated on code with natural-language descriptions. In real projects, developers often implement missing functions under limited project-specific artifacts, while the local call-site context is already available in the surrounding code. This usage context provides actionable cues about expected behavior, but existing models are not explicitly optimized to leverage it reliably, leading to implementations that may not integrate smoothly with surrounding usage in repository settings. In this work, we propose contextualized code pretraining, an invocation-aware framework that integrates calling context into both the training and evaluation of code models. Using static analysis, we automatically extract large-scale caller–callee pairs from real repositories to construct pretraining tasks and benchmarks that condition generation on the calling context. We train CallerGen , the first code models pretrained with invocation-aware objectives spanning multiple sizes, and evaluate them on CallerEval , a new benchmark featuring realistic scenarios. Experiments across our two primary benchmarks show that CallerGen outperforms comparable-scale models and remains competitive with larger ones. Our 220M and 0.5B models achieve 16.58% and 22.81% pass@1, surpassing baselines on CallerEval . These results highlight the importance of calling context in realistic code generation.

Authors

Institutions

Publication Details

Journal
ACM Transactions on Software Engineering and Methodology
Published
2026-11-03
DOI
https://doi.org/10.1145/3860400
Citations
1
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
4.54
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Contextualized Code Pretraining for Code Generation

Hanwen Zhang, Zeyu Sun, Qingyuan Liang, Yakun Zhang et al.
1 citations
ACM Transactions on Software Engineering and Methodology
Software Engineering Research
4.54
article

Contextualized Code Pretraining for Code Generation

Hanwen Zhang, Zeyu Sun, Qingyuan Liang, Yakun Zhang, Lu Zhang, Chen Liu
article en
1 citations

Abstract

As code generation becomes increasingly central to improving software development efficiency, modern code models are largely trained and evaluated on code with natural-language descriptions. In real projects, developers often implement missing functions under limited project-specific artifacts, while the local call-site context is already available in the surrounding code. This usage context provides actionable cues about expected behavior, but existing models are not explicitly optimized to leverage it reliably, leading to implementations that may not integrate smoothly with surrounding usage in repository settings. In this work, we propose contextualized code pretraining, an invocation-aware framework that integrates calling context into both the training and evaluation of code models. Using static analysis, we automatically extract large-scale caller–callee pairs from real repositories to construct pretraining tasks and benchmarks that condition generation on the calling context. We train CallerGen , the first code models pretrained with invocation-aware objectives spanning multiple sizes, and evaluate them on CallerEval , a new benchmark featuring realistic scenarios. Experiments across our two primary benchmarks show that CallerGen outperforms comparable-scale models and remains competitive with larger ones. Our 220M and 0.5B models achieve 16.58% and 22.81% pass@1, surpassing baselines on CallerEval . These results highlight the importance of calling context in realistic code generation.

ACM Transactions on Software Engineering and Methodology
Chinese Academy of Sciences (CN), Peking University (CN), Harbin Institute of Technology (CN), Institute of Software (CN), Beihang University (CN)
Openalex Percentile: Top 6%
Software Engineering Research
4.54
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon
Contextualized Code Pretraining for Code Generation — Hanwen Zhang, Zeyu Sun, et al. · ACM Transactions on Software Engineering and Methodology (2026) | TGRS Research Map | TGRS