---
title: "Detect-Localize-Repair — paper by Bui et al. (2022)"
description: "How CodeT5-DLR learns to detect buggy functions, rank suspect lines, and propose repairs, and what its Java and Python experiments establish."
canonical: "https://research.elamur.ai/free/en/papers/bui-2022-detect-localize-repair-unified-framework/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Parse](https://mova.elamur.ai/free/en/parse/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Translate](https://md.translate.elamur.ai/free/en/) · **Research** · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/) · [Constitution](https://md.constitution.elamur.ai/)

[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/bui-2022-detect-localize-repair-unified-framework/)

[Elamur Research](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2022](https://md.research.elamur.ai/free/en/papers/2022/) / Detect-Localize-Repair: A Unified Framework for Learning to Debug with CodeT5

# Detect-Localize-Repair: A Unified Framework for Learning to Debug with CodeT5

Paper · 2022 · Nghi Bui, Yue Wang and Steven C.H. Hoi

**Authors:** Nghi Bui, [Yue Wang](https://md.research.elamur.ai/free/en/authors/yue-wang/) and [Steven C.H. Hoi](https://md.research.elamur.ai/free/en/authors/steven-c-h-hoi/) · **Year:** 2022 · **Venue:** Findings of the Association for Computational Linguistics: EMNLP 2022 · **Licence:** [CC BY 4.0 (ACL Anthology)](https://creativecommons.org/licenses/by/4.0/)

[Cited by **4** papers in our library of more than 163,000 papers whose bibliographies we read](https://md.research.elamur.ai/free/en/papers/bui-2022-detect-localize-repair-unified-framework/cited-by/) · Findings of the Association for Computational Linguistics: EMNLP 2022 · [licence](https://creativecommons.org/licenses/by/4.0/)

- [Publisher's page](https://aclanthology.org/2022.findings-emnlp.57/)
- [PDF](https://aclanthology.org/2022.findings-emnlp.57.pdf)
- [DOI 10.18653/v1/2022.findings-emnlp.57](https://doi.org/10.18653/v1/2022.findings-emnlp.57)

## Summary

Finding a bug in a function and knowing how to fix it are different problems. A warning about the whole function can leave a developer searching through many lines, while a well-placed warning can still leave the right replacement unclear. Bui, Wang, and Hoi study whether a single system can learn to make all of these judgments from examples of past fixes. Their framework, CodeT5-DLR, starts with CodeT5, which has already learned from a large collection of source code. It then learns to classify functions, rank their lines by how likely they are to contain a bug, and generate candidate replacements for the whole function.

The authors build benchmarks from GitHub commits to support all three tasks. Each bug-fix pair supplies the function before the change, the function after it, and the location of the changed line or lines. SL-Java contains single-line fixes in Java. ML-Python contains fixes that span multiple lines in Python. For detection, the before and after versions provide examples on both sides of the classification task. For repair, the before version supplies the input and the after version supplies the text the system is trained to predict.

Training all three tasks together generally gives the strongest results. On the SL-Java test split, CodeT5-DLR reaches an F1 score of 63.46 for function detection, an MRR@5 of 34.67 for line ranking, and an exact-match repair score of 10.30. On ML-Python, the corresponding detection and repair scores are 54.83 and 6.30, with a MAP@5 of 33.75 for ranking multiple suspect lines. The paper also runs a combined procedure in which the detector decides which test functions to send to localization and repair. On SL-Java, the resulting localization score is 33.93 on MRR@5 and the repair score is 46.93 on BLEU. Those scores measure line ranking and resemblance to the recorded fix, respectively.

The main result is that learning these tasks together helps even when the outputs are evaluated separately. The paper also shows where that benefit ends. The detector and the repair generator can disagree about whether a function needs a change, and a correctly ranked line can still elicit the wrong repair. Each prediction is based on the text inside the function, so a bug whose explanation lies in a caller or another definition may have little evidence in the input.

## Deep dive: Detect-Localize-Repair: A Unified Framework for Learning to Debug with CodeT5

How CodeT5-DLR learns to detect buggy functions, rank suspect lines, and propose repairs, and what its Java and Python experiments establish. · about 33 minutes to read

**In this deep dive**

1. [The problem and its context](#dd-the-problem-and-its-context)
2. [The method, step by step](#dd-the-method-step-by-step)
3. [Experiments and results](#dd-experiments-and-results)
4. [What the ablations show](#dd-what-the-ablations-show)
5. [Limitations](#dd-limitations)
6. [What came after](#dd-what-came-after)

### The problem and its context

#### From a warning to a useful place to look

The paper treats debugging as a series of judgments about source code. The first judgment concerns a whole function. Does anything in it look wrong? The second concerns the location of the fault. Which lines deserve attention? The third concerns the change itself. What would the corrected function look like? A system might be useful at one of these jobs and struggle at another. It can recognize that an expression is suspicious while having little basis for choosing between plausible replacements. It can also produce a plausible edit without reliably recognizing when the original code should be left alone.

The unit of localization matters because it determines what the developer can do with a warning. A file-level warning can cover many separate definitions. A function-level warning narrows the search to a piece of code with a recognizable purpose, but it can still leave several plausible sites. At the other extreme, a token-level prediction singles out an identifier, operator, literal, or other piece of the input. The authors argue that very fine predictions can produce many false alarms and that line-level output better matches the way a programmer reads a function during debugging. A line gives the reader enough surrounding text to inspect the suspicious expression while identifying a concrete place to start.

The line is also a unit that can be recovered from a recorded fix. A commit can show where an operator, call, or identifier changed inside a function. The authors use that evidence to construct supervision without asking a reviewer to annotate each function from scratch. Some fixes affect multiple lines, so the location target must be able to mark more than one line in the same function. That requirement changes the prediction problem. A system that must pick a single location can always point somewhere, even when several lines matter or when an input is the repaired member of a pair.

#### What earlier approaches supplied

The paper describes two broad traditions. Program-analysis approaches draw on techniques from compilers and software engineering. Some use structural information about the code. Others obtain a signal for fault localization by observing what happens when tests run. In spectrum-based localization, failed tests provide evidence about statements associated with the failure. In mutation-based localization, the analysis changes statements and measures the effects through a test suite. Both approaches can produce line- or statement-level suspicions. Their dependence on running tests is the scaling concern the authors emphasize for this branch of the field.

Learning-based approaches acquire patterns from source code and past repairs. The rationale the paper invokes is that code has enough regularity for recurring expressions and edits to be learned from examples. A program can use a valid identifier in a setting where a different identifier is customary, or make a call whose form is familiar but whose choice is unusual in context. Historical repairs give a learning system examples in which such choices changed. The method in this paper asks how far those examples can take a system that sees the source of a function at prediction time.

Prior learning approaches vary in how much program structure they build into the input. The paper names abstract syntax trees, control flow, and data flow as examples. An abstract syntax tree represents the nesting and roles of constructs in the source. Control flow represents paths through a program's statements, and data flow represents relationships involving the values those statements use. The authors see work in constructing these representations for particular languages or tools as a cost of moving a method to a new setting. CodeT5-DLR uses a sequence of code tokens with explicit line boundaries for its prediction input. Its data preparation still uses tools that understand source files well enough to extract functions and, for part of the analysis, recognize edit patterns.

Another thread of earlier work transferred methods for learning from ordinary text to source code. The paper describes CodeBERT as adapting RoBERTa to code in multiple languages, while CuBERT learned from a curated collection of Python files. It also describes a move toward pretraining objectives that take account of source-specific properties such as identifiers or data flow. This gave the authors a starting point for adaptation. They could begin with representations learned across a broad code collection and then use function pairs to teach the particular outputs needed for debugging. [RoBERTa](https://md.research.elamur.ai/free/en/papers/liu-2019-roberta-robustly-optimized-bert-pretraining/) · [GraphCodeBERT](https://md.research.elamur.ai/free/en/papers/guo-2021-graphcodebert-pre-training-code-representations/)

#### Why share the learning across tasks?

Some earlier work in the paper addresses repair as a task in its own right. In that setting, a defective fragment is the starting point, and the system learns to produce a correction. This is a natural way to measure the ability to rewrite code, but it leaves the decision about which inputs need attention outside the task. The paper also describes approaches that learn localization and repair together using simple, artificially introduced errors. Such data provide a known edit and a known location by construction. The authors want to study functions drawn from actual fixes, where the original edit was made as part of work on a repository.

The authors discuss a related approach that gives the system a token-level location and replacement problem. A pointer network selects a position in the input. CodeT5-DLR's localization objective instead assigns a probability to each line and uses those probabilities to form a ranking. The difference is important when clean functions can arrive alongside buggy ones, and when a defective function can have several relevant lines. The paper treats the many clean lines relative to the buggy ones as a design issue for a pointer-based approach in its setting. [Self-Supervised Bug Detection and Repair](https://md.research.elamur.ai/free/en/papers/allamanis-2021-self-supervised-bug-detection-repair/) · [Pointer Networks](https://md.research.elamur.ai/free/en/papers/vinyals-2015-pointer-networks/)

The central question is whether the kinds of evidence useful for these jobs can be learned together. Detection can benefit from understanding what normal code looks like around an anomalous statement. Localization provides more specific supervision by showing where an edit occurred. Repair gives supervision about how the expression or statement changed. A shared representation can receive all of those signals. Whether they actually improve each other is an experimental question. The paper addresses it by comparing jointly trained CodeT5-DLR with versions of CodeT5 trained for a single job.

The distinction between shared learning and a sequence of decisions matters throughout the study. A developer may first suspect a function, inspect the most likely lines, and then propose a patch. That order offers a template for evaluating the system. During training, however, the authors give the heads access to a shared representation of the input and use their losses together. The paper can therefore ask separately whether the tasks benefit from being learned together and what happens when their outputs are used in a detection-first procedure.

### The method, step by step

#### A common input with different outputs

Begin with a before-and-after pair from a bug-fix commit. The earlier function is the code the system needs to examine. The later function is a record of what the developer changed it to. The difference between them provides the location used in training. A detector can learn from the before and after versions as separate inputs, because they come with different function labels. A locator can learn which lines in a function have been associated with the fix. A repair generator can learn to read the before version and produce the after version. In the formal task, an input with no buggy line has an empty repair target.

CodeT5 is an encoder–decoder system. The encoder reads the input and produces a sequence of contextual representations, one for each encoded position. A representation at a position can carry information about the surrounding code, so its usefulness extends beyond the identity of the token at that position. The decoder uses the encoded input to generate an output sequence. In this framework, the encoder serves all three tasks. Detection and localization read different parts of its output, and repair uses the decoder to write a candidate fixed function.

The authors keep line boundaries visible by inserting `[SEP]` at the end of each line. A source line can occupy several positions once split into tokens. The separator gives the localization head a consistent position to read for that line. The input still contains the rest of the function, so scoring a line can draw on relationships across lines within it. The authors initialize the framework with CodeT5, whose pretraining included source code in 8 languages and used an objective concerned with identifiers. Its code-specific byte-pair encoding divides text into pieces, allowing a rare identifier to be represented through pieces from the vocabulary. [Subword tokenization](https://md.research.elamur.ai/free/en/concepts/subword-tokenization/)

Shared encoding and outputs in CodeT5-DLR The steps in order.

The three outputs have different meanings. The detector produces a probability for a function-level class. The locator produces scores that can be ordered to decide what to inspect first. The repair generator produces a ranking of candidate functions, each comprising generated code. The order in the diagram follows the debugging questions the paper poses. In the task architecture, line scores and repair candidates each depend on the encoded function.

#### Representing the training example

The authors use a triple to describe the information available for each input. It contains the function text, line labels, and a repair target.

```
D = {(X, Y, F)}
```

Here, `D` denotes the collection of debugging examples, and the braces indicate the collection of triples of the displayed form. `X` denotes the source function under examination. `Y` is its collection of line labels. `F` denotes the fixed function used as the target for a buggy input, or the empty string when there is no buggy line. The paper writes `|D|` for the size of the collection, with the vertical bars denoting the number of examples. The `D` in the task shorthand DLR stands for detection, a separate use of the same letter.

```
Y = (y₁, …, yₗ, …, yₗₐₛₜ)
```

Here, `Y` lists one label per line in source order. The first entry is `y₁`, `yₗ` is the label at a line indexed by `l`, and `yₗₐₛₜ` indicates the final line's label. The ellipses indicate intervening entries. In the paper's notation the last line index is `L`, the number of lines in `X`, and each label `yᵢ`, for line index `i`, is binary. The indicators for individual lines determine the binary indicator for the whole function.

```
y = 1 if any yᵢ = 1, and y = 0 otherwise
```

Here, `y` is the function label, `yᵢ` is the label of the line at index `i`, and the index ranges over the lines of `X`. In the formal definition, `1` marks a bug and `0` its absence. The dataset description assigns the opposite numeric values to the before and after versions. The semantic distinction is clear in both places: the before version is treated as buggy, and the after version is treated as clean. The formulas here follow the convention of the formal task definition.

This relationship between the line labels and the function label is a fact about the training targets. The architecture learns the two predictions separately. Its classifier can therefore give a function a low bug probability even if the line-ranking head assigns one of its lines a high score. The same distinction matters for the repair output. Training on examples with an empty target gives the decoder a way to learn to refrain from editing. Its decision still comes from generation, while the detector's decision comes from a separate classification head.

#### Detection reads a representation of the function

For function detection, CodeT5 encodes the marked input. The detection head takes the last encoder state as the representation of the sequence and applies a linear layer to obtain scores for the binary classes. The target is the label attached to the function. Since the label concerns the whole input, the head can use evidence anywhere in the function if that evidence is reflected in the state it reads.

```
Pθ(y | X)
```

Here, `P` denotes the predicted probability, `θ` denotes the parameters of CodeT5 as used for this prediction, `y` is the function's binary label, and `X` is the input function. The vertical bar means the probability is conditioned on the input. The detection loss is standard cross-entropy. In this task it penalizes placing low probability on the function's recorded class. At inference time the paper calls the function buggy when its predicted probability of belonging to that class is higher than 0.5.

The detection decision says whether the function warrants attention. It can be evaluated by counting how often it agrees with the classification labels, including how frequently a repaired version is incorrectly flagged. The threshold makes this a distinct task from line ranking. A ranking has a highest-scoring entry even in the absence of a convincing candidate, while thresholded detection can return a clean judgment for the whole input.

#### Localization reads the line endings

The localization head collects the final-layer states at all `[SEP]` positions and maps them to line probabilities. Because the markers align with source lines, the score associated with a marker is assigned to that line. An example supplies supervision to the lines changed in the fix and to the other lines in the function. With this design, separate lines can receive high scores even when they lie far apart in the input.

```
Pφ(Y | X)
```

Here, `P` expresses the line-label prediction conditioned on the input. `φ` denotes the parameters of the CodeT5 encoder in the paper's localization notation. `Y` denotes the line labels, `X` is the source function, and the vertical bar denotes conditioning. The head gives a probability for each line. The paper denotes the vector of probabilities by `Ŷ`, with an entry `ŷᵢ` for each line index `i`. Training applies binary cross-entropy between those probabilities and their corresponding labels in `Y`. That supervision rewards the head for giving a high probability to a labeled buggy line and a low probability to a labeled clean line.

At evaluation time the authors order the lines by score and retrieve the top `k`, where `k` is the number of positions the evaluator considers. A caller can inspect the strongest candidate first or inspect a longer list. The appropriate measure depends on what the target contains. In the Java benchmark, the evaluator wants to find a specific line. In the Python benchmark, it wants to find several relevant lines and bring them toward the top of the ranking. These different goals explain the use of different ranking metrics across the benchmarks.

#### Repair writes a candidate fixed function

The repair objective treats the transformation as sequence generation. The encoder reads the source function, and the decoder predicts the tokens of the fixed function in order. The decoder's prediction for a later token can depend on the target prefix. This lets the generation procedure use both the original function and the choices already made in the candidate output. The repair target is the whole corrected function. Even a fix that changes one part of one line requires the generator to preserve the remaining code if it is to match the reference.

```
Pθ(F | X) = ∏ⱼ₌₁ⁿ Pθ(Fⱼ | X, F₁:ⱼ₋₁)
```

Here, `Pθ` is the probability assigned by the CodeT5 parameters `θ`. `F` is the target function and `X` is the source function. The product symbol `∏` combines the conditional probabilities for the target positions, indexed by `j` from `1` through `n`, where `n` is the target length in tokens. `Fⱼ` is the token at position `j`. `F₁:ⱼ₋₁` denotes the prefix that precedes it, which is empty at the first position. The vertical bar again means conditioning. The formula uses `Fⱼ` for the current target token to distinguish it from `Y`, which denotes line labels.

The paper uses a standard sequence generation loss for training. At inference it uses beam search, which retains a set of promising partial outputs as decoding proceeds and yields a ranked list of candidate fixes. A candidate's position in that list reflects the sequence score from the generator. The paper evaluates the candidate code against the recorded corrected function. The generation process as described has the encoded source as input. It gives no separate input slot to the line-ranking head's predictions.

This matters for understanding how localization can help repair in the framework. A benefit from localization supervision can appear through the shared encoder. The encoder learns to represent cues useful for recognizing suspect statements, and those representations are also available to the decoder. The architecture does not require a downstream edit to be restricted to a particular line. That flexibility suits a training target that can contain changes at several locations, and it leaves open the possibility of editing a line the locator ranked low.

#### The shared training objective

CodeT5-DLR adds the losses together during adaptation. The classification and localization heads put pressure on the encoder to represent evidence relevant to their targets. The generation objective trains the encoder and decoder to support the conversion from source to corrected function. Sharing the encoder provides a mechanism for the supervision from different targets to affect subsequent predictions.

```
ℒall = ℒdetect + ℒlocalize + ℒrepair
```

Here, `ℒ` denotes a training loss. The subscript `all` refers to the objective optimized by CodeT5-DLR, `detect` refers to the cross-entropy on the function label, `localize` refers to the binary cross-entropy on the line labels, and `repair` refers to the generation loss on the target sequence. The plus signs indicate that the paper combines the terms by addition. The paper's equation specifies no separate task weights. Addition also leaves room for the terms to exert different amounts of influence, since their values and gradients can differ.

The design has a corresponding experimental control. CodeT5-D learns through the detection loss alone, CodeT5-L through the localization loss alone, and CodeT5-R through the repair loss alone. These variants give the authors a comparison with the same starting architecture under narrower supervision. The comparisons test the value of the combined objective as a package. Additional combinations would be needed to isolate what each auxiliary loss contributes to each output.

#### Turning repository changes into supervision

The data pipeline begins with the history of a GitHub repository. The authors use PyDriller to obtain changes, including a file before the commit, the file afterwards, and the patch describing the difference. They use words in commit messages to identify probable bug fixes. The list includes terms such as *defect*, *mistake*, *fault*, and *fix*. The authors cite earlier checks of that rule that reported 96% accuracy on 300 manually verified commits and 97.6% on 384 manually verified commits. Those figures concern the commit selection heuristic in the cited checks.

A file patch contains line changes, but the training input is a complete function. The authors use Lizard to extract functions from both versions of a source file and compare the versions. This associates the affected lines with a before function and an after function. The resulting example retains the location information for training the locator and the full paired code for training the repair generator. It also stores the project name, commit identifier, and commit message, which let readers trace the change back to its repository history.

For SL-Java, the authors also use tree-sitter to assign 13 patterns to the single-line edits. Substituting an identifier, changing an operand, and changing the called method are examples of what such a category can describe. These tags support analysis of the results by edit type. The debugging objective requires identifying a suspect line and generating the corrected code. It has no pattern-classification head. The authors present CodeT5-DLR as an adaptation of the released CodeT5 implementation and say that the collected SL-Java and ML-Python data are to be made available for further research.

The training target depends on which output is under supervision. For detection, both versions supply function inputs with their respective labels. For localization, the defective line numbers supply the labels associated with the separator positions. For repair, the before version is the source for generation and the after version is the reference target. The paper also describes giving the repair component clean inputs, so it can learn when to return an empty repair. The common data source makes it possible to evaluate the same underlying debugging problem from each of these angles.

### Experiments and results

#### Benchmarks and evaluation settings

SL-Java tests single-line fixes in Java, and ML-Python tests multiline fixes in Python. The split statistics count bug-fix instances and projects. In SL-Java, the training split has 52,789 instances from 2,348 projects. Validation has 7,465 instances from 335 projects, and the test split has 15,250 instances from 700 projects. In ML-Python, training has 132,243 instances from 4,428 projects. Validation has 22,395 instances from 480 projects, and testing has 35,457 instances from 867 projects. Since a bug-fix instance contains paired versions, those counts describe the collected instances rather than simply the number of inputs to the detector.

The experiments use CodeT5-base, specified as 220M parameters. The maximum source sequence length and maximum target sequence length are both 512 tokens. This is a limit on encoded length, so the size that matters is the tokenized function, including the inserted separators in the source. The authors report running the experiments on NVIDIA A100 GPUs with 40 GB of memory. The detection, localization, and repair evaluations use distinct metrics because their outputs answer different questions.

There are also separate choices about which inputs to score. The isolated evaluations give each task its appropriate benchmark input. The combined procedure starts with classification of test functions and then continues on the subset flagged by the detector. That subset can contain both defective and repaired functions and can omit genuinely defective functions. The combined scores therefore refer to what happens after a selection decision, while the standalone scores refer to their respective task evaluations.

#### Detecting buggy functions

The detection evaluation reports F1 and false positive rate, abbreviated FPR. F1 combines precision and recall. Precision asks how many of the functions flagged as buggy were labeled buggy. Recall asks how many of the labeled buggy functions were flagged. F1 gives credit for doing well on both. FPR asks a different question. It measures how frequently a function labeled clean gets flagged. Its denominator consists of clean functions, so it is useful for tracking review effort spent on false alarms.

```
FPR = FP ÷ (FP + TN)
```

Here, `FPR` is the false positive rate, `FP` is the count of clean functions incorrectly flagged in the detection evaluation, and `TN` is the count of clean functions correctly left unflagged. Addition gives the full count of clean functions, and `÷` denotes division. The same definition applies at line level with counts of lines, where a clean line is flagged if it appears in the retrieved set.

The detection comparison covers methods that represent code in different ways. The tree-based convolutional classifier, TBCNN, serves as an established code classification approach. SpotBugs gives the Java evaluation a static-analysis baseline. The authors also adapt public checkpoints for CodeBERT, GraphCodeBERT, and PLBART to the classification task. The CodeT5 variants allow a narrower comparison between a detector trained directly for this job, a generator whose empty or nonempty output can be read as a bug signal, and the jointly trained framework. The paper presents PLBART as a pretrained approach to program understanding and generation. [Unified Pre-training for Program Understanding and Generation](https://md.research.elamur.ai/free/en/papers/ahmad-2021-unified-pre-training-program-understanding/)

Function detection F1 on the SL-Java test split Joint training gives CodeT5-DLR the highest F1 among the reported systems.

**The numbers**

| System or setting | F1 |
| --- | --- |
| SpotBugs | 4.6 |
| TBCNN | 45.49 |
| CodeBERT | 55.67 |
| GraphCodeBERT | 56.44 |
| PLBART | 59.01 |
| CodeT5-R | 50.94 |
| CodeT5-D | 59.28 |
| CodeT5-DLR (this paper) | 63.46 |

On the SL-Java test split, CodeT5-D has an F1 of 59.28 and an FPR of 34.32. CodeT5-DLR raises F1 to 63.46 and lowers FPR to 31.24. PLBART, the strongest of the listed external baselines on Java F1, reports 59.01 on F1 and 35.21 on FPR. SpotBugs gives an F1 of 4.6 on this set. That score belongs to a particular benchmark built around functions with single-line fixes, so its meaning is tied to the defects and labels represented there.

On the ML-Python test split, CodeT5-DLR gives an F1 of 54.83 and an FPR of 43.21. The detection-only CodeT5-D gives 52.93 and 46.45 on those metrics. The table has no SpotBugs result for ML-Python. For both benchmarks, the joint result improves the reported tradeoff at the evaluated threshold relative to direct detection-only training. The remaining false positive rates also show why a classifier on this task still needs to be considered in terms of the volume of warnings it produces.

#### Ranking lines within a function

The line-ranking evaluation treats a source function as a collection of lines to search. The method returns the highest-scoring lines, and the evaluator checks where the labeled buggy lines occur. The cutoffs are `k = 1` and `k = 5`. A short list tests how often the strongest prediction is immediately useful. The longer list gives a developer more candidates to examine and the method more room to put a relevant line within reach. This framing comes from [information retrieval](https://md.research.elamur.ai/free/en/topics/information-retrieval/).

The Java measure is mean reciprocal rank, abbreviated MRR. For a function with a single target line, reciprocal rank rewards finding the target earlier in the list. A target outside the evaluated cutoff makes no contribution for that input. The mean combines these results across functions. The Python measure is mean average precision, abbreviated MAP. It can reward retrieving several labeled lines early because average precision takes account of the relevant entries encountered throughout the ranking. In both datasets the authors also report FPR at the chosen cutoff. This measures the share of labeled clean lines that are included in the returned list.

The comparison uses CodeBERT, GraphCodeBERT, and PLBART alongside the CodeT5 variants. It also adapts DeepLineDP and LineVul to the localization problem. These two approaches first make predictions at function level and then use attention scores to derive line scores. DeepLineDP organizes its representation around functions, lines, and tokens using a hierarchical attention design. LineVul aggregates token attention scores for each line. The comparison gives the experiment alternatives that obtain line-level information from function-level prediction, as well as CodeT5-DLR's method of explicitly supervising the line scores. [Hierarchical Attention Networks for Document Classification](https://md.research.elamur.ai/free/en/papers/yang-2016-hierarchical-attention-networks-document-classification/) · [Transformer and attention](https://md.research.elamur.ai/free/en/concepts/transformer/)

Line localization MRR@5 on the SL-Java test split Jointly trained CodeT5-DLR places the defective line higher than the localization-only system on this ranking measure.

**The numbers**

| System or setting | MRR@5 |
| --- | --- |
| DeepLineDP | 15.33 |
| LineVul | 16.79 |
| CodeBERT | 29.69 |
| GraphCodeBERT | 28.45 |
| PLBART | 30.98 |
| CodeT5-L | 32.01 |
| CodeT5-DLR (this paper) | 34.67 |

For CodeT5-DLR on the SL-Java test split, MRR@1 is 26.78 and MRR@5 is 34.67. Its corresponding FPR values are 3.04 at the shorter cutoff and 8.05 at the longer cutoff. CodeT5-L gives an MRR@1 of 24.40 and an MRR@5 of 32.01. Its FPR values are 7.33 and 10.39. On these rows, joint training improves the ranking and reduces the share of clean lines retrieved at each cutoff. The table also contains a Java row labeled CodeT5-DLR-new, with 27.67 on MRR@1 and 38.38 on MRR@5. The paper does not specify the change behind this row, so the chart uses the configurations defined for the main comparison.

On the ML-Python test split, CodeT5-DLR reports MAP@1 of 26.98 and MAP@5 of 33.75. At those cutoffs its FPR is 9.84 and 38.46, respectively. CodeT5-L reports MAP@1 of 24.59 and MAP@5 of 32.40, with FPR of 13.67 and 42.44. The results show the two effects of expanding the list within this task. A longer list makes more of the labeled lines available to inspect, and it selects a greater share of the clean lines as well. MAP and FPR together describe that exchange. The difference in ranking metrics means the Java and Python column values answer different retrieval questions.

#### Generating the patched function

The repair evaluation uses exact match and BLEU. Exact match requires the generated function to agree with the reference function as scored. It puts the same all-or-nothing requirement on a candidate that changes the wrong expression and one that gets the intended edit right but also changes unrelated text.

```
EM = 1 if F̂ = F, and EM = 0 otherwise
```

Here, `EM` is exact match for an individual prediction, `F̂` is the generated function, and `F` is the recorded target. The equality between the functions denotes an exact match. The outcomes `1` and `0` record whether the prediction meets that condition. BLEU gives a score based on overlap between candidate and reference text, so it can credit partially matching output. This provides information about resemblance that exact match leaves unresolved. [BLEU score](https://md.research.elamur.ai/free/en/concepts/bleu/)

The authors fine-tune CodeBERT, GraphCodeBERT, and PLBART with the repair objective for this comparison. CodeT5-R supplies the single-task comparison from the same starting system as the jointly trained CodeT5-DLR. The input is the defective version of the function, and the result is scored against the version recorded after the fix.

Program repair exact match on the SL-Java test split CodeT5-DLR reproduces the recorded corrected function most often in the reported Java comparison.

**The numbers**

| System or setting | Exact match |
| --- | --- |
| CodeBERT | 3.66 |
| GraphCodeBERT | 3.35 |
| PLBART | 6.02 |
| CodeT5-R | 7.30 |
| CodeT5-DLR (this paper) | 10.30 |

On the SL-Java test split, CodeT5-DLR's exact-match score of 10.30 comes with a BLEU score of 43.42. CodeT5-R gives 7.30 on exact match and 40.20 on BLEU. Among the external approaches, PLBART reports 6.02 and 40.12. On the ML-Python test split, the joint system gives 6.30 on exact match and 38.44 on BLEU, while CodeT5-R gives 6.01 and 35.54. The two metrics favor the same training configuration in both datasets. The separation between them also shows what each measure credits. A generated function can gain overlap with the reference without becoming an exact reproduction.

The authors interpret the lower exact-match scores on ML-Python in light of the need to repair several lines in an example. Exact match is demanding in that setting because all of the required edits have to appear in the same output. The two datasets differ in language and collection as well as in the number of labeled lines. The observed performance belongs to those full benchmark settings.

#### Running detection, localization, and repair together

In the combined procedure, the function detector first screens the test functions, including clean ones. The locator ranks lines in the flagged subset. The repair generator supplies candidate fixed functions for that same subset. The paper scores the rankings and generated code and compares them with the outputs of the single-task localization and repair variants used in the same debugging sequence. It says it found no external system that performed the same complete procedure in the form required for this comparison.

On SL-Java, the combined procedure reports a localization MRR@5 of 33.93 for CodeT5-DLR and 28.58 for CodeT5-L. On the repair side, its BLEU is 46.93, compared with 43.20 for CodeT5-R. On ML-Python, the localization entries are 28.49 for CodeT5-DLR and 24.59 for CodeT5-L. The localization column caption names MRR@5 for this comparison, whereas the paper uses MAP for the standalone Python ranking experiment. The combined Python repair entries are BLEU of 41.21 for CodeT5-DLR and 38.50 for CodeT5-R.

The combined scores inherit the detector's selection. A buggy function the detector misses never reaches localization or repair. Conversely, a false alarm can send a clean function to both heads. This setup describes the performance of those heads on inputs selected by a detector. The Java BLEU of 46.93 measures similarity to references within that procedure. An end-to-end rate of correctly repaired functions would require a different measure that follows every input through detection and repair.

### What the ablations show

#### Comparing shared training with one task at a time

The main ablation holds the CodeT5 starting point in common and changes the objectives used for adaptation. CodeT5-D is trained for function classification. CodeT5-L is trained for ranking lines. CodeT5-R is trained to generate repaired functions. Each variant gives the authors a test of how far direct supervision for a task can take the starting system. CodeT5-DLR gives the corresponding result when training also includes supervision from the other debugging tasks.

The detection comparison is informative because the gains show up in both measures the paper cares about. CodeT5-DLR improves on CodeT5-D in test F1 and FPR on SL-Java and ML-Python. The higher F1 is accompanied by a smaller share of clean examples flagged at the decision threshold. On Java, the repair-only variant's F1 of 50.94 is also lower than the detection-only variant's 59.28. An empty or nonempty repair output carries some information about whether a function is defective, and the comparison shows the value of a dedicated detection loss for the evaluated function decisions.

The localization comparison examines whether the related objectives help rank lines once the system has direct labels for them. CodeT5-DLR improves on CodeT5-L at both list lengths in both datasets. It also reduces false positives at the listed cutoffs. A gain in MRR on Java means the annotated line tends to be placed nearer the top or recovered within the cutoff more often. A gain in MAP on Python concerns the ordering of several labeled lines. The results support shared training for both forms of localization, even though the benchmarks use different definitions of successful ranking.

For repair, adding the classification and localization objectives improves exact match and BLEU over CodeT5-R in both benchmarks. The Java comparison shows a clearer separation in exact match than the Python comparison. Python still shows improved overlap on BLEU. This pattern is consistent with an encoder that becomes more useful to the decoder after receiving line and function supervision. The ablation measures the package of added losses, leaving the magnitude of each loss's individual contribution unresolved.

The combined evaluation extends the comparison to a detection-first setting. The joint system retains its advantage over the single-task variants on the selected inputs. This matters because selecting inputs changes which functions reach the later tasks, including which hard cases and false alarms they see. The experiment supports the use of shared training when the outputs are put into that procedure. It does not independently vary the sequence of inference decisions or use the predicted line as a condition for the decoder, so the contribution of those design choices remains outside this comparison.

#### Outcomes depend on the kind of edit

The Java dataset's pattern labels give the authors a way to ask which edits the detector handles more readily. The labels describe the recorded change. An operand change, an identifier substitution, and a change to a called method each describe a different way a line might have been repaired. The pattern breakdown groups function-level detection outcomes by those labels. It therefore describes recognition of defective functions in each group. Correct classification still leaves localization and generation to their own evaluations.

In this analysis, the paper compares CodeBERT, CodeT5-L, and CodeT5-DLR. It reports that CodeT5-L does better than CodeT5-DLR by an average of 4.1% in the pattern-level F1 analysis and better than CodeBERT by an average of 10.2%. For the examples of edit types identified as P1, P2, and P5, the authors report an average F1 advantage of >14% for CodeT5-DLR over CodeBERT. These are the operand, identifier, and called-method patterns, respectively. The aggregate advantage of joint training is therefore compatible with a more variable result after the Java examples are grouped by edit type.

The pattern distribution also matters when interpreting these comparisons. The authors say identifier changes are the most frequent in the Java data and Boolean literal swaps the least frequent. A number averaged across patterns need not agree with a score evaluated over all functions. The paper reports the pattern averages alongside the overall results, without specifying enough detail to derive one from the other. The dataset discussion names 13 patterns, while the caption of the breakdown refers to 14. The reported averages support the comparison as stated, but the category count is internally inconsistent.

The authors also discuss an alternative line-selection design using a pointer network. They say experiments confirmed that the approach worked poorly in their setting, where there can be many clean lines and clean functions can also be submitted. They provide no numerical comparison for that experiment. Its role in the paper is to explain their choice to score lines separately and rank them. It offers less evidence about the size of the effect than the comparisons that directly remove training objectives.

#### Two cases separate finding from fixing

In a successful example, the system flags a function, ranks the changed line first, and generates the correction that changes the method being called. The authors associate the change with the Java pattern for substituting a call. This case makes the relationship between the three outputs concrete. The function warning gives a reason to look, the line ranking singles out one place, and the generated function contains the replacement from the recorded fix. The example establishes that the complete sequence can succeed on a bug drawn from an actual project.

In another case, the system recognizes the defective function and finds the correct line but proposes the wrong repair. The change in the repository replaces a numeric literal. A system might learn that a number looks unusual in context while having little basis for recovering the particular number the developer intended. A line label resolves where the edit was made, while the generation target specifies the exact replacement. The example exposes the extra information needed by the second judgment. It also shows why a general claim about repair would require evidence beyond a good line-ranking score.

### Limitations

#### Limits identified by the authors

The authors flag inconsistency between the outputs as a central limitation. Joint optimization gives every objective access to a shared representation, but it leaves each head responsible for a distinct prediction. The differences show up when the function classifier returns a clean decision and the decoder produces a repair anyway. The empty-target examples teach the decoder that some inputs should produce no fix. They give it no explicit constraint requiring agreement with the classifier. The authors propose investigating a training procedure in which generation depends on the detector's signal.

Their combined evaluation already uses detection as a gate at inference time. This can hide a disagreement that would be visible if all heads were run on every function because generation is evaluated downstream only for the selected inputs. A training dependency would address a different issue. It would change how the two components learn to interact, whereas the inference gate controls which results a caller receives. The paper shows the latter procedure and identifies the former as future work.

The authors also emphasize the restriction to information within the function. In a repository, a function can depend on other definitions in the file or on code elsewhere in the project. A suspicious call may become easy to explain once its callee or a caller's assumptions are visible. The CodeT5-DLR input contains the function itself with its line separators. Additional program context is left for future investigation. The paper also proposes investigating completion of a missing or broken line as a possible extension to its repair setting.

#### Limits of using commits as labels

The benchmark labels record the before and after of a particular developer change. This gives the experiment real examples and a traceable source for the target. It also raises a question about what the labels establish. The presence of a bug-related word in a commit message makes the commit a candidate fix. An altered function in that commit might include other adjustments, and several changed lines can have different roles in the correction. Conversely, the after version is treated as clean for purposes of the experiment because it follows the recorded repair. This designation is narrower than a claim that all behavior of the function is correct.

The line label has a related scope. It identifies the location associated with the recorded change. The cause of a fault could depend on a definition or earlier computation that the developer chose to leave intact. A developer can also address a problem at one of several locations. Line ranking is therefore tested against the annotation that can be derived from the repository history. Its score measures agreement with that location, which is useful for a benchmark and can differ from agreement with a broader account of the fault.

The cited validation figures for bug-fix keywords describe manual checks in earlier work. The paper gives repository metadata for the new examples and explains the extraction procedure. Those details make the labels traceable. They leave the accuracy of the new function-level pairings and line annotations to be established separately. The project counts in each split likewise describe dataset size. They do not on their own establish whether all evaluation projects are disjoint from training projects or whether closely related functions occur across splits.

Another unresolved question is how much of the difference between the datasets comes from line count. Java supplies the single-line setting and Python supplies the multiline setting. Language, repositories, and the kinds of changes represented can all affect the task. The paper's design compares the framework against each baseline within a benchmark. A controlled estimate of the effect of requiring more changed lines would call for settings in which the other relevant factors are held more almost constant.

#### Limits of the scores and comparisons

Exact match and BLEU evaluate the text of a suggested repair against the text of the recorded one. Exact match can reject an alternative implementation with the same behavior. BLEU can reward a function that preserves much of the reference while keeping the consequential bug. A patch may also change surrounding behavior even when some of its text looks plausible. The paper's repair evaluation uses reference comparisons, so the numerical support concerns target recovery and text overlap. Results for compilation, execution against tests, and preservation of behavior are outside those measures.

The line-ranking measures have a different scope. They indicate how early labeled lines appear, and FPR indicates the share of labeled clean lines included in the shortlist. They leave the actual cost of reviewing the list unmeasured. Going from a shorter list to a longer one makes sense when missing a defective line is costly and inspection is easy. The same choice can increase review work for functions whose lines are hard to interpret. The paper measures ranking behavior and the associated false alarms. It does not measure developer time or the effect of showing these outputs in a real review workflow.

The detector is evaluated at its stated threshold. The FPR and F1 values characterize that operating point on the paper's labeled examples. If the system were used on a collection in which buggy functions occurred with a different frequency, the composition of the warnings could change. The benchmark pairs before and after versions of known changes, which is a useful way to construct both classes. It gives no direct measurement of how many warnings a developer would see when screening the ordinary contents of a repository.

The task-specific baselines also delimit the conclusions. SpotBugs provides one static comparison on SL-Java. DeepLineDP and LineVul were adapted to this evaluation, and the combined procedure compares only variants of CodeT5. These experiments support claims about the tested systems and inputs. A comparison against a workflow that uses test failures, compiler information, or a human-confirmed location would answer a different question. The experiments also cap source and target lengths at 512 tokens. How performance changes with longer functions or with dependencies outside the function remains open.

Finally, some reported entries support a more cautious reading than the surrounding prose suggests. The combined procedure's Java scores are labeled by ranking and overlap metrics in the table, so they are best reported as MRR@5 and BLEU. The combined Python localization label is less clearly reconciled with the standalone use of MAP. The Java localization table's additional CodeT5-DLR-new row has numerical results but lacks a corresponding method definition. These uncertainties affect how those particular numbers can be compared or reproduced. The defined single-objective and joint configurations still provide direct comparisons for the main task results.

### What came after

[When is Tree Search Useful for LLM Planning? It Depends on the Discriminator](https://md.research.elamur.ai/free/en/papers/chen-2024-when-is-tree-search-useful/) cites CodeT5-DLR and poses a question about when tree search helps with planning, identifying the discriminator as a condition in its title. The citation establishes a connection between the works, but the specific use it makes of CodeT5-DLR is unspecified. The title supports a limited thematic comparison. CodeT5-DLR separates judgments about a function and its lines from the generation of a candidate repair. The later work's title puts the value of a procedure for searching possible plans in relation to the component that judges them. Whether the later study adopts any of the debugging objectives, evaluates them, or cites them as background remains open.

## Cite

Cite as Nghi Bui, Yue Wang and Steven C.H. Hoi. 2022. Detect-Localize-Repair: A Unified Framework for Learning to Debug with CodeT5. Findings of the Association for Computational Linguistics: EMNLP 2022.

The paper itself, not this page. BibTeX from the library's record of the work. [DOI 10.18653/v1/2022.findings-emnlp.57](https://doi.org/10.18653/v1/2022.findings-emnlp.57)

```bibtex
@inproceedings{bui2022detect,
  title = {{Detect-Localize-Repair: A Unified Framework for Learning to Debug with CodeT5}},
  author = {Nghi Bui, Yue Wang and Steven C.H. Hoi},
  booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2022},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.57},
  url = {https://doi.org/10.18653/v1/2022.findings-emnlp.57}
}
```

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://research.elamur.ai/sitemap.xml) · [llms.txt](https://research.elamur.ai/llms.txt)
