CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning

5 Jul 2022  ·  Hung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese, Steven C. H. Hoi ·

Program synthesis or code generation aims to generate a program that satisfies a problem specification. Recent approaches using large-scale pretrained language models (LMs) have shown promising results, yet they have some critical limitations. In particular, they often follow a standard supervised fine-tuning procedure to train a code generation model only from the pairs of natural-language problem descriptions and ground-truth programs. Such paradigm largely ignores some important but potentially useful signals in the problem specification such as unit tests, which thus often results in poor performance when solving complex unseen coding tasks. To address the limitations, we propose "CodeRL", a new framework for program synthesis tasks through pretrained LMs and deep reinforcement learning (RL). Specifically, during training, we treat the code-generating LM as an actor network, and introduce a critic network that is trained to predict the functional correctness of generated programs and provide dense feedback signals to the actor. During inference, we introduce a new generation procedure with a critical sampling strategy that allows a model to automatically regenerate programs based on feedback from example unit tests and critic scores. For the model backbones, we extended the encoder-decoder architecture of CodeT5 with enhanced learning objectives, larger model sizes, and better pretraining data. Our method not only achieves new SOTA results on the challenging APPS benchmark, but also shows strong zero-shot transfer capability with new SOTA results on the simpler MBPP benchmark.

PDF Abstract

Results from the Paper


Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Code Generation APPS CodeRL+CodeT5 Introductory Pass@1 6.77% # 6
Interview Pass@1 1.80% # 6
Competition Pass@1 0.69% # 6
Introductory Pass@1000 38.10% # 1
Interview Pass@1000 14.33% # 1
Competition Pass@1000 15.70% # 1
Competition Pass@5 2.36% # 2
Interview Pass@5 4.48% # 2
Introductory Pass@5 15.27% # 2
Competition Pass@any 15.70% # 1
Interview Pass@any 14.33% # 2
Introductory Pass@any 38.10% # 2
Code Generation APPS GPT-J 6B (Finetuned) Introductory Pass@1 5.60% # 7
Interview Pass@1 1.00% # 7
Competition Pass@1 0.50% # 7
Introductory Pass@1000 35.20% # 2
Interview Pass@1000 13.15% # 2
Competition Pass@1000 13.51% # 2
Competition Pass@5 1.00% # 3
Interview Pass@5 1.73% # 3
Introductory Pass@5 9.20% # 4
Competition Pass@any 13.51% # 3
Interview Pass@any 13.15% # 3
Introductory Pass@any 35.20% # 3
Code Generation APPS GPT-Neo 2.7B (Finetuned) Introductory Pass@1 3.90% # 9
Interview Pass@1 0.57% # 9
Competition Pass@1 0.00% # 9
Introductory Pass@1000 27.90% # 3
Interview Pass@1000 9.83% # 3
Competition Pass@1000 11.40% # 3
Competition Pass@5 0.00% # 5
Interview Pass@5 0.80% # 5
Introductory Pass@5 5.50% # 5
Competition Pass@any 11.40% # 4
Interview Pass@any 9.83% # 4
Introductory Pass@any 27.90% # 4
Code Generation APPS GPT2 1.5B (Finetuned) Introductory Pass@1 1.30% # 11
Interview Pass@1 0.70% # 8
Competition Pass@1 0.00% # 9
Introductory Pass@1000 25.00% # 5
Interview Pass@1000 9.27% # 4
Competition Pass@1000 8.80% # 4
Competition Pass@5 0.00% # 5
Interview Pass@5 1.03% # 4
Introductory Pass@5 3.60% # 7
Competition Pass@any 8.80% # 5
Interview Pass@any 9.27% # 6
Introductory Pass@any 25.00% # 6

Methods