Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation

CodeT5 pre-trains one encoder-decoder on code using identifier-aware tasks

  • Problem Encoder-only and decoder-only pre-trained models each cover only part of code tasks, and most code pre-training treats source code as plain tokens, ignoring its identifiers.
  • Method CodeT5 is a T5-style encoder-decoder that learns to recover masked spans and identifiers, and to tag which tokens are identifiers. It then fine-tunes one shared model across understanding and generation tasks.
  • Results CodeT5-base reaches 19.55 smoothed BLEU-4 on code summarization, against 18.32 for PLBART, and 43.20 CodeBLEU on Concode.

Why one model has to cover both roles

Pre-training recipes carried over from natural language to code have mostly taken one of two shapes. Encoder-only models such as CodeBERT suit understanding, but a generation task needs an extra decoder that never receives pre-training. Decoder-only models go the other way, leaving understanding tasks at a disadvantage.

A second gap concerns the input side. Most methods feed code to the model as an ordinary token sequence, much as they would prose, which discards structure that bears on meaning. Identifiers are a natural target for this. A developer picks a name such as binarySearch to say what a function does, so the name carries semantics that a generic token sequence hides.

Input format and identifier labels

CodeT5 keeps the T5 architecture and changes what enters the encoder. A snippet with no accompanying comment enters as program tokens alone. When a comment is available, the sequence starts with a [CLS] token, the natural-language words come next, and a [SEP] token separates them from the code, which ends with another [SEP].

The labels for the code segment come from an Abstract Syntax Tree. The code is parsed, the node type of each token is read, and a token receives 1 when it is an identifier and 0 otherwise. Function names and variables are the identifier types that the paper singles out, since they are among the most language-agnostic features of code.

Identifier-aware denoising pre-training

The first objective is masked span prediction. It corrupts the input by hiding random spans, and the decoder writes them back using sentinel tokens. Span lengths are drawn uniformly from 1 to 5 tokens, and the corruption rate is 15%, the same as in T5. This gives an average span length of 3. Spans are sampled before subword tokenization, so whole words are masked rather than fragments of them.

The loss sums, over the k tokens of the masked output, the negative log-likelihood of each token given the corrupted input and the earlier tokens of the target. \[ \mathcal{L}_{MSP}(\theta)=\sum_{t=1}^{k}-\log P_\theta\left(x^{\text{mask}}_t \mid x^{\backslash \text{mask}},\; x^{\text{mask}}_{<t}\right) \] Here theta denotes all model parameters, x^{\backslash mask} is the corrupted input, and x^{mask}_{<t} is the span text generated so far.

Identifier tagging adds a sequence-labelling loss on the encoder. The final encoder state of each code token is mapped to a probability p_i that the token is an identifier. The loss is a binary cross-entropy summed over all m code tokens, with label y_i, and it is minimized over the encoder parameters theta_e. \[ \mathcal{L}_{IT}(\theta_e)=\sum_{i=1}^{m}-\left[y_i\log p_i+(1-y_i)\log(1-p_i)\right] \] Because every token must be classified, the encoder is pushed to pick up the syntax and the data-flow structure of the code.

Masked identifier prediction works in the opposite way. Every identifier in the code is masked, and all occurrences of one identifier share one unique sentinel. The decoder writes the sentinels together with their identifiers as an ordered target sequence I, and predicts it one step at a time. \[ \mathcal{L}_{MIP}(\theta)=\sum_{j=1}^{|I|}-\log P_\theta\left(I_j \mid x^{\backslash I},\; I_{<j}\right) \] Here x^{\backslash I} is the input with its identifiers masked.

The authors call this deobfuscation and treat it as harder than span recovery, because the decoder must link the occurrences of the same identifier together.

The three losses are optimized in alternation, each chosen with equal probability, and together they form the identifier-aware denoising stage.

Bimodal dual generation

The denoising stage trains the decoder mostly on masked spans and identifier sequences, whereas downstream tasks need fluent natural language or syntactically valid code from it. Bimodal dual generation is meant to narrow that gap by training the model on NL-PL pairs in both directions.

Each NL-PL pair yields two training instances, one for NL-to-PL and one for PL-to-NL, and each instance carries a language id such as java or en. The authors describe this as a special case of span masking, in which either the whole NL segment or the whole PL segment is masked.

Adapting one model to downstream tasks

Generation tasks use the sequence-to-sequence interface directly. For understanding tasks, the label is generated as a unigram target sequence, or a class is predicted from a vocabulary of labels using the last decoder hidden state.

Multi-task learning trains one shared model on several tasks at a time. No task-specific network is added, and a control prefix in the source input tells the model which task it is handling, such as translating Java to CSharp.

Because the task datasets differ widely in size, tasks are sampled with probabilities q_i derived from the share of data each task holds. \[ q_i=\frac{r_i^{\alpha}}{\sum_{j=1}^{N} r_j^{\alpha}},\qquad r_i=\frac{n_i}{\sum_{k=1}^{N} n_k} \] Here n_i is the number of examples for the i-th task and alpha is set to 0.7. Because alpha is below one, the large tasks are sampled less than their raw share, which reduces the bias toward high-resource tasks.

Pre-training corpus, tokenizer and model sizes

The corpus is CodeSearchNet, with unimodal and bimodal data for six programming languages, plus C and C# code gathered from BigQuery. In total the pre-training set has around 8.35 million instances. Identifier rates differ by language. Go has the lowest share of identifiers over all code tokens, at 19%, and Ruby the highest, at 32%.

The tokenizer is a byte-level BPE with a vocabulary of 32,000, trained on the pre-training data, with special tokens such as [PAD], [CLS], [SEP] and [MASK0] through [MASK99] added. Compared with T5's default tokenizer, it shortens tokenized code sequences by 30% to 45% on downstream tasks, and the default tokenizer maps common brackets to unknown tokens.

The denoising stage runs for 100 epochs and dual training for a further 50 epochs on 16 NVIDIA A100 GPUs. Total training takes 5 days for CodeT5-small and 12 days for CodeT5-base.

Code summarization results

Smoothed BLEU-4 is averaged over six languages. CodeT5-base reaches 19.55 overall, against 18.32 for PLBART, and CodeT5-small reaches 19.14. The base model is over 1.2 absolute points above PLBART on this average.

Encoder-only baselines sit lower, at 16.57 for RoBERTa and 17.83 for CodeBERT overall. The authors read this gap as showing that encoder-only frameworks are suboptimal for generation.

Dual generation and multi-task variants of CodeT5-base reach 19.75 and 19.77 overall, respectively.

Concode code generation results

The CodeBLEU gap to PLBART is around 4.7 points. CodeT5-small, at 41.39 CodeBLEU, is also above PLBART. The authors attribute the CodeBLEU gain to identifier-aware pre-training, which they argue helps the model handle code syntax and semantics.

The variants do not move the same way. Adding bimodal dual generation raises the base model's CodeBLEU to 44.10, while multi-task fine-tuning lowers it to 40.01.

Code translation and refinement results

One C# to Java output is semantically correct and reads more cleanly than the reference, yet it gets a 50.23% BLEU-4 score, so the authors use it to argue that BLEU is an imperfect metric for generation.

Refinement is judged by exact match, because copying the buggy input already yields high BLEU, 78.06 on small and 90.91 on medium, with zero exact matches. On the medium set, CodeT5-base reaches 13.96 EM, against 9.10 for GraphCodeBERT and 8.98 for PLBART. On the small set it reaches 21.61 EM, against 19.21 for PLBART.

Defect and clone detection results

Defect detection is scored by accuracy. CodeT5-base reaches 65.78, against 63.18 for PLBART and 61.05 for RoBERTa, and CodeT5-small reaches 63.40. The defect label is generated as a unigram target sequence by the decoder.

Clone detection uses the sequence embedding from the last decoder state, and the labels are predicted by measuring similarity. The base model reaches an F1 of 97.2, equal to PLBART and above GraphCodeBERT's 97.1.

The authors take these results as showing that an encoder-decoder can be adapted to understanding tasks. For the base model, the dual generation variant lowers defect accuracy to 62.88.

Which identifier-aware objectives carry the gain

The ablation trains CodeT5-small with one objective removed at a time and evaluates four tasks. Without masked span prediction, code generation CodeBLEU falls from 41.39 to 37.44, and summarization BLEU on Python falls from 20.04 to 18.93. Lower scores here mean the removed objective was contributing, since CodeBLEU and BLEU are higher-is-better metrics.

The same removal raises defect detection accuracy from 63.40 to 64.02, which runs against the generation trend. The authors read this as masked span prediction being more important for syntax in generation, and they note that it is the other way round for defect detection.

Without masked identifier prediction, defect detection accuracy drops to 62.92 from 63.40, and the authors tie this to a stronger role in semantic understanding. Removing identifier tagging gives refinement EM of 18.65 against 19.06 for the full model.

In a code generation example on Concode, the full model reproduces the target function, while the variant without masked identifier prediction and identifier tagging fails to recover the identifiers s2 and hasField.

Checking how the two masking tasks interact

Identifier tagging reaches over 99% F1 on every language, which the authors take as evidence that the encoder separates identifiers reliably. Masked span prediction and masked identifier prediction share sentinel tokens, which could conflict, because identifier masking maps many occurrences to one sentinel while span prediction maps one span to one sentinel.

Pre-training on masked span prediction alone gives 50.13 accuracy on that task and 2.94 on identifier prediction. Masked identifier prediction alone gives 42.75 on identifier prediction and 1.68 on span prediction. Combining the two gives 48.26 on masked span prediction and 42.72 on masked identifier prediction.

The authors find that identifier-only pre-training recovers the right number of predictions on the span task more readily than span-only pre-training does on the identifier task, which they read as moving from many-to-one to one-to-one mapping being easier. They present the combined model as a trade-off between the two tasks.

Limitations

BLEU is an imperfect guide for generation in this work. A semantically correct translation can score 50.23% BLEU-4, and the authors note that a high BLEU can instead reflect copying.

Bimodal dual generation helps the NL-PL tasks but does not help PL-PL generation and understanding, and it sometimes slightly hurts them. The authors suspect the objective pulls the model toward PL-NL tasks. With dual generation, base defect accuracy falls from 65.78 to 62.88.

Multi-task learning does not improve code translation or defect detection, and for the base model it lowers CodeBLEU on Concode from 43.20 to 40.01 and defect accuracy from 65.78 to 65.02. Clone detection was excluded from multi-task learning.

The experiments cover two model sizes, 60M and 220M. Baseline numbers are taken from the original papers and the CodeXGLUE paper rather than from reruns under one protocol.

The authors also flag dataset bias from comments and identifiers, automation bias when developers over-trust generated code, and possible leakage of sensitive information from the training data.

Paper info

Authors
Yue Wang, Weishi Wang, Shafiq Joty, Steven C. H. Hoi
Venue
arXiv · Preprint
First published
2021-9-2
Added
2026-11-12
Updated
2021-9-2
Version
v1
arXiv
2109.00859
Category
cs.CL · cs.PL
Original paper terms
CC BY-NC-SA 4.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Yue Wang, Weishi Wang, Shafiq Joty, Steven C. H. Hoi (2021). CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation. arXiv:2109.00859v1. https://arxiv.org/abs/2109.00859v1

BibTeX
@misc{wang2021codet5,
  title = {{CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation}},
  author = {Yue Wang and Weishi Wang and Shafiq Joty and Steven C. H. Hoi},
  year = {2021},
  eprint = {2109.00859},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.00859v1}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up