AI
Adding Context Boosts AI Code Models, But Results Vary by Task and Architecture
A new study shows that enriching code representations with contextual signals like version history and structural relationships can significantly improve deep learning model performance, though the gains depend on the model family and the task.
Researchers have investigated whether feeding machine learning models additional context beyond raw source code can improve their ability to understand and process software. The findings reveal a nuanced picture: context helps substantially for some tasks and models, while occasionally hindering others.
Study Scope and Methodology#
The team ran an empirical evaluation across four programming tasks—code clone detection, code classification, code summarisation, and vulnerability detection—using three datasets. They tested two categories of models: five foundational code models including CodeBERT, GraphCodeBERT, CodeT5, PLBART, and ASTNN, alongside seven specialized large language models such as CodeLlama, Qwen2.5-Coder, and DeepSeek-Coder. The approach compared two strategies for incorporating context: injecting it directly into prompts versus fine-tuning models to use the extra information.
Where Context Helps Most#
Context delivered consistent gains for code classification, with all five foundational models showing improvement and most LLMs benefiting after fine-tuning. When different context types were combined, performance jumped by as much as 21.48% in macro-F1 scores. Similarly, clone detection saw improvements up to 15.04% F1 when blending contextual signals.
For code summarisation, results split sharply along model lines. Version history boosted all four foundational models across every metric, but at the prompt level, the strategy backfired: it helped only two of the seven LLMs while degrading results for the remaining five. Human evaluation of 100 Java code samples showed that summaries enriched with context received significantly higher ratings for accuracy and content quality.
Security and Transfer Potential#
An early investigation into vulnerability detection suggested the approach may transfer benefits to security-focused applications, though the evidence remains preliminary.
This research, available on arXiv, highlights that integrating contextual signals is not a universal fix—practitioners must carefully match their choice of context type and injection method to their model architecture and task requirements.

