Skip to main content
QUICK REVIEW

[論文レビュー] Learning Deep Semantic Model for Code Search using CodeSearchNet Corpus

Chen Wu, Ming Yan|arXiv (Cornell University)|Jan 27, 2022
Software Engineering Research被引用数 6
ひとこと要約

本稿では、マルチモーダル学習、自己注意プーリング、統合表現を活用して、自然言語クエリとコードスニペットの間の意味的ギャップを埋めるためのディープな意味的モデルを提案する。CodeSearchNetコーパスを用いた大バッチ学習とハードネガティブマイニングにより訓練されたモデルは、最先端の0.384 NDCGスコアを達成し、ベンチマークチャレンジで1位を獲得した。

ABSTRACT

Semantic code search is the task of retrieving relevant code snippet given a natural language query. Different from typical information retrieval tasks, code search requires to bridge the semantic gap between the programming language and natural language, for better describing intrinsic concepts and semantics. Recently, deep neural network for code search has been a hot research topic. Typical methods for neural code search first represent the code snippet and query text as separate embeddings, and then use vector distance (e.g. dot-product or cosine) to calculate the semantic similarity between them. There exist many different ways for aggregating the variable length of code or query tokens into a learnable embedding, including bi-encoder, cross-encoder, and poly-encoder. The goal of the query encoder and code encoder is to produce embeddings that are close with each other for a related pair of query and the corresponding desired code snippet, in which the choice and design of encoder is very significant. In this paper, we propose a novel deep semantic model which makes use of the utilities of not only the multi-modal sources, but also feature extractors such as self-attention, the aggregated vectors, combination of the intermediate representations. We apply the proposed model to tackle the CodeSearchNet challenge about semantic code search. We align cross-lingual embedding for multi-modality learning with large batches and hard example mining, and combine different learned representations for better enhancing the representation learning. Our model is trained on CodeSearchNet corpus and evaluated on the held-out data, the final model achieves 0.384 NDCG and won the first place in this benchmark. Models and code are available at https://github.com/overwindows/SemanticCodeSearch.git.

研究の動機と目的

  • コード検索における自然言語クエリとコードスニペットの間の意味的ギャップを解消すること。
  • 複数のプログラミング言語にまたがるクロスリンガル埋め込みを共同で学習することで、コード検索のパフォーマンスを向上させること。
  • 中間的なコードおよびクエリ埋め込みの特徴統合と自己注意プーリングを通じて、表現学習を強化すること。
  • 実世界のコード検索アプリケーションに適した効果的で効率的なモデルアーキテクチャの開発。
  • マルチ言語意味的コード検索のためのCodeSearchNetベンチマークで最先端のパフォーマンスを達成すること。

提案手法

  • 効率的なコード検索を実現するためのバイエンコーダアーキテクチャを採用し、クエリとコードスニペットそれぞれに別々のエンコーダを設ける。
  • 学習可能な注意重みを用いて、可変長のコードおよびクエリ表現を1つのベクトルに集約する自己注意プーリングを適用する。
  • エンコーダーの複数の中間表現を、学習可能な言語固有の重みを用いて統合し、最終的な統合表現を生成する。
  • 一般化性能と表現品質の向上を図るために、大バッチ学習とハードネガティブマイニングを採用する。
  • コードおよびドキュメンテーションのパースとトークン化にTreeSitterとBPEトークン化を活用し、語彙サイズを削減する。
  • 正例(クエリ、コード)ペア間のコサイン類似度を最大化し、負例ペア間では最小化するように、対照的損失関数を用いてモデルを訓練する。

実験結果

リサーチクエスチョン

  • RQ1標準的なプーリング手法と比較して、中間表現の自己注意プーリングはコード検索パフォーマンスを向上させることができるか?
  • RQ2学習可能な重みを用いて複数のエンコーダーレイヤーの表現を統合することは、コード検索における意味的表現学習を向上させるか?
  • RQ3ハードネガティブマイニングを伴う大バッチ学習は、マルチ言語コード検索におけるモデルの一般化性能を顕著に向上させることができるか?
  • RQ4クロスリンガル埋め込みの整合性は、異なるプログラミング言語間でのゼロショットまたはフェイントショットコード検索を強化するのにどの程度効果的か?
  • RQ5マルチモーダル学習と、統合や注意プーリングといったアーキテクチャ的イノベーションを組み合わせることで、標準的なニューラルコード検索ベースラインを上回る性能が得られるか?

主な発見

  • 提案モデルは、CodeSearchNetベンチマークで平均NDCGスコア0.384を達成し、コンテストに参加したすべての他のモデルを上回った。
  • 自己注意プーリングと統合表現を備えたモデル(NBoW+Weighted)は、テストセットで最高のパフォーマンスを示し、NDCGが0.3841に達した。
  • アブレーションスタディの結果、ベースラインのNBoWモデルと比較して、自己注意プーリングと表現統合の両方が性能向上に顕著な寄与をしていることが確認された。
  • モデルはGo、Java、JavaScript、PHP、Python、Rubyの6つのプログラミング言語にわたって優れた一般化性能を示した。
  • 大バッチ学習とハードネガティブマイニングの活用により、表現学習が向上し、ノイズや曖昧なクエリに対しても頑健性が向上した。
  • 最終的なモデルはGitHub上で公開されており、再現性と意味的コード検索分野におけるさらなる研究を可能にしている。

より良い研究を、今すぐ始めましょう

論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。