Exploring Distributional Shifts in Large Language Models for Code Analysis
Paper · 2023 · Shushan Arakelyan, Rocktim Das, Yi Mao et al.
Summary
A code assistant can score well on a benchmark and still struggle when it encounters a new repository. Arakelyan and colleagues ask how much performance changes when the unfamiliar code belongs to a different organization, a different project, or a different part of a project. They study large language models on two tasks that use the same material in opposite directions. In code summarization, a system reads a JavaScript function and writes a description. In code generation, it reads the description and writes the function. The authors use function–description pairs from CodeSearchNet to test CodeT5, Codex, and ChatGPT.
For each kind of software boundary, the authors hold out evaluation functions and compare different ways of preparing a system to handle them. They give CodeT5 a small set of labeled examples for further training. They show Codex and ChatGPT examples in the prompt. The examples can come from the same domain as the evaluation functions or from elsewhere. All three systems show sensitivity to where those examples come from. For summarization, the paper reports an average improvement of over 10 points on the BLEU score after adaptation with a few examples from the target domain. The effect varies by system, task, and boundary. In code generation, for instance, it is smaller for CodeT5 under CodeBLEU than for Codex.
The authors then ask what can be done when a new domain has inputs but few or no labeled examples. They search the existing training corpus for labeled examples similar to the new inputs. CodeT5 trains on the collected examples, while Codex receives a separate selection for each prompt. On CodeSearchNet, this strategy can match or exceed adaptation with a small set of labeled examples from the new domain. Joint training across source domains gives CodeT5 a starting point, and retrieval makes the subsequent adaptation more relevant. The gains are less consistent when the target examples come from The Vault, a separate dataset.
Finally, the paper tests whether adaptation can be shared across targets. A single CodeT5 system trained on examples pooled for several domains can come close to separately adapted systems on code generation. Summarization incurs a clearer cost. For Codex, drawing demonstrations from a shared domain pool lowers scores compared with selecting them for each input. The experiments distinguish two decisions that matter in practice. One is whether examples from outside a new domain can help. The other is how closely those examples need to be tailored to the domain or the individual request.
Deep dive: Exploring Distributional Shifts in Large Language Models for Code Analysis
Arakelyan and colleagues test how code assistants handle unfamiliar software and whether training examples from other projects can help. · about 34 minutes to read
The problem and its context
What counts as unfamiliar software
A software project provides its own context for understanding a function. The function may refer to a member defined elsewhere, or use names that make sense to people who work in that part of the codebase. A system trained on other software can still recognize the programming language and the shape of the task. Its training experience may give it less guidance about the particular function, documentation, or conventions it now encounters. The paper investigates that gap through the boundaries by which software is already organized.
The broadest boundary in the study is the organization. A move across that boundary can bring code from a new owner and from projects the system has yet to encounter in the experiment. The next boundary is the repository, which the paper uses as the project unit. A change of repository can matter even in a corpus whose projects all use JavaScript. The finest boundary is the folder containing the function. Folders give the authors a way to identify parts of projects using information available in the dataset. A folder is thus an operational definition of a component. Its path tells the researchers where the code belongs, while the experiment tests whether that grouping is meaningful for prediction.
A distribution shift is a change in the kinds of examples a system encounters between the data it learns from and the data on which it is used. Here, the authors use organizational membership to construct comparisons that could exhibit such a change. The label attached to a domain is a way to define the experiment. The distributional evidence comes from performance comparisons and from a separate analysis of example similarity. Two functions from separate repositories can still resemble each other closely, and functions in a shared folder can serve quite different purposes.
The paper’s practical motivation is a reader deciding what a benchmark score means for their own software. A good benchmark result says how well the system handled the examples and preparation used in that evaluation. A private project or a newly created component can present a different selection of code. To study that difference, the authors ask what happens when the system has access to some labeled examples from the relevant domain and compare that with performance when the available examples come from outside it. Holding the evaluation target steady makes that comparison more informative than comparing raw scores from unrelated datasets.
Where earlier work left the question
The paper places its study in a line of software engineering research that had already encountered problems transferring predictions to new systems. Much of the work it describes studied cross-project transfer. A predictor learned from one collection of projects and was evaluated on a disjoint collection. Earlier systems in that literature included linear classifiers and support vector machines, followed by recurrent approaches using LSTMs. The paper also notes that cross-company and cross-project distinctions had been used in software engineering work on problems such as defect prediction and cost estimation. Those distinctions gave the authors a reason to start from the organization of software itself.
The authors describe more recent code studies that examined shifts involving different source-code authors, different points in a project’s history, and changes in the distribution of code tokens. The introduction also describes work concerned with code from large projects and from smaller programming problems. Each choice defines a different way for future inputs to depart from earlier ones. A temporal split asks about change over time, for instance, while the splits in this paper ask what happens when the next function comes from a different organizational unit. Studying several granularities lets the authors treat “new code” as a more specific condition than a single cross-project label.
Several of the adaptation methods already had precedents. In few-shot learning, a system is given a small number of examples from which to adapt its behavior. Work on GPT-3 had shown that the examples could be presented as part of the input. A prompt could state the task, show completed examples, and then present a new item to complete. This gave the authors an adaptation procedure for systems whose weights they would leave fixed. Language Models are Few-Shot Learners
Earlier prompt-selection work also gave the paper a reason to vary the examples themselves. As Arakelyan and colleagues describe it, Liu and colleagues encoded candidate examples and selected nearby examples for individual test inputs. The premise was that examples could differ in usefulness even when they all demonstrated the same task. The code study extends that question to examples used for additional training, as well as examples shown in a prompt. The related work also describes task-specific retrievers used for knowledge-base questions and demonstrations selected for semantic parsing. What Makes Good In-Context Examples for GPT-3?
For systems that can be updated, the paper considers joint training and meta-learning. Joint training uses examples from several tasks or domains to produce a shared starting point. Meta-learning explicitly seeks a starting point that will respond well to a small amount of later training. The background distinguishes these aims because both can produce an initialization for adaptation, even though they optimize it differently. The paper also draws on parameter-efficient adaptation, which changes a small set of trainable parameters during fine-tuning.
Why the two tasks belong together
The functions and their accompanying docstrings make it possible to study both prediction directions with the same underlying data. A docstring is the text associated with the function that describes its purpose or use. For summarization, it serves as the reference output. For generation, it supplies the request. This pairing keeps the study focused on a recognizable unit of software and gives the authors a way to see whether a domain boundary affects both tasks similarly.
The two directions also expose different information at prediction time. A function supplied for summarization presents concrete implementation clues, including the names that appear in its body. A description supplied for generation may leave implementation decisions implicit. This distinction matters later when the authors retrieve supervision from the visible side of each example and when they judge the resulting output against the paired reference. A system can benefit from seeing relevant examples in both cases, while the size and meaning of the score changes depend on the task.
The method, step by step
Start with functions and keep track of their origin
The primary experiment uses the JavaScript partition of CodeSearchNet. Each record supplies a function, its natural-language description, and a path that identifies its source. The authors extract the organization, repository, and lowest-level folder from that path. They build a collection of groups for each of those granularities. Within the repository grouping, for instance, a group contains functions from a particular repository. The same function can be a member of a folder group in one evaluation and an organization group in another.
The authors begin with the corpus’s existing training partition. They combine its development and test partitions into a candidate pool for evaluation. CodeSearchNet was partitioned by project, so an organization can have one project in training and a different project in the candidate pool. The authors therefore remove any evaluation domain that also occurs in the training partition under the boundary being tested. This extra filtering matters particularly for the organization comparison. Holding out a repository alone would leave open whether the system had seen other training repositories from the same organization.
The paper denotes a domain’s group of examples by τ with an index. Its notation for a training-side group can be written as follows.
τᵢ ⊂ Xₜᵣₐᵢₙ
Here τᵢ is the set of examples in domain i for the granularity in use. The subscript i identifies the domain. Xₜᵣₐᵢₙ is CodeSearchNet’s original training partition, and ⊂ marks the group as a subset of that partition. In the experiments that prepare CodeT5 across domains, this partition supplies the examples. It is also the search corpus for retrieving supervision.
The held-out groups have the corresponding membership relation.
τᵢ ⊂ Xₜₑₛₜ
Here Xₜₑₛₜ denotes the collection made from the corpus’s development and test partitions, with overlap with training removed at the relevant domain granularity. The symbol τᵢ denotes a group in that collection, i identifies the domain, and ⊂ again means that the group belongs to the larger set. The paper’s use of unseen is tied to this separation. It concerns the split used in the experiment, while exposure during pretraining is a separate question.
Give every held-out domain its own evaluation split
The authors split each eligible held-out domain into portions for adaptation, development, and evaluation. They write these as τ with the domain index i and the role marked by train, dev, or test. The adaptation portion supplies labeled examples for the in-domain condition. The development portion is available for selecting an adapted checkpoint. The evaluation portion supplies the scored examples.
Keeping these portions distinct is essential to the comparison. A system receiving in-domain supervision sees other labeled examples from the same software group. It is then judged on the held-out functions or descriptions in the evaluation portion. This estimates the advantage of having a little information about the new domain. The authors call it a proxy for performance if the domain had been encountered during training. It represents a particular amount of access to the domain, with the adaptation budget specified by each run.
The preprocessing procedure uses 5 random seeds to divide the held-out domains. It aims to reserve at least 32 examples apiece for development and evaluation, and allows up to 32 for adaptation. The cutoff reported in the procedure and used in the table’s eligibility notation is as follows.
|τᵢ| ≥ 96
The bars around τᵢ indicate the number of examples in the domain indexed by i. The sign ≥ means at least, and 96 is the domain-size threshold. For the retrieval experiment, the paper specifies a test portion of 32 examples per domain. Repeating the split with different seeds varies which particular functions or descriptions are available for adaptation, checkpoint selection, and evaluation.
Establish how much in-domain examples help
The first comparison asks how performance changes when the source of a small set of adaptation examples changes. In-domain examples come from the adaptation portion of the same domain as the evaluation input. The random condition uses examples from outside that domain. For CodeT5, each version is trained for the task using one of these sources before it is tested. For Codex and ChatGPT, the authors show completed input–output examples alongside the task instruction. The comparison is between sources of supervision for the same target evaluation.
CodeT5 uses the T5-large encoder–decoder architecture, with 700 million parameters in the paper’s account. Its encoder processes the function or description supplied as input, and its decoder produces the sequence for the requested output. The original CodeT5 training described by the paper takes account of programming identifiers and of links between code and natural-language comments. The authors use CodeT5-large in both directions without altering its architecture. The underlying text-to-text formulation comes from T5. Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer
The authors compare full fine-tuning of CodeT5 with a parameter-efficient alternative. Full fine-tuning updates the existing weights. In their full fine-tuning setup, the authors run 500 steps with a batch size of 8 and select the best checkpoint using the domain’s development portion. They vary the amount of adaptation data across 8, 16, and 32 labeled examples. The corresponding random conditions give the comparison a training baseline at each budget. That helps separate the benefit of doing some additional training from the benefit of doing it on relevant data.
Low-Rank Adaptation, or LoRA, gives the authors another way to make that comparison. It learns updates through pairs of smaller matrices associated with existing weight matrices. For CodeT5, the paper specifies rank 4, an initialization scale of 0.01, and updates in the attention and feedforward layers. Each run uses a batch size of 8 and spans 1000 steps. Full fine-tuning and LoRA thus provide different ways to learn from the same kinds of examples. LoRA: Low-Rank Adaptation of Large Language Models
For Codex, the study uses code-cushman-001. The paper describes Codex as a decoder-only system based on GPT-3. The researchers give it an instruction followed by the function or description to process. They also test in-context learning, where the prompt includes examples of the requested input and its desired output. A generation prompt can demonstrate how a description is followed by a function, while a summarization prompt can show the function followed by its description. These demonstrations are read as part of the prompt. The weights stay fixed throughout the comparison. Evaluating Large Language Models Trained on Code
The ChatGPT experiments use gpt-3.5-turbo, described in the paper as a conversational system derived from InstructGPT and trained with feedback from people. It too receives either an instruction alone or an instruction with demonstrations. The authors use a 4096-token input limit for these prompt experiments and fit up to 8 demonstrations alongside each evaluation item. They vary instruction wording and average results. They also shuffle the demonstrations 5 times and average across those arrangements, since changing the order can affect a prompt’s performance. Training language models to follow instructions with human feedback
Prepare CodeT5 for adaptation across domains
The next group of experiments asks whether a better starting checkpoint can improve performance on a held-out domain. The authors begin with pretrained CodeT5 and consider several ways of preparing it before the target adaptation step. These preparations use the training portion of CodeSearchNet. The subsequent evaluation distinguishes performance directly from the prepared checkpoint from performance after additional adaptation.
In ordinary multitask learning, abbreviated MTL in the paper, the authors train a shared system across source domains. Here, training across domains can still concern a single output direction. For summarization, they use the available CodeT5 checkpoint already fine-tuned on the CodeSearchNet training portion. For JavaScript generation, they prepare their own checkpoint because the corresponding checkpoint was unavailable from the CodeT5 authors. The generation training uses 80% of the training partition for updates and holds out 20% for checkpoint selection. It runs for 150K steps with a batch size of 4.
The dual-generation variant also mixes the two prediction directions. A task instruction at the front of each input indicates whether CodeT5 should produce a description or JavaScript. The paper applies the same training and development division used for generation, and again gives the budget as 150K steps with a batch size of 4. It selects a checkpoint for each direction using the corresponding development metric, CodeBLEU for generation and BLEU for summarization. This lets the authors test whether learning both directions in a single training run improves the starting point for adaptation.
The meta-learning experiment uses a gradient-based method. The idea is to prepare weights that respond well to a small update on a new domain. The authors restrict the source domains to those with at least 96 examples so each domain can support disjoint data for training and meta-training. They initialize from pretrained CodeT5, run the meta-learning procedure for 10K steps, and use its last checkpoint. The data restriction is part of the comparison because meta-learning requires grouping examples into sufficiently large domains, whereas ordinary joint training can draw on the broader training partition. Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks
Search for labeled examples using the new inputs
The retrieval procedure begins with a situation in which inputs from a new domain are available and their correct outputs are unknown for adaptation. For summarization, the system can read the functions it is asked to describe. For generation, it can read the descriptions it is asked to implement. The search aims to find labeled examples elsewhere that resemble these inputs. A match from the training corpus brings both sides of its pair, so it can be used for supervised training or as a complete demonstration.
The authors use the pretrained CodeT5 checkpoint to obtain embeddings, numerical vectors that represent examples for comparison. Their main retrieval method scores pairs of vectors by cosine similarity. This measure compares their directions. For each held-out input they rank the source examples and take the nearest ones. Searching separately for each input lets each part of the evaluation domain contribute matches. A query involving one kind of function can bring in examples different from those contributed by a query involving another kind.
The procedure is easiest to follow in the CodeT5 case. The domain’s evaluation portion supplies 32 search queries. For each query, the authors collect k matches, where k is set to 4, 8, or 32 in separate experiments. The size of the candidate collection before removing duplicate retrievals follows directly from the paper’s specification.
k × |τₜₑₛₜⁱ|
Here k is the number of matches requested for each evaluation input. The symbol τₜₑₛₜⁱ is the evaluation portion of domain i, the bars count its examples, and × denotes multiplication. The paper gives the resulting candidate counts as 128, 256, and 1024, respectively. A training example can be retrieved for more than one query. The authors remove repeated entries and call the resulting set τᵣₑₜ, where τ denotes a set of examples and the subscript ret indicates that the set came from retrieval.
The authors then fine-tune CodeT5 using the labeled pairs in that set and evaluate it on the new domain. The adaptation is specific to the domain because its collection was assembled from that domain’s inputs. It can use supervision even when the target domain has supplied no labeled adaptation examples. The target inputs themselves remain important, since they determine which labeled pairs from the source are used.
For Codex, the retrieval stage serves a similar purpose but produces a different artifact. The authors take 4 or 8 nearest training examples for an individual evaluation input and put those examples into its prompt. Every new input can receive a different demonstration set. The distinction is important for interpreting the retrieval budgets. In CodeT5, the matches gathered across a domain become training data. In Codex, the matches for an input accompany that single request and the system reads them at prediction time.
How the authors adapt to a held-out software domain
The steps in order.
Test how much adaptation can be shared
Domain-specific fine-tuning creates a separate adapted CodeT5 checkpoint for each target domain. The authors test a shared alternative by pooling the retrieved sets from the target domains and fine-tuning a single CodeT5 system on the combined examples. They repeat the experiment with different per-query retrieval budgets. The shared checkpoint can then be evaluated across the domains for which the pool was assembled. The reference for comparison is the separately adapted checkpoint for each domain.
The authors also test fast vote-k, a selection method that seeks representative examples while preserving diversity. They run it at the candidate budgets associated with the combined nearest-example strategy. The comparison asks whether a diverse selection can serve the same practical role as pooling the neighbors chosen for target inputs. The two procedures use different criteria for assembling training data, giving the authors a way to examine how much the selection rule matters.
The corresponding Codex experiment relaxes the requirement to select demonstrations individually. For each evaluation input, the authors sample demonstrations from the retrieved pool for its domain. They use 4 or 8 demonstrations, as in the individually retrieved setting. This preserves some domain relevance because every example in the pool was retrieved for a query from that domain. The examples available for a particular prompt can nevertheless have been collected for a different query.
Repeat the retrieval test across datasets
The authors use the test partition of The Vault for a challenge evaluation. The Vault is a multilingual corpus collected from GitHub. For the experiment, the researchers process the data to follow the grouping and splitting procedure used for CodeSearchNet and address differences in the treatment of functions and docstrings. CodeSearchNet examples can retain inline comments, for instance, while The Vault strips them from function bodies. The Vault descriptions also tend to be longer and can include documentation for parameters that CodeSearchNet omits.
This setup asks how well retrieval works when the labeled pool and evaluation examples come from different collections. It retains the basic function–description format and a shared upstream source, while allowing the dataset construction process to differ. Across the paper, the authors report releasing the code and data for their experiments.
Experiments and results
Which domains contribute to the scores
The CodeSearchNet training partition contains 9737 organization domains, 15,858 repository domains, and 25,268 folder domains before the minimum-size restriction. At the cutoff used for eligibility, it contains 195 organization domains, 147 repository domains, and 100 folder domains. The corresponding held-out evaluation counts are 8 organizations, 15 repositories, and 10 folders. These are counts of domain groups in each evaluation, so a comparison between folder and repository results can involve different collections of functions.
The main baselines address different questions. In the first experiment, the CodeT5 random-supervision conditions measure how far a small training set goes when it comes from outside the domain. For Codex and ChatGPT, instruction-only prompting gives a starting score, and random demonstrations show the effect of adding examples without matching the domain. In the retrieval experiments, a prepared CodeT5 checkpoint used without adaptation tests whether broader initial training suffices. Labeled in-domain adaptation provides a reference for what can be gained when the target domain supplies examples directly.
The final comparisons use a more specific reference. CodeT5 trained on combined retrieved data is judged against CodeT5 trained on a separate retrieved set for each domain. Codex prompted with examples sampled from a domain pool is judged against Codex prompted with neighbors of the current input. These baselines hold the broad kind of adaptation steady and vary how the examples are selected or pooled. Their score changes therefore answer a different question from the initial comparison between in-domain and randomly chosen examples.
How the authors score functions and descriptions
For summarization, the authors use BLEU-4 to compare each system’s generated descriptions with the reference docstrings. BLEU evaluates overlap between sequences in the prediction and reference. The score favors outputs whose wording resembles the recorded description. In this experiment, that comparison is made on the held-out part of each domain, after the relevant training or prompt preparation. Bleu: a Method for Automatic Evaluation of Machine Translation
For code generation, the main score is CodeBLEU. The authors use an existing implementation and add a list of JavaScript keywords for the evaluation. The reference is the function paired with the input description. They supplement this metric with measures that compare the output and reference differently, including the character-based chrF, RougeL, and CodeBERTScore. They report that the metrics broadly support the same conclusions in their experiments, with the exact scores supplied separately.
The supplementary metrics matter because the paper cites earlier evidence of disagreement between CodeBLEU scores and assessments by people. Consistent direction across several metrics increases confidence that the main comparison depends on more than a single scoring rule. Absolute values still depend on the metric. A BLEU score on a docstring and a CodeBLEU score on a function describe different output comparisons. The stronger evidence for a domain effect comes from matching the task, metric, and evaluation domain while changing the source of examples.
CodeT5 gains more from in-domain supervision on summaries
The CodeT5 summarization experiment shows a separation between in-domain and random supervision at all the studied granularities. For the folder split with 8 labeled adaptation examples, full fine-tuning yields 14.39 BLEU with in-domain data and 3.58 with random data. LoRA yields 16.57 with in-domain data and 3.69 in its random counterpart. The direction of the comparison is the same when the system changes only the low-rank updates. The relative advantage of the target-domain examples persists across these two ways of changing weights.
For repository summarization with 16 examples, CodeT5 full fine-tuning reaches 14.73 BLEU using in-domain examples and 4.70 using random ones. LoRA reaches 17.14 and 5.56 under those respective conditions. With 32 repository examples, the strongest setting in the comparison is in-domain LoRA. Both ways of training with in-domain examples clearly outperform both random conditions at that budget.
CodeT5 adaptation with 32 examples on CodeSearchNet repository summarization
In-domain supervision yields higher BLEU with either update method.
The numbers
| System or setting | BLEU |
|---|---|
| Full fine-tuning with random examples | 5.79 |
| LoRA with random examples | 5.92 |
| Full fine-tuning with in-domain examples | 16.82 |
| LoRA with in-domain examples (this paper) | 21.20 |
On the organization split with 32 examples, the in-domain full fine-tuning score is 17.65 BLEU and the in-domain LoRA score is 20.87. The respective random-example scores are 6.27 and 6.26. Looking across the folder, repository, and organization comparisons gives the paper grounds to say that the issue extends to several natural boundaries. The experiment attributes the stronger scores to the opportunity to learn from labeled material related to the evaluation domain, under the particular adaptation budgets used.
The CodeBLEU figures for generation show less uniform separation. For CodeT5 full fine-tuning with 8 folder examples, the in-domain condition scores 14.67 and the random condition scores 15.23. At 32 folder examples, the respective scores are 16.13 and 15.15. The folder comparison thus includes a case in which random examples do better on this metric and a case in which more in-domain examples give the expected ordering.
The repository generation comparison supplies clearer evidence of an in-domain advantage for CodeT5. With 32 examples, full fine-tuning reaches 18.62 CodeBLEU for in-domain supervision and 14.67 for random supervision. LoRA reaches 18.96 and 15.04, respectively. On the organization split at that same budget, full fine-tuning scores 16.43 with in-domain examples and 14.44 with random ones. LoRA scores 16.62 with in-domain examples and 14.81 with random ones. The overall trend therefore admits variation by granularity and by adaptation budget. The paper suggests that the difficulty of generation for CodeT5 may make the domain effect less visible on CodeBLEU.
Closely matched prompts make a large difference for Codex
Without demonstrations, Codex scores 1.55 BLEU on folder summarization, 1.52 on repository summarization, and 1.61 on organization summarization. Random demonstrations raise those scores to 7.17, 6.84, and 6.73, respectively. In-domain demonstrations yield 20.34, 19.00, and 20.72. These are the paper’s 8-shot prompting conditions, with the actual number of demonstrations bounded by the space available in the prompt. The comparisons show an advantage from seeing examples of the requested output and a further advantage when those examples come from the domain under evaluation.
Codex also benefits from demonstrations on code generation. On the folder split, the instruction-only score is 5.49 CodeBLEU. Random and in-domain demonstrations produce 16.82 and 25.73, respectively. On the organization split, the corresponding scores are 5.77, 16.82, and 23.87. The same ordering appears on the repository split. This is the main contrast with the initial CodeT5 generation results. The benefit of target-domain examples is readily visible for Codex across all the generation granularities under the prompt procedure used.
Prompt settings on CodeSearchNet repository code generation
In-domain demonstrations give both systems their highest scores, with Codex achieving the highest result overall.
The numbers
| System or setting | CodeBLEU |
|---|---|
| Codex, instruction only | 5.72 |
| Codex, random demonstrations | 17.47 |
| Codex, in-domain demonstrations (this paper) | 24.64 |
| ChatGPT, instruction only | 8.39 |
| ChatGPT, random demonstrations | 13.19 |
| ChatGPT, in-domain demonstrations | 15.81 |
ChatGPT has the stronger instruction-only result in the paper’s comparisons, while the addition of examples affects it differently. On repository summarization, it scores 5.48 BLEU with an instruction alone, 6.58 with random demonstrations, and 9.15 with in-domain demonstrations. For folder summarization, the scores are 5.74, 5.47, and 7.47. The slight decline with random folder demonstrations illustrates that giving a system examples and giving it useful examples are separate interventions. On organization generation, ChatGPT moves from 8.04 CodeBLEU with instruction only to 12.70 with random examples and 15.55 with in-domain ones.
The authors inspect ChatGPT’s responses and find cases where it declines to complete the task when the input is vague or noisy. Unanswered items receive 0 in their evaluation, so the aggregate scores incorporate both the decision to answer and the match between a produced answer and the reference. The paper uses this observation to explain some of ChatGPT’s weaker gains from demonstration and ends its ChatGPT comparison after establishing the sensitivity to domain. The later retrieval and pooling results concern CodeT5 and Codex.
Retrieved supervision is most competitive at small label budgets
Preparing CodeT5 through multitask training or meta-learning gives the authors several checkpoints to try on unseen domains. The reported results show a persistent gap between running those checkpoints directly and adapting them with a small amount of relevant supervision. This pattern appears both when the new supervision comes from the domain itself and when the authors retrieve it from training data. The checkpoint determines where adaptation starts. Which examples it sees next remains consequential.
On CodeSearchNet summarization, retrieving 4 or 8 examples per test input can bring performance up to, or above, the level of adaptation with 8 labeled examples from the held-out domain. The authors observe this for both CodeT5 and Codex, particularly on the repository and organization splits. For CodeT5, the retrieved neighbors are pooled before fine-tuning. The 8-example in-domain comparison is therefore a comparison of scarce target labels with a potentially larger set of labeled source examples. For Codex, the examples appear in the prompt, so 8 retrieved demonstrations and 8 in-domain demonstrations are much closer in form.
The generation results are especially favorable to retrieval for CodeT5. The paper reports settings where fine-tuning on retrieved examples outperforms fine-tuning on 32 labeled examples from the target domain. This result answers a question about the value of access to a large labeled source corpus when target labels are scarce. How those examples are selected also matters. The same initial CodeT5 can perform differently when given a broad neighborhood than when trained on a narrower one.
The challenge test on The Vault gives a more qualified result. Further adaptation remains valuable compared with running the prepared checkpoint directly, but the paper finds that retrieved supervision is less effective across the two datasets. The authors connect this result to residual differences in collection and preprocessing after aligning the examples as far as they could. The experiment consequently supports the retrieval strategy most strongly when the labeled corpus and new inputs are drawn from similarly constructed data.
Shared training is more competitive for generation
When the authors combine the retrieved training sets for several domains, the generation results for CodeT5 sometimes come very close to separate adaptation. At 4 retrieved examples per input, the combined training run reaches 29.46 CodeBLEU on the organization split, with a reported change of -0.19 relative to separate adaptation. On the repository split, it reaches 29.41, with a change of -0.01. On the folder split, the score is 26.60, with a change of -1.53. The closest agreement is therefore found for organization and repository generation at this retrieval depth.
The shared settings with a larger retrieval budget can be less competitive. At 32 retrieved examples per input, combined CodeT5 training scores 26.28 CodeBLEU on the organization split and 25.01 on the repository split. The reported changes relative to individual adaptation are -3.63 and -4.02, respectively. This variation puts a condition on the paper’s broad conclusion about a shared generation system. The choice of retrieval depth influences how well pooling works.
Summarization shows a clearer cost from sharing a checkpoint. With 4 retrieved examples per input, combined CodeT5 training gives 18.74 BLEU on the organization split, a change of -4.74 compared with separate adaptation. The repository score is 18.59 with a change of -4.47, and the folder score is 18.06 with a change of -1.06. A pooled checkpoint can still be useful across the domains. How close it comes to dedicated adaptation depends on both the task and the grouping.
For Codex, drawing demonstrations from a domain pool produces larger losses against individual retrieval. With 4 demonstrations sampled from the pool, organization summarization scores 14.66 BLEU, with a change of -7.04. Repository summarization scores 12.68 with a change of -7.95. On generation, folder prompts sampled from the pool score 19.39 CodeBLEU, with a change of -6.21. These conditions retain the same general pool of relevance while weakening the direct connection between each demonstration and its query. The results favor preserving that connection when retrieving demonstrations for Codex.
What the ablations show
Where the examples come from matters across update methods
The comparison between in-domain and random supervision also functions as a control on the source of improvement. In CodeT5 summarization, both full fine-tuning and LoRA show a large separation between matched and random examples. This rules out an explanation specific to one method for changing the system’s parameters. For the in-domain conditions, LoRA also scores higher in every summarization cell in the main comparison. On the folder split at 16 examples, for instance, it reaches 19.07 BLEU while full fine-tuning reaches 16.06. In this setup, updating a smaller set of parameters is sufficient to exploit the new domain labels.
Generation offers a more qualified comparison. For repositories at 16 labeled examples, CodeT5 reaches 17.42 CodeBLEU with full in-domain fine-tuning and 17.45 with in-domain LoRA. For folders at the same budget, the scores are 15.22 and 15.06. The two update methods are close on these examples. This helps explain why a single conclusion about LoRA across both directions would be too broad. The clearer effect is the interaction between the source of supervision and the task.
The Codex and ChatGPT instruction baselines provide another control. They show what each system produces when told the task and given only the input to process. Adding randomly selected demonstrations supplies examples of output form and of the input–output relationship, with uncertain relevance to the target. Adding in-domain demonstrations supplies those cues from the relevant software group. Prompt wording and ordering are varied in the experiment, making the comparison less dependent on one particular prompt sequence.
Retrieval depth has a practical optimum in the tested range
The authors vary how many neighbors each evaluation input can contribute to CodeT5 adaptation. When the budget grows from 4 or 8 neighbors to 32, performance is almost always worse in this comparison. The authors also find that Codex performs similarly with 4 or 8 retrieved demonstrations. A neighbor count can enlarge the amount of available supervision, but the additional candidates come from farther down the ranking. The comparison establishes that a larger candidate set can be less effective. How much of that outcome comes from individual examples, label quality, or subsequent training remains open.
The trend differs from the one the paper observes with small sets of labeled examples drawn directly from the domain. In the in-domain experiments, gains continue as the tested label budget rises. For example, full fine-tuning for CodeT5 repository summarization rises from 12.68 BLEU with 8 in-domain examples to 14.73 with 16, then to 16.82 with 32. The distinction is important for interpreting the retrieval experiment. Additional observed labels from the target domain and additional lower-ranked neighbors from an outside corpus vary more than the sheer number of examples.
The authors also compare cosine retrieval with a selection procedure based on IsoScore. IsoScore characterizes how uniformly a set of embeddings uses its vector space. The authors apply it to a set of evaluation embeddings together with an individual source candidate, then use the candidates associated with the largest values. They compare sets selected at the same nominal supervision budgets as the cosine runs. This tests two ways of using the embeddings. Cosine ranks examples by their relation to an individual query, while the IsoScore procedure judges a candidate in relation to a group of target embeddings.
The paper finds cosine similarity more effective overall and uses it for the main retrieval results. The alternate results provide a view of how scores vary with the selection rule. For organization generation after CodeT5 adaptation, the IsoScore table reports 15.05 CodeBLEU at the 4 setting, 15.32 at 8, and 16.13 at 32. For folder summarization it reports 15.47, 15.71, and 14.34 BLEU at the same settings. The response to budget varies with the task and the retrieval procedure. A trend under cosine retrieval need not hold under a different way of ranking examples.
Pooling and representative selection change different things
The fast vote-k comparison tests the use of a representative, diverse selection for the shared CodeT5 checkpoint. On CodeSearchNet organization generation, it yields lower scores than training on the combined retrieved neighbors at each of the shown budgets. The score for the pooled-neighbor approach is strongest at the smallest shown budget, while fast vote-k reaches its best score at the middle budget. This is a comparison between selection procedures at corresponding nominal budgets. Repeated retrievals can be removed when assembling the pooled supervision, so the budget label describes the selection setup.
Shared CodeT5 supervision selection on CodeSearchNet organization code generation
Pooling the retrieved neighbors yields higher scores than fast vote-k at each shown budget.
The numbers
| System or setting | CodeBLEU |
|---|---|
| Fast vote-k, budget for 4 neighbors | 24.96 |
| Fast vote-k, budget for 8 neighbors | 25.10 |
| Fast vote-k, budget for 32 neighbors | 24.25 |
| Combined retrieval, 4 neighbors per input (this paper) | 29.46 |
| Combined retrieval, 8 neighbors per input | 29.13 |
| Combined retrieval, 32 neighbors per input | 26.28 |
The shared CodeT5 comparison and the domain-pool Codex comparison involve different changes to the procedure. CodeT5 receives more than one domain’s retrieved examples during training, and the question is whether a single set of weights can serve them together. Codex has to decide what to predict using the few demonstrations visible in a particular prompt. Sampling those demonstrations from a domain pool can remove a close match that individual retrieval would have placed in front of it. The authors interpret the larger Codex losses as evidence of sensitivity to the precise demonstrations.
For CodeT5 generation, the near agreement between pooled and separate training in some settings is consistent with little negative transfer. In this context, negative transfer would mean that training on examples gathered for other domains impairs performance on the current one. The code generation scores show that substantial interference is avoidable in the tested setting. The summarization scores and some generation conditions record a cost, so the evidence for compatibility is strongest under the particular task and retrieval depth where the combined checkpoint comes close to its separate counterparts.
Other metrics and example outputs narrow the interpretation
The alternative generation metrics help explain why a weak CodeBLEU contrast in one setup should be read carefully. For CodeT5 full fine-tuning with 8 folder examples, the chrF score is 19.36 with in-domain labels and 17.61 with random labels. RougeL scores the same comparison at 14.15 and 11.34. CodeBLEU, in contrast, favors the random folder examples in that particular setting. The supplementary measures support the wider finding about domain sensitivity while showing that the magnitude and even the direction of an individual comparison can depend on the scoring rule.
Codex’s repository generation results illustrate a comparison where the other metrics agree more clearly. In-domain prompting scores 31.05 on chrF, versus 20.87 for random prompting and 10.60 for instruction only. The respective RougeL scores are 24.62, 15.67, and 6.50. The CodeBERTScore appendix also reports a higher score for in-domain than random demonstrations on this split. Its reported F1 values are 0.75 and 0.70, and its F3 values are 0.73 and 0.68. Agreement across these measures supports the ordering of prompt conditions on the repository evaluation.
The paper also inspects example outputs for summarization. It reports cases where CodeT5 trained on labels from the target domain uses the correct member name, while other versions miss that detail. The difference is plausible when the other examples in the same project provide relevant names or context. The authors also identify retrieved training examples that closely resemble held-out examples. In such cases, the retrieved supervision can lead to an output very close to the reference. Both observations are concrete ways in which the relationship between training examples and an evaluation input can affect a score.
The domain visualization gives another view of that relationship. The authors plot the average similarity of examples inside a domain against the average similarity between its examples and those of other domains. Most groups cluster in a region indicating greater internal similarity and less similarity to other groups. Some show the reverse pattern, with that pattern more common among folders than repositories and among repositories than organizations. The authors suggest that groups can share a functional role across the software hierarchy, as with folders that collect utilities, even if individual functions inside each folder perform different jobs. This gives a reason to expect an example-level retriever to find useful material across a boundary.
Limitations
Limits identified by the authors
The authors emphasize that their size filter favors larger software groups. A test domain has to support separate labeled adaptation, development, and evaluation portions. In their procedure, groups below 96 examples are filtered out. The authors give the variability of very small test sets as their reason for the cutoff. This decision has a direct consequence for the scope of the result. The held-out domains are large enough to sustain the study, while the scarcity in the low-data comparisons is created by restricting how many labels an adaptation run can use.
That matters because scarcity can also arise when a new component contains very few functions in total. The authors motivate their study with the prospect of a module or repository with fewer than 32 functions. A mature domain with few available adaptation labels and a newly created domain with very few functions both present a scarcity problem. Their available inputs, possible neighbors, and evaluation uncertainty can differ. The filter means the strongest evidence in this paper concerns limited supervision inside a domain with enough examples to evaluate reliably under the authors’ procedure.
The authors also flag uncertainty about pretraining exposure. Codex’s training data are undisclosed, so CodeSearchNet could have been represented in it. The appendix similarly describes limited information about ChatGPT’s training data and architecture. The domain filters govern the CodeSearchNet training and evaluation split and the examples supplied during the study. The evidence thus establishes what happens when the study changes access to relevant adaptation examples, under uncertain earlier exposure for the prompted systems.
A further concern the authors raise is how to interpret code generation metrics. Their use of multiple measures responds to prior evidence that CodeBLEU can disagree with human judgments. Agreement among the scores is evidence about trends under the chosen comparisons. The reported generation experiments evaluate resemblance to reference functions through those measures. Whether the generated programs behave as required in their projects remains a separate question.
Finally, the paper itself notes that some retrieved source examples can be near duplicates of held-out examples. Removing repeats from the collected training set stops the same retrieved record from being counted repeatedly within that set. A close match across the source and evaluation split can still remain and can help produce a reference-like answer. The examples in the appendix establish that this happens. The scale of its contribution to the overall retrieval gains remains open.
Limits visible in the experimental design
The paper’s in-domain comparison is a proxy for access to the domain under a specified label budget. It measures what happens after an adaptation procedure sees a few labeled examples from the same group as the evaluation items. A different amount of training, a larger labeled collection, or training from the beginning with the domain included could produce a different result. The reported gap should therefore be understood as an estimate conditional on the checkpoint, training procedure, and example budget used in each experiment.
The retrieval method for CodeT5 can use the full set of visible evaluation inputs when assembling supervision for a domain. This is a setting in which a batch of future requests is available for adaptation, even though their reference outputs are withheld. The results directly address that setting. A system that must prepare before observing any target inputs, or that receives a stream of new requests without a batch to search from, would face a different adaptation problem. Codex’s individual retrieval is closer to the latter case because it can choose demonstrations after an input arrives.
The in-domain and retrieved CodeT5 conditions also have different supervision budgets. The target-domain example count is the number of labeled pairs actually supplied for training. The retrieval budget specifies neighbors per visible input, after which the matches are pooled and duplicates removed. Retrieval getting close to a small labeled condition shows that outside supervision can substitute for some scarce target labels. It leaves open how the two sources compare when the number of distinct labeled pairs and the amount of computation are held equal.
The three boundary comparisons also use different domain inventories, after filtering for adequate size and excluding domains shared with training. A folder is operationally identified by its path. The layout of a repository determines how much that path corresponds to a coherent software component. Results across granularities show that the effects occur at multiple boundaries. They offer less direct evidence about which boundary creates the largest inherent shift, because the sets of software and the composition of each group can differ.
The scope of the tasks is also specific. The primary study works at the level of a JavaScript function and its docstring. Within that setup, a generation input can omit decisions that the reference function resolves in one particular way. For summarization, a description can express the same purpose in different words. Reference-based scores evaluate the outputs against the corpus’s recorded choices. Generalization to other programming languages, to tasks involving several files, or to decisions in an interactive project remains beyond the demonstrated scope.
The Vault comparison introduces new inputs and changes in dataset construction together. The authors take steps to align preprocessing and observe weaker retrieval effectiveness. That result establishes sensitivity to using a different collection. It cannot isolate which remaining differences are most important, such as documentation length or the treatment of comments. Likewise, the ChatGPT output inspection suggests that refusals affect average scores, but the reported comparison gives limited grounds for separating that contribution from the quality of the answers it does provide.
What came after
A later citing study examines self-verification in reasoning and planning, asking how well large language models can check proposed answers. The connection is a shared question about the conditions under which an apparent capability holds up. Arakelyan and colleagues vary the software domain and the source of examples, then measure the quality of predicted summaries or functions. The later study’s title identifies verification of reasoning and plans as its focus. On the Self-Verification Limitations of Large Language Models on Reasoning and Planning Tasks
These are distinct points at which a system can be evaluated. Better-matched examples can improve the function or description a system produces. Whether the system can recognize an error in a proposed answer requires a separate test. The citation establishes a connection between the studies. The extent to which the later work takes up the software splits, retrieval procedure, or adaptation experiments remains unspecified.
Cite
Cite as Shushan Arakelyan, Rocktim Das, Yi Mao and Xiang Ren. 2023. Exploring Distributional Shifts in Large Language Models for Code Analysis. Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing.
@inproceedings{arakelyan2023exploring,
title = {{Exploring Distributional Shifts in Large Language Models for Code Analysis}},
author = {Shushan Arakelyan, Rocktim Das, Yi Mao and Xiang Ren},
booktitle = {Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing},
year = {2023},
doi = {10.18653/v1/2023.emnlp-main.1013},
url = {https://doi.org/10.18653/v1/2023.emnlp-main.1013}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/arakelyan-2023-exploring-distributional-shifts-large-language/