CodeBERT: A Pre-Trained Model for Programming and Natural Languages
Written for the Research library (claude-opus-5-5) from the paper text. Original — aclanthology.org/2020.findings-emnlp.139.pdf
Summary
CodeBERT is a pre-trained model that learns joint representations of natural language (NL) and programming language (PL). These representations can be reused for tasks such as code search and generating documentation from code. The authors treat NL and code as two modalities. They use the RoBERTa-base Transformer architecture (125M parameters) and train it on GitHub functions in six languages from the dataset of Husain et al. (2019), the CodeSearchNet data. Training combines two objectives. Masked language modeling is applied to NL–code pairs. Replaced token detection trains a discriminator to spot plausible tokens that small NL and code generators substituted into the input. Because of this second objective, the model can also learn from functions that have no documentation. After fine-tuning, CodeBERT reached state-of-the-art results on natural language code search and on code-to-documentation generation. The authors also built a new NL–PL probing dataset. On it, the frozen model beat RoBERTa and a variant trained only on code. This work is an early, influential example of applying BERT-style pre-training to source code.
Key points
- Pre-training data: about 2.1M documented functions (bimodal) and 6.4M functions without documentation (unimodal) in Python, Java, JavaScript, PHP, Ruby and Go. A single model covers all six languages, and no tag marks which language an input is in.
- On code-to-documentation generation (smoothed BLEU-4), the model trained with RTD+MLM scored 17.83 overall, compared with 16.57 for RoBERTa (about +1.3).
- On C# summarization with the CodeNN StackOverflow dataset, a language not seen in pre-training, it scored 22.36 BLEU. That is 2.55 points above RoBERTa but below code2seq (23.04), which uses the code's AST paths.
- The authors introduced the first probing dataset for code-based pre-trained models. It frames probing as a cloze-style task: the model picks the right answer from a set of distractors, with no fine-tuning.
- Code and data are released at github.com/microsoft/CodeBERT.
Cited by
- SantaCoder: don't reach for the stars!
- Program Synthesis with Large Language Models
- Evaluating Large Language Models Trained on Code
- GraphCodeBERT: Pre-training Code Representations with Data Flow
- DeBERTaV3: Improving DeBERTa using ELECTRA-Style Pre-Training with Gradient-Disentangled Embedding Sharing
- MetaGPT: Meta Programming for A Multi-Agent Collaborative Framework
- Qwen2.5-Coder Technical Report
- A Survey on Large Language Models for Code Generation
- Unsupervised Translation of Programming Languages
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- Competition-Level Code Generation with AlphaCode
- Recent Advances in Natural Language Processing via Large Pre-Trained Language Models: A Survey
- Text and Code Embeddings by Contrastive Pre-Training
- Code Llama: Open Foundation Models for Code
- A Survey of Large Language Models
- CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-X
- BigCodeBench: Benchmarking Code Generation with Diverse Function Calls and Complex Instructions
Cite
@inproceedings{feng2020codebert,
title = {{CodeBERT: A Pre-Trained Model for Programming and Natural Languages}},
author = {Feng, Zhangyin and Guo, Daya and Tang, Duyu and Duan, Nan and Feng, Xiaocheng and Gong, Ming and Shou, Linjun and Qin, Bing and Liu, Ting and Jiang, Daxin and Zhou, Ming},
booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2020},
year = {2020},
doi = {10.18653/v1/2020.findings-emnlp.139},
eprint = {2002.08155},
archivePrefix = {arXiv},
url = {https://doi.org/10.18653/v1/2020.findings-emnlp.139}
}References
- Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Ves Stoyanov, and Luke Zettlemoyer. 2019. Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension. arXiv preprint arXiv:1910.13461. find our card
- Uri Alon, Shaked Brody, Omer Levy, and Eran Yahav. 2019. code2seq: Generating sequences from structured representations of code. International Conferenceon Learning Representations. find
- Kyunghyun Cho, Bart Van Merriënboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning phrase representations using rnn encoder-decoder for statistical machine translation. arXiv preprint arXiv:1406.1078. find
- Kevin Clark, Minh-Thang Luong, Quoc V. Le, and Christopher D. Manning. 2020. {ELECTRA}: Pre-training text encoders as discriminators rather than generators. In International Conference on Learning Representations. find
- Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2018. Bert: Pre-training of deep bidirectional transformers for language understanding. arXiv preprint arXiv:1810.04805. find
- Xiaodong Gu, Hongyu Zhang, and Sunghun Kim. 2018. Deep code search. In 2018 IEEE/ACM 40th International Conference on Software Engineering (ICSE), pages 933–944. IEEE. find
- Hamel Husain, Ho-Hsiang Wu, Tiferet Gazit, Miltiadis Allamanis, and Marc Brockschmidt. 2019. Codesearchnet challenge: Evaluating the state of semantic code search. arXiv preprint arXiv:1909.09436. find our card
- Srinivasan Iyer, Ioannis Konstas, Alvin Cheung, and Luke Zettlemoyer. 2016. Summarizing source code using a neural attention model. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 2073–2083. find
- Chin-Yew Lin and Franz Josef Och. 2004. Orange: a method for evaluating automatic evaluation metrics for machine translation. In Proceedings of the 20th international conference on Computational Linguistics, page 501. Association for Computational Linguistics. find
- Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. 2019. Roberta: A robustly optimized bert pretraining approach. arXiv preprint arXiv:1907.11692. find
- Jiasen Lu, Dhruv Batra, Devi Parikh, and Stefan Lee. 2019. Vilbert: Pretraining task-agnostic visiolinguistic representations for vision-and-language tasks. In Advances in Neural Information Processing Systems, pages 13–23. find our card
- Bhaskar Mitra, Nick Craswell, et al. 2018. An introduction to neural information retrieval. Foundations and Trends® in Information Retrieval, 13(1):1–126. find
- Matthew E Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018. Deep contextualized word representations. arXiv preprint arXiv:1802.05365. find
- Fabio Petroni, Tim Rocktäschel, Patrick Lewis, Anton Bakhtin, Yuxiang Wu, Alexander H Miller, and Sebastian Riedel. 2019. Language models as knowledge bases? arXiv preprint arXiv:1909.01066. find our card
- Telmo Pires, Eva Schlinger, and Dan Garrette. 2019. How multilingual is multilingual bert? arXiv preprint arXiv:1906.01502. find our card
- Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. 2018. Improving language understanding by generative pre-training. URL https://s3-us-west-2. amazonaws. com/openai-assets/researchcovers/languageunsupervised/language understanding paper. pdf. find
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. 2019. Exploring the limits of transfer learning with a unified text-to-text transformer. arXiv preprint arXiv:1910.10683. find
- Alexander M Rush, Sumit Chopra, and Jason Weston. 2015. A neural attention model for abstractive sentence summarization. arXiv preprint arXiv:1509.00685. find
- Chen Sun, Austin Myers, Carl Vondrick, Kevin Murphy, and Cordelia Schmid. 2019. Videobert: A joint model for video and language representation learning. arXiv preprint arXiv:1904.01766. find our card
- Ilya Sutskever, Oriol Vinyals, and Quoc V Le. 2014. Sequence to sequence learning with neural networks. In Advances in neural information processing systems, pages 3104–3112. find
- Kai Sheng Tai, Richard Socher, and Christopher D Manning. 2015. Improved semantic representations from tree-structured long short-term memory networks. arXiv preprint arXiv:1503.00075. find
- Alon Talmor, Yanai Elazar, Yoav Goldberg, and Jonathan Berant. 2019. olmpics–on what language model pre-training captures. arXiv preprint arXiv:1912.13283. find our card
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Advances in neural information processing systems, pages 5998–6008. find
- Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, et al. 2016. Google’s neural machine translation system: Bridging the gap between human and machine translation. arXiv preprint arXiv:1609.08144. find
- Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, and Quoc V Le. 2019. Xlnet: Generalized autoregressive pretraining for language understanding. arXiv preprint arXiv:1906.08237. find our card