Source-linked AI summary

CoditT5: Pretraining for Source Code and Natural Language Editing

Jiyang Zhang, Sheena Panthaplackel, Pengyu Nie, Junyi Jessy Li, Milos Gligoric

arXiv:2208.05446v2cs.SEcs.LG

TL;DR

Software-related editing tasks require models to make changes, but generation-oriented pretrained models are not designed to reason explicitly about edits. CoditT5 is pretrained to generate edit plans and target sequences, and outperforms existing models across three editing tasks; reranking with a standard generation model further improves results.

  • Problem

    Generation-oriented pretrained models are not designed to reason about edits, although software tasks such as bug fixing, code review, and comment updating require editing.

    Source: §1 · p. 1
  • Method

    CoditT5 is pretrained to generate an explicit plan of edit operations followed by the edited target sequence.

    Source: §1 · p. 2, §3.1 · p. 4
  • Results

    CoditT5 outperforms state-of-the-art models on comment updating, bug fixing, and automated code review, while reranking it with a standard generation model beats either model individually by up to 19.35%.

    Source: §1 · p. 2
  • Takeaways & Limitations

    Edit-based and standard generation models offer complementary strengths, and simple reranking achieves state-of-the-art performance on the three evaluated editing tasks.

    Source: §1 · p. 2, §8 · p. 10

    The downstream editing tasks studied use Java; performance on editing tasks in other programming languages remains empirically unverified.

    Source: §6 · p. 9

Abstract

from arXiv · show

Pretrained language models have been shown to be effective in many software-related generation tasks; however, they are not well-suited for editing tasks as they are not designed to reason about edits. To address this, we propose a novel pretraining objective which explicitly models edits and use it to build CoditT5, a large language model for software-related editing tasks that is pretrained on large amounts of source code and natural language comments. We fine-tune it on various downstream editing tasks, including comment updating, bug fixing, and automated code review. By outperforming standard generation-based models, we demonstrate the generalizability of our approach and its suitability for editing tasks. We also show how a standard generation model and our edit-based model can complement one another through simple reranking strategies, with which we achieve state-of-the-art performance for the three downstream editing tasks.

1 INTRODUCTION

Generation-oriented models are not explicitly designed to reason about edits, despite editing being central to tasks such as bug fixing, code review, and comment updating. CoditT5 models edit plans before target sequences, and combining it with a standard generation model improves results across three editing tasks.

1 INTRODUCTION

  • Generation models can copy the input without making requested edits or introduce irrelevant changes, because their pretraining objectives do not explicitly model edits.The paper reports copying without edits in up to 34.25% of cases when applying large generation models to editing tasks.Source: §1 · pp. 1–2
  • CoditT5 first generates an explicit plan of edit operations, then generates the target sequence using that plan.The model is pretrained on more than 5.9 million code snippets and 1.6 million natural language comments.Source: §1 · p. 2
  • CoditT5 outperforms state-of-the-art and standard generation models on comment updating, bug fixing, and automated code review.The authors present this cross-task result as evidence that the approach generalizes and suits software editing tasks.Source: §1 · p. 2
  • Combining CoditT5 with a standard generation model through reranking outperforms both models individually by up to 19.35%.The authors attribute the gain to complementary strengths: explicit modeling of edits and contextual coherence.Source: §1 · p. 2

2 BACKGROUND

This background introduces conditional generation and transformer-based models, large pretrained language models and fine-tuning, and pretrained models for software engineering. It notes that existing code models have focused on generation and are only implicitly aware of edit operations.

2 BACKGROUND

  • The background section introduces the building blocks needed to understand the paper's approach.These include transformer-based generation, large pretrained models, and pretrained models for software engineering.Source: §2 · p. 2, §2.1 · p. 2, §2.2 · p. 3

2.1 Generation with Transformer-Based Models

  • Conditional sequence generation produces an output sequence from an input, commonly using an encoder-decoder whose decoder predicts tokens using the input and previously generated tokens.Transformers use attention to relate tokens in a sequence and can serve as the encoder and decoder.Source: §2.1 · pp. 2–3

2.2 Large Pretrained Language Models

  • Large pretrained language models learn from large unlabeled datasets using unsupervised objectives; BART and T5 denoise corrupted inputs, while fine-tuning transfers pretrained knowledge to supervised downstream tasks.Denoising trains a model to reconstruct the original input from a noised version.Source: §2.2 · p. 3

2.3 Large Pretrained Language Models for Software Engineering

  • Software engineering models such as PLBART and CodeT5 support code understanding and generation, but are only implicitly aware of edit operations, if at all.CodeT5 is pretrained on six programming languages and their natural language comments, and is trained to incorporate identifier information.Source: §2.3 · p. 3

3 CODITT5

CoditT5 uses the CodeT5 encoder-decoder architecture and is pretrained to generate an edit-based output from corrupted input. The section outlines the objective, pretraining data, and setup.

3 CODITT5

  • CoditT5 uses the same encoder-decoder architecture as CodeT5.Source: §3 · p. 3
  • The model is pretrained to generate an edit-based output sequence from a corrupted input sequence.Source: §3 · p. 3
  • The section presents the pretraining objective, the data used to build CoditT5, and additional details of the pretraining setup.Source: §3 · p. 3

3.1 Pretraining Objective

The pretraining objective trains the model to denoise corrupted inputs by first generating an explicit edit plan and then the reconstructed target sequence. Multiple noising functions expose it to insertion, deletion, and replacement edits.

3.1 Pretraining Objective

  • The model denoises corrupted inputs by generating an edit plan followed by the target sequence that reconstructs the original input.The edit-based output representation separates the plan from the target with a separation token.Source: §3.1 · pp. 3–4

3.1.1 Edit Plan.

  • Edit plans specify operations for reconstructing the input; difflib determines the operations and orders them by the edited spans’ positions.The plan can include Insert, Delete, and Replace operations.Source: §3.1.1 · p. 4

3.1.2 Target Sequence.

  • Because edit plans are fragmented and some operations lack deterministic locations, the model also generates the target sequence to maintain fluency and coherency.The decoder can use the earlier plan while generating the target sequence left to right.Source: §3.1.2 · p. 4

3.1.3 Noising Functions.

  • Pretraining corrupts inputs by masking spans, inserting masks, or deleting spans, requiring replacement, deletion, or insertion edits during denoising.Source: §3.1.3 · p. 4

3.2 Pretraining Data

CoditT5 is pretrained on source code and natural-language comments from CodeSearchNet. Its corruption process is calibrated to downstream edit statistics, and sequences outside the 3–512-token range are removed.

3.2.1 Data Collection.

  • CodeSearchNet provides six programming languages and natural-language comments; the processed training set contains 6.1 million code snippets and 1.9 million comments.Source: §3.2.1 · p. 4

3.2.2 Data Preparation.

  • Pretraining edit-operation probabilities and corrupted-span lengths are set to reflect distributions and sizes of real-world downstream edits.Source: §3.2.2 · pp. 4–5
  • The authors estimate operation probabilities, edited-span token counts, and edited spans per input from bug-fixing, code-review, and comment-updating training sets, then sample edits accordingly.Source: §3.2.2 · p. 5
  • After tokenization, sequences shorter than 3 or longer than 512 tokens are removed, leaving 5.9 million code snippets and 1.6 million comments.Source: §3.2.2 · p. 5

3.3 Pretraining Setup

CoditT5 is a 223M-parameter model initialized from CodeT5-base and further pretrained on CodeSearchNet using the proposed objective.

  • CoditT5 has 12 encoder and decoder layers, 12 attention heads, a hidden dimension of 768, and 223M parameters.Source: §3.3 · p. 5
  • The model parameters are initialized from CodeT5-base before further pretraining on CodeSearchNet with the proposed objective.Source: §3.3 · p. 5
  • Pretraining runs for four days on 16 Nvidia 1080-TI GPUs; fine-tuning uses four such GPUs and CodeT5’s hyperparameters.Source: §3.3 · p. 5

4 EXPERIMENTAL DESIGN

The experimental design fine-tunes CoditT5 on comment updating, bug fixing, and automated code review, using edit-based outputs during training and target sequences at test time. It compares against generation-based and task-specific baselines using task-appropriate metrics.

4 EXPERIMENTAL DESIGN

  • At fine-tuning, CoditT5 generates an edit plan followed by a target sequence; at test time, the plan is discarded and the sequence after <s> is used as the prediction.Source: §4 · p. 5

4.1 Downstream Tasks

  • The three tasks are updating comments to reflect code changes, fixing buggy code, and revising code to implement review recommendations.Source: §4.1 · p. 5

4.2 Data for Downstream Tasks

  • Downstream datasets pair Java method changes with comments, buggy code with guidance and context, or pre-review code with pull-request comments.For comment updating, the input combines the old comment and code edits; bug-fixing inputs include buggy code, guidance, and context; review inputs combine code and reviewer comment.Source: §4.2 · p. 6

4.3.1 Generation Baselines.

  • Generation baselines PLBART and CodeT5 directly generate targets, while a CodeT5 variant generates the specialized edit-based output representation.Source: §4.3.1 · p. 6

4.3.2 Task-Specific Baselines.

  • Task-specific baselines include prior models for comment updating and bug fixing; no baseline was available for the concrete-token code-review dataset, so new baselines were established.Source: §4.3.2 · p. 6

4.4 Evaluation Metrics

  • Comment updating is evaluated with xMatch, BLEU-4, METEOR, GLEU, and SARI; bug fixing with xMatch; and code review with xMatch and BLEU-4.Source: §4.4 · p. 6

5 EVALUATION

The evaluation compares CoditT5 with editing and generation baselines, tests whether edit-based pretraining supports edit reasoning, and assesses reranking with CodeT5.

5.1 Comparing CoditT5 to Baselines

  • Across all three tasks, CoditT5 outperforms PLBART and CodeT5, significantly on most metrics; it also beats CodeT5 with edit-based output on most metrics.CodeT5 with edit-based output outperforms standard CodeT5 on xMatch and SARI; CoditT5 still exceeds it on most metrics.Source: §5.1 · p. 7, Table 5 · p. 7, Table 6 · p. 7

5.2 Evaluating our Pretraining Objective

  • CoditT5 copies input content less often than PLBART and CodeT5, and its target sequence matches its edit plan in 74%–92% of cases.The target decoder is not constrained to follow the plan.Source: §5.2 · p. 8, Table 9 · p. 8
  • Even with ambiguous or erroneous edit plans, CoditT5 can produce correct target sequences by disambiguating or disregarding unreasonable edits; both plan and target sequence matter.Figure 4 illustrates examples from automated code review.Source: §5.2 · p. 8, Figure 4 · p. 8

5.3 Integrating CoditT5 and CodeT5

  • CoditT5 performs better than CodeT5 on xMatch, and on SARI for comment updating, but worse on BLEU-4, reflecting a trade-off between edit accuracy and generation metrics.This motivates incorporating CodeT5 into the approach.Source: §5.3 · p. 8

5.3.1 Experimental Setup.

  • At test time, each model generates 20 candidates with beam search, and likelihood-based scores rerank candidates without additional training.The strategies use CodeT5 to score CoditT5 candidates or CoditT5 to score CodeT5 candidates.Source: §5.3.1 · p. 9

5.3.2 Results.

  • CodeT5 reranking improves CoditT5 on all metrics across tasks, while CoditT5 reranking improves CodeT5 on edit-focused metrics, including xMatch and GLEU and SARI for comment updating.CodeT5 likelihood can filter a defective CoditT5 prediction; CoditT5 reranking can disfavor a copied comment that misses code changes.Source: §5.3.2 · p. 9
  • Reranking CoditT5 and CodeT5 improves performance across most metrics for all three tasks, outperforming either model individually and achieving new state-of-the-art results.The three tasks are comment updating, bug fixing, and automated code review.Source: §5.3.2 · p. 9

6 LIMITATIONS

The evaluation is limited to Java editing tasks, and potential overlap between pretraining data and downstream test examples remains unexamined.

6 LIMITATIONS

  • The studied downstream editing tasks use Java; transfer to other programming languages is expected from six-language pretraining but remains empirically unverified.The authors leave evaluation on other languages to future work.Source: §6 · p. 9
  • Because CoditT5 uses open-source-project data, similar examples may occur in downstream test sets; the impact of such contamination remains for future study.Source: §6 · p. 9

7 RELATED WORK

Related work spans explicit edit representations, pretrained code models, and methods that combine complementary models; the paper distinguishes its pretraining approach from these lines.

Learning Edits

  • Prior work represents edits as token-level actions or AST-node actions, while this paper uses token sequences to support natural-language generalization and compatibility with pretrained models.The authors state that AST editing does not generalize to natural language and is not easily combined with large pretrained models.Source: §7 · p. 10
  • Edit embeddings have been used in task-specific systems, but the authors argue that domain gaps across tasks limit their use in pretraining and fine-tuning, and that explicit edits are more explainable.Source: §7 · p. 10
  • Copying and pointer-based editing approaches preserve unchanged content or identify edit locations, which the authors describe as orthogonal to their edit-focused pretraining.The cited approaches include copy tokens, reference tokens, and pointers to input positions.Source: §7 · p. 10

Pretrained Models for Code Edits; Combining Complementary Models

  • Prior code-edit systems adapt pretrained models or train on task-specific data, while this work combines an edit-pretrained model with a standard generator through reranking.The paper contrasts reranking with ensembling, which it says requires additional training.Source: §7 · p. 10

8 CONCLUSION

The conclusion presents CoditT5 as an edit-pretrained model evaluated on three software-editing tasks and reports that reranking it with a generation model achieves state-of-the-art results.

8 CONCLUSION

  • The paper introduces an edit-driven pretraining objective and CoditT5, pretrained on source code and natural-language comments for software-related editing.Source: §8 · p. 10
  • Fine-tuned on comment updating, bug fixing, and automated code review, CoditT5 outperforms task-specific and pure-generation baselines across tasks.The authors present this as evidence of suitability for editing tasks and generalizability across the evaluated tasks.Source: §8 · p. 10
  • Simple reranking combines CoditT5 with a pure generation model, outperforming each model individually and achieving state-of-the-art performance on the three evaluated tasks.Source: §8 · p. 10
Loading 2208.05446v2…