NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

On the Importance of Building High-quality Training Datasets for Neural Code Search

Zhensu Sun, Li Li 0091, Yan Liu, Xiaoning Du, Li Li 0029

Abstract

Neural code search models rely heavily on massive training datasets, but the standard practice of using scraped code comments as a proxy for user queries introduces severe noise. This paper introduces a two-step data cleaning framework (syntactic and semantic) that filters out bad comment-code pairs. Training on this smaller, high-quality dataset drastically improves search accuracy while cutting training time in half.

The Problem: Comments are Not Queries

Semantic code search engines allow developers to find code snippets using natural language queries (e.g., "convert string to JSON"). Deep learning models excel at this, but they are incredibly data-hungry. Because real user search queries are proprietary and hard to obtain, researchers typically scrape open-source repositories (like GitHub) and use the first line of a function's code comment as the "query."

The problem is that comments are not queries. Developers write comments to generate documentation (using HTML or Javadoc tags), provide external URLs, or leave "TODO" notes. Furthermore, comments often explain why code exists rather than what it does. The authors found that over one-third of the popular CodeSearchNet dataset contains noise that deviates wildly from how a human would actually type a search query. Training a model on this "garbage-in" data leads to "garbage-out" performance in real-world scenarios.

Methodology: The NLQF Framework

To bridge the gap between noisy code comments and natural user queries, the authors propose NLQF (Natural Language Query Filter), a two-stage automated cleaning pipeline:

  1. Rule-based Syntactic Filter: A set of heuristics designed to strip out obvious non-query text. It removes HTML tags, Javadoc tags (e.g., @param), URLs, non-English text, punctuation-heavy dividers, and extremely short sentences.
  2. Model-based Semantic Filter: This novel core determines if a comment reads like a human query. The authors collected a "bootstrap corpus" of StackOverflow question titles starting with "how to" and trained a Variational Auto-Encoder (VAE) using Gated Recurrent Units (GRUs). GitHub comments are fed into the VAE; if a comment is semantically similar to a StackOverflow query, it yields a low reconstruction loss. An unsupervised clustering algorithm (EM-GMM) then finds the optimal cutoff point to discard anomalies.
The NLQF pipeline consists of a rule-based syntactic filter followed by a model-based semantic filter using a VAE and clustering.

Datasets and Evaluation

  • Training Data: The Java subset of CodeSearchNet (CSN), containing 394,471 raw comment-code pairs.
  • Bootstrap Query Corpus: 168,779 Java-related StackOverflow question titles used to train the VAE.
  • Evaluation Benchmarks: Three human-annotated, real-world datasets: CSN-v (434 queries), CosBench (CB) (52 queries), and NCSED (287 queries).
  • New Release: The authors released COFIC (Codebase Paired with Filtered Comments), a newly distilled dataset of over 1 million high-quality Java comment-code pairs.

Key Results

The authors trained two popular neural code search models (DeepCS and CARLCS) on both the raw dataset and the filtered dataset. The results demonstrate that quality beats quantity: aggressively pruning the dataset (removing roughly half of it) makes the model significantly smarter.

Comparison of model performance across three benchmarks shows that filtered training sets consistently outperform full datasets.
  • Performance Boost: DeepCS trained on filtered data beat the model trained on full data by 21.3% in Answer@1 and 19.2% in Mean Reciprocal Rank (MRR).
  • Efficiency: Because the filtered training dataset is roughly half the size of the original, training time and compute resources were cut in half.
  • Human Validation: Manual inspection confirmed the filtered data was superior; the average "likeness to a real query" score jumped from 0.27 to 0.61.

Limitations and Future Work

While effective, the framework has limitations. Heuristics can be brittle; for instance, a "short sentence" rule might accidentally filter out valid, concise queries like "quick sort." Additionally, the VAE's reliance on "how to" StackOverflow titles might introduce a specific bias in phrasing. Future work should verify if this framework generalizes to other programming languages and modern Transformer-based architectures.

Summary updated

BibTeX
@inproceedings{sun2022importance,
  author = {Zhensu Sun and Li Li and Yan Liu and Xiaoning Du and Li Li},
  title = {{On the Importance of Building High-quality Training Datasets for Neural Code Search}},
  booktitle = {ICSE},
  year = {2022},
  doi = {10.1145/3510003.3510160},
}
Figure