Skip to main content
QUICK REVIEW

[논문 리뷰] CodeBERT: A Pre-Trained Model for Programming and Natural Languages

Zhangyin Feng, Daya Guo|arXiv (Cornell University)|2020. 02. 19.
Topic Modeling참고 문헌 27인용 수 247
한 줄 요약

CodeBERT는 자연어와 코드 데이터를 대상으로 학습된 양모달 프리트레인 Transformer 모델로, NL-코드 검색 및 코드 문서화 생성에서 최첨단 결과를 달성하고 제로샷 NL-PL 탐색을 가능하게 한다.

ABSTRACT

We present CodeBERT, a bimodal pre-trained model for programming language (PL) and nat-ural language (NL). CodeBERT learns general-purpose representations that support downstream NL-PL applications such as natural language codesearch, code documentation generation, etc. We develop CodeBERT with Transformer-based neural architecture, and train it with a hybrid objective function that incorporates the pre-training task of replaced token detection, which is to detect plausible alternatives sampled from generators. This enables us to utilize both bimodal data of NL-PL pairs and unimodal data, where the former provides input tokens for model training while the latter helps to learn better generators. We evaluate CodeBERT on two NL-PL applications by fine-tuning model parameters. Results show that CodeBERT achieves state-of-the-art performance on both natural language code search and code documentation generation tasks. Furthermore, to investigate what type of knowledge is learned in CodeBERT, we construct a dataset for NL-PL probing, and evaluate in a zero-shot setting where parameters of pre-trained models are fixed. Results show that CodeBERT performs better than previous pre-trained models on NL-PL probing.

연구 동기 및 목표

  • 다수의 프로그래밍 언어에 걸쳐 자연어와 프로그래밍 언어를 포괄하는 통합 프리트레인 모델을 개발한다.
  • 양모달 NL-PL 쌍과 단일모달 코드 데이터를 모두 활용하여 강력한 표현을 학습한다.
  • NL-PL 과제 예로 자연어 코드 검색 및 코드 문서화 생성을 포함한 효과를 입증한다.
  • 제로샷 설정에서 NL-PL 탐색을 통해 CodeBERT가 어떤 지식을 포착하는지 조사한다.

제안 방법

  • 변환기 기반 아키텍처를 사용한다(RoBERTa-base 크기, 125M 파라미터).
  • NL-PL 데이터의 MLM과 단모달 데이터를 활용하는 RTD를 결합한 하이브리드 목표로 사전학습한다.
  • 입력을 두 구간(NL 및 코드)으로 구분하고 [SEP] 토큰으로 구분하며 [CLS]를 집계 표현으로 사용한다.
  • 여섯 가지 언어(Python, Java, JavaScript, PHP, Ruby, Go)에서 양모달 NL-PL 쌍과 단모달 코드 데이터를 활용해 학습한다.
  • RTD를 위해 제너레이터로 가능한 대체 토큰을 생성하고 원래 토큰과 대체 토큰을 구분하는 판별기를 학습한다.
  • NL-PL 과제의 다운스트림 작업으로 NL 기반 코드 검색 및 코드-텍스트 생성과 같은 작업에 대해 CodeBERT를 미세조정한다.

실험 결과

연구 질문

  • RQ1양모달 프리트레인 모델이 NL-PL 쌍과 단모달 코드 데이터로 학습된 경우 순수 NL 또는 코드 전용 모델보다 NL-PL 이해 과제를 향상시키는가?
  • RQ2MLM 단독, RTD 단독, 그리고 이들의 결합이 NL-PL 과제에 미치는 영향은 무엇인가?
  • RQ3CodeBERT가 다중 프로그래밍 언어에 걸쳐 코드 검색 및 코드 문서화 생성에 일반화할 수 있는가?
  • RQ4RoBERTa 및 코드 전용 프리트레인 모델과 비교했을 때 NL-PL 탐색에서 CodeBERT의 성능은 어떠한가?

주요 결과

모델루비자바스크립트파이썬자바PHP전반
NBow0.42850.46070.64090.58090.51400.48350.5181
CNN0.24500.35230.62740.57080.52700.52940.4753
BiRNN0.08350.15300.45240.32130.28650.25120.2580
selfAtt0.36510.45060.68090.69220.58660.60110.5628
RoBERTa0.62450.60600.82040.80870.66590.65760.6972
PT w/ Code Only (init=s)0.57120.55570.79290.78550.65670.61720.6632
PT w/ Code Only (init=R)0.66120.64020.81910.84380.72130.67060.7260
CodeBERT (MLM, init=s)0.56950.60290.83040.82610.71420.65560.6998
CodeBERT (MLM, init=R)0.68980.69970.83830.86470.74760.68930.7549
CodeBERT (RTD, init=R)0.64140.65120.82850.82630.71500.67740.7233
CodeBERT (MLM+RTD, init=R)0.69260.70590.84000.86850.74840.70620.7603
  • CodeBERT는 미세조정 시 자연어 코드 검색(CodeSearchNet)에서 최첨단 결과를 달성하며 RoBERTa 및 코드 전용 프리트레인 모델보다 우수하다.
  • RoBERTa에서 초기화된 MLM+RTD 프리트레이닝이 언어 전반에서 최상의 검색 성능을 제공한다(예: 대조군 대비 Ma-Avg 개선).
  • 코드 문서화 생성에서 CodeBERT 기반 인코더가 RoBERTa 및 코드 전용 벤치마크보다 더 높은 BLEU-4 점수를 달성하며 RTD+MLM이 추가 이점을 제공한다.
  • 제로샷 설정의 NL-PL 탐색에서 CodeBERT는 RoBERTa 및 코드 전용 프리트레인 모델보다 PL 및 NL 예측 과제에서 우수한 성능을 보인다.
  • 사전 학습에 등장하지 않은 프로그래밍 언어(C# 코드→NL 생성)에 대한 일반화에서 CodeBERT가 RoBERTa 및 일부 벤치마크보다 더 나은 일반화를 보이지만 모든 경우에 최첨단 code2seq를 능가하지는 않는다.
  • NL 및 PL 탐색에 대한 사례 연구는 CodeBERT가 RoBERTa가 실패하는 곳에서 마스킹된 NL 및 PL 토큰을 정확히 예측할 수 있음을 보여준다.

더 나은 연구,지금 바로 시작하세요

연구 설계부터 논문 작성까지, 연구 시간을 획기적으로 줄여보세요.

카드 등록 없음 · 무료 플랜 제공

이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.