ProCQA: A Large-scale Community-based Programming Question Answering Dataset for Code Search

Zehan Li, Jianfei Zhang, Chuantao Yin, Yuanxin Ouyang, Wenge Rong

TL;DR

This paper introduces ProCQA, a massive new dataset of programming questions and answers extracted from StackOverflow, designed to better align natural language queries with relevant code. They also propose a "modality-agnostic contrastive pre-training" (MACP) method that leverages this dataset to achieve state-of-the-art results in code search tasks.

What Problem Does This Paper Address?

The core challenge is effectively matching natural language questions to relevant code snippets, a crucial task for developer productivity and software intelligence. Existing approaches often rely on pre-training models using curated datasets that separate text and code. However, these datasets can be limited in scale, diversity, and how well they reflect real-world programming questions, which are often "mixed-modal" – containing both natural language and code interleaved. This makes it difficult for models to learn a truly unified representation space for text and code.

Methods

The paper introduces two main contributions:

  • ProCQA Dataset: This is a large-scale dataset (5 million QA pairs) mined from StackOverflow, covering 11 programming languages. Its key innovation is the "mixed-modal" format, where questions and answers naturally interleave text and code, mimicking how developers actually ask and answer questions. They employed rigorous filtering and decontamination to ensure data quality.
  • Modality-Agnostic Contrastive Pre-training (MACP): This is a novel pre-training approach that treats text and code within the mixed-modal data as equally important. Instead of trying to explicitly align separate text and code representations, MACP uses a contrastive learning objective to learn a shared representation space that can handle both modalities simultaneously. This is a departure from previous methods that often focused on unimodal (code-code) or bimodal (text-code) alignment.

Datasets

  • ProCQA: The newly introduced dataset, mined from StackOverflow, containing approximately 5 million mixed-modal programming QA pairs across 11 languages.
  • CodeSearchNet (CSN): Used as a baseline pre-training corpus and for evaluation. It consists of code-comment pairs.
  • Evaluation Benchmarks: The paper evaluates their model on a variety of established benchmarks, including:
  • CodeSearchNet: For text-code search across multiple languages.
  • Adv Test, CoSQA, CoNaLa, SO-DS, StaQC: Datasets closer to real-world user queries.
  • POJ-104: For code-code search (intra-modal retrieval).
  • CodeNet: For cross-lingual code retrieval.
  • Smart Contracts (SC) and Spider: For cross-domain code search (unseen languages).

Key Insights and Ideas

  • Real-world questions are mixed-modal: The paper strongly advocates for the importance of mixed-modal data (interleaved text and code) for training models that truly understand programming questions. StackOverflow naturally provides this.
  • Modality-agnostic learning is powerful: By not forcing a strict separation between text and code during pre-training, MACP can learn a more robust and unified representation space, leading to better performance across various tasks.
  • Large-scale, diverse data matters: ProCQA's scale and multi-language support are shown to be crucial for improving generalization, especially for cross-domain and zero-shot scenarios.
  • Existing datasets have limitations: The paper highlights that datasets like CodeSearchNet, while useful, have limitations in query type (documentation strings vs. natural questions) and data distribution, which ProCQA aims to overcome.

Key Results

  • State-of-the-art performance: MACP, trained on ProCQA, consistently outperforms previous state-of-the-art models like CodeRetriever on various code retrieval benchmarks, often by significant margins (e.g., 1-10% points).
  • Improved CodeSearchNet performance: MACP achieved an average improvement of 2.1 points over CodeRetriever on six programming language subsets of CodeSearchNet.
  • Significant gains on challenging benchmarks: On datasets closer to real-world scenarios (Adv Test, CoSQA, etc.), MACP outperformed prior models by up to 10 points.
  • Strong cross-lingual and cross-domain results: MACP demonstrated superior performance in zero-shot cross-lingual code search and cross-domain code retrieval on unseen languages, suggesting ProCQA's diverse language coverage is beneficial.
  • Pre-training corpus impact: Experiments showed that using ProCQA as a pre-training corpus outperformed using CodeSearchNet alone, and combining both yielded the best results.

Limitations and Future Work

  • Answer Generation Challenge: While MACP excels at retrieval, the paper notes that generating long-form answers from ProCQA remains challenging due to the length and complexity of the answers.
  • Future Work: The authors suggest exploring the benefits of ProCQA for other generative code QA tasks. They also imply that further research into improving long-form answer generation is warranted.

Summary updated

BibTeX
@inproceedings{li2024procqa,
  author = {Zehan Li and Jianfei Zhang and Chuantao Yin and Yuanxin Ouyang and Wenge Rong},
  title = {{ProCQA: A Large-scale Community-based Programming Question Answering Dataset for Code Search}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2024},
}
Figure