Skip to main content
QUICK REVIEW

[논문 리뷰] InferCode: Self-Supervised Learning of Code Representations by Predicting Subtrees

Nghi D. Q. Bui, Yijun Yu|arXiv (Cornell University)|2020. 12. 13.
Software Engineering Research참고 문헌 65인용 수 9
한 줄 요약

InferCode는 코드의 추상 구문 트리(abstract syntax trees, ASTs) 내에서 부분 트리를 예측하도록 트리 기반 컨volution 신경망(Tree-based Convolutional Neural Network, TBCNN)을 훈련시켜, 이식 가능하고 작업에 종속되지 않는 임베딩을 얻는 자기지도 학습 방법을 제안한다. 대규모 레이블이 없는 자바 코드로 훈련된 모델은 코드 클러스터링, 클론 탐지, 다국어 간 검색과 같은 다양한 하류 작업에서 최신 기술 수준의 성능을 달성하며, code2vec 및 ASTNN과 같은 이전 방법들보다 뚜렷한 격차를 확보한다.

ABSTRACT

Building deep learning models on source code has found many successful software engineering applications, such as code search, code comment generation, bug detection, code migration, and so on. Current learning techniques, however, have a major drawback that these models are mostly trained on datasets labeled for particular downstream tasks, and code representations may not be suitable for other tasks. While some techniques produce representations from unlabeled code, they are far from satisfactory when applied to downstream tasks. Although certain techniques generate representations from unlabeled code when applied to downstream tasks they are far from satisfactory. This paper proposes InferCode to overcome the limitation by adapting the self-supervised learning mechanism to build source code model. The key novelty lies in training code representations by predicting automatically identified subtrees from the context of the ASTs. Subtrees in ASTs are treated with InferCode as the labels for training code representations without any human labeling effort or the overhead of expensive graph construction, and the trained representations are no longer tied to any specific downstream tasks or code units. We trained an InferCode model instance using the Tree-based CNN as the encoder of a large set of Java code and applied it to downstream unsupervised tasks such as code clustering, code clone detection, cross-language code search or reused under a transfer learning scheme to continue training the model weights for supervised tasks such as code classification and method name prediction. Compared to previous code learning techniques applied to the same downstream tasks, such as Code2Vec, Code2Seq, ASTNN, higher performance results are achieved using our pre-trained InferCode model with a significant margin for most tasks including those involving different programming languages.

연구 동기 및 목표

  • 수작업 레이블이 필요하고 소프트웨어 공학 작업 간 일반화 능력이 떨어지는 작업에 종속된 코드 표현 방식의 한계를 해결하기 위해.
  • 인간이 레이블링한 데이터나 복잡한 그래프 구축 없이도 레이블이 없는 소스 코드에서 코드 표현을 학습하는 자기지도 학습 방법을 개발하기 위해.
  • AST로 파arse 가능한 모든 코드 단위에 대해 민첩하고 재사용 가능한 코드 임베딩을 가능하게 하여 다양한 하류 작업을 지원하기 위해.
  • 기존의 지도 학습 또는 약한 지도 학습 방법에 비해 프로그래밍 언어 및 작업 간 이식성과 성능을 향상시키기 위해.
  • AST 내에서 부분 트리 예측이 강력하고 일반적인 목적의 코드 임베딩을 학습하는 데 효과적인 사전 과제(pretext task)가 될 수 있는지 탐색하기 위해.

제안 방법

  • 모델은 추상 구문 트리(abstract syntax trees, ASTs)를 조밀한 코드 벡터로 매핑하기 위해 트리 기반 컨볼루션 신경망(Tree-based Convolutional Neural Network, TBCNN)을 인코더로 사용한다.
  • 사전 과제는 AST의 맥락에서 무작위로 샘플된 부분 트리를 예측하는 것으로, 코드 벡터를 맥락 표현으로 사용해 부분 트리를 재구성한다.
  • 부분 트리는 인간의 레이블 없이 AST에서 자동으로 식별되며, 사전 훈련을 위한 자기 생성 레이블로 기능한다.
  • 모델은 레이블이 없는 대규모 자바 코드 데이터셋에서 사전 훈련되어 AST의 구조적 및 의미적 패턴을 학습한다.
  • 사전 훈련 후, 인코더는 지도 학습 작업에 대해 미세조정될 수 있거나 직접 비지도 학습 작업(예: 코드 클러스터링 및 검색)에 사용될 수 있다.
  • 이 방법은 비용이 많이 드는 그래프 구축을 피하고, AST의 보편적인 파싱 가능성 덕분에 다양한 프로그래밍 언어로 일반화되도록 설계되어 있다.

실험 결과

연구 질문

  • RQ1AST 내에서 부분 트리 예측이 일반적인 목적의 코드 표현을 학습하는 데 효과적인 자기지도 사전 과제로 기능할 수 있는가?
  • RQ2제안된 자기지도 학습 방법이 작업에 종속되거나 약한 지도 학습 방법보다 다양한 하류 작업에 더 잘 일반화되는 코드 임베딩을 생성하는가?
  • RQ3InferCode의 성능은 코드 클러스터링, 클론 탐지 및 다국어 간 검색에서 code2vec, code2seq, ASTNN과 같은 최신 기술 수준의 모델들과 비교해 어떻게 되는가?
  • RQ4사전 훈련된 InferCode 모델을 코드 분류 및 메서드 이름 예측과 같은 지도 학습 작업에 효과적으로 미세조정할 수 있는가?
  • RQ5모델의 성능은 특히 다국어 코드 검색에서 다양한 프로그래밍 언어 간에 견고한가?

주요 결과

  • InferCode는 코드 클러스터링에서 ARI: 0.70으로 code2vec(0.58)보다 17% 상대적 향상률을 기록하며 슈퍼리어 성능을 보였다.
  • BigCloneBench에서 클론 탐지 성능은 정밀도 0.90을 기록하여 code2vec(0.81)와 code2seq(0.45)보다 뚜렷하게 높았다.
  • Rosetta Stone에서 다국어 코드 검색 성능은 MRR 0.57을 기록하여 code2vec(0.41)와 code2seq(0.32)를 모두 앞섰다.
  • 사전 훈련된 InferCode 모델을 지도 학습 작업에 대해 미세조정하면, 랜덤 초기화에서 훈련하는 것보다 더 뛰어난 성능을 보였으며, 강력한 이식성의 가능성을 입증했다.
  • 모델의 성능은 다양한 프로그래밍 언어 간에 견고하여, 단일 언어를 넘어서 일반화된 성능을 보였다.
  • 부분 트리 예측이 사전 과제로 사용되었을 때, 메서드 이름 예측보다 더 나은 표현을 얻었으며, 후자는 유사한 이름이지만 다른 구현 방식을 가진 모델이 허구적인 상관관계를 학습하도록 유도하기 때문이다.

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

논문 읽기부터 검토까지, 연구 시간을 획기적으로 줄여보세요.

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

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