Skip to main content
QUICK REVIEW

[Paper Review] Evaluating Semantic Representations of Source Code

Yaza Wainakh, Moiz Rauf|arXiv (Cornell University)|Sep 25, 2019
Software Engineering ResearchComputer Science26 references5 citations
TL;DR

This paper introduces IdBench, a benchmark based on 500 developers' ratings to evaluate semantic representations of source code identifiers. It reveals that while top embeddings capture semantic relatedness reasonably well, none adequately represent semantic similarity, often conflating oppositely meaning identifiers, which risks errors in downstream tools.

ABSTRACT

Learned representations of source code enable various software developer tools, e.g., to detect bugs or to predict program properties. At the core of code representations often are word embeddings of identifier names in source code, because identifiers account for the majority of source code vocabulary and convey important semantic information. Unfortunately, there currently is no generally accepted way of evaluating the quality of word embeddings of identifiers, and current evaluations are biased toward specific downstream tasks. This paper presents IdBench, the first benchmark for evaluating to what extent word embeddings of identifiers represent semantic relatedness and similarity. The benchmark is based on thousands of ratings gathered by surveying 500 software developers. We use IdBench to evaluate state-of-the-art embedding techniques proposed for natural language, an embedding technique specifically designed for source code, and lexical string distance functions, as these are often used in current developer tools. Our results show that the effectiveness of embeddings varies significantly across different embedding techniques and that the best available embeddings successfully represent semantic relatedness. On the downside, no existing embedding provides a satisfactory representation of semantic similarities, e.g., because embeddings consider identifiers with opposing meanings as similar, which may lead to fatal mistakes in downstream developer tools. IdBench provides a gold standard to guide the development of novel embeddings that address the current limitations.

Motivation & Objective

  • To address the lack of a standardized, unbiased evaluation framework for code identifier embeddings.
  • To measure how well existing embedding techniques represent semantic relatedness and similarity in source code.
  • To identify limitations in current embeddings, especially their tendency to treat semantically opposite identifiers as similar.
  • To provide a gold-standard benchmark for guiding future development of improved code embeddings.

Proposed method

  • Collecting semantic relatedness and similarity ratings from 500 software developers on thousands of identifier pairs.
  • Designing IdBench as a large-scale, human-annotated benchmark for evaluating code embeddings.
  • Evaluating state-of-the-art natural language embeddings, code-specific embeddings, and lexical string distance functions on the benchmark.
  • Using correlation-based metrics to compare embedding similarity scores against human-annotated ratings.
  • Analyzing discrepancies between embedding outputs and human judgments to identify systematic failures.

Experimental results

Research questions

  • RQ1How well do existing code identifier embeddings represent semantic relatedness as judged by human developers?
  • RQ2To what extent do embedding techniques fail to distinguish between semantically opposite identifiers?
  • RQ3How do code-specific embeddings compare to general-purpose natural language embeddings in capturing code semantics?
  • RQ4How do lexical string distance functions perform relative to learned embeddings in representing semantic similarity?

Key findings

  • The best-performing embeddings achieve moderate correlation with human judgments on semantic relatedness, but none achieve high accuracy on similarity.
  • Many embeddings incorrectly rank identifiers with opposite meanings as semantically similar, posing risks for downstream tools.
  • Code-specific embeddings outperform general-purpose NLP embeddings in capturing code semantics, but still show significant limitations.
  • Lexical string distance functions perform poorly compared to learned embeddings, especially on semantic similarity tasks.
  • The benchmark reveals systematic biases in current embedding models, particularly in handling semantic opposites.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.