[Paper Review] Exploring Distributional Shifts in Large Language Models for Code Analysis
This paper investigates distributional shifts in code-focused LLMs (CodeT5, Codex, ChatGPT) across organizational, project, and module-level domains. It proposes using retrieved out-of-domain examples for few-shot fine-tuning to improve zero-shot generalization, showing this method outperforms direct fine-tuning in low-data regimes and enables effective multi-domain adaptation with minimal performance loss—especially for code generation.
We systematically study how three large language models with code capabilities - CodeT5, Codex, and ChatGPT - generalize to out-of-domain data. We consider two fundamental applications - code summarization, and code generation. We split data into domains following its natural boundaries - by an organization, by a project, and by a module within the software project. We establish that samples from each new domain present all the models with a significant challenge of distribution shift. We study how established methods adapt models to better generalize to new domains. Our experiments show that while multitask learning alone is a reasonable baseline, combining it with few-shot finetuning on examples retrieved from training data can achieve very strong performance. Moreover, this solution can outperform direct finetuning for very low-data scenarios. Finally, we consider variations of this approach to create a more broadly applicable method to adapt to multiple domains at once. We find that for code generation, a model adapted to multiple domains simultaneously performs on par with those adapted to a single domain
Motivation & Objective
- To evaluate how large language models (CodeT5, Codex, ChatGPT) generalize to out-of-domain code data across organizational, project, and module-level boundaries.
- To investigate the impact of distributional shifts on code summarization and code generation tasks in real-world software systems.
- To develop and evaluate practical adaptation techniques for improving model generalization when labeled in-domain data is scarce or unavailable.
- To assess whether models can be adapted to multiple domains simultaneously without significant performance degradation.
Proposed method
- The study defines out-of-domain scenarios based on natural software boundaries: organization, project, and module/folder-level components.
- Performance is evaluated on the CodeSearchNet dataset using BLEU scores for code summarization and exact match for code generation.
- A retrieval-based adaptation method is proposed: for each test sample, similar labeled examples are retrieved from an out-of-domain corpus to serve as few-shot demonstrations.
- For multi-domain adaptation, models are fine-tuned on combined retrieved examples from multiple domains, with ablation studies using fast vote-k to select diverse examples.
- The approach compares fine-tuning with retrieved examples against direct fine-tuning on in-domain data and meta-learning techniques.
- For in-context learning, demonstrations are either selected per test sample (individual) or from a shared pool per domain (shared), with performance measured across both settings.
Experimental results
Research questions
- RQ1How do CodeT5, Codex, and ChatGPT perform on code summarization and code generation tasks when evaluated on out-of-domain data from new organizations, projects, or modules?
- RQ2Can retrieving similar out-of-domain examples improve model generalization in low-data scenarios where in-domain labeled data is unavailable?
- RQ3Does fine-tuning a single model on combined retrieved examples from multiple domains yield performance comparable to domain-specific fine-tuning?
- RQ4How does the sensitivity of in-context learning to demonstration quality affect performance when using shared vs. per-sample demonstrations?
- RQ5What trade-offs exist between model generalization and performance when adapting to multiple domains simultaneously?
Key findings
- All three models—CodeT5, Codex, and ChatGPT—exhibit significant performance drops on out-of-domain data, with code summarization showing a drop of over 10 BLEU points without adaptation.
- Retrieval-augmented few-shot fine-tuning outperforms direct fine-tuning on in-domain data when only 8–16 labeled examples are available, especially in low-data regimes.
- For code generation, a model fine-tuned on combined retrieved examples from multiple domains performs on par with models adapted to a single domain, indicating minimal negative transfer.
- CodeT5 maintains near-identical performance across domains when adapted jointly, making it feasible to use a single model for multiple domains without performance loss.
- Codex is highly sensitive to demonstration quality; using shared demonstrations across a domain degrades performance significantly, requiring per-sample retrieval for optimal results.
- The fast vote-k algorithm for example selection is less effective than fine-tuning on combined retrieved data, suggesting that model updates from diverse examples are more effective than heuristic selection.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.