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

CodeQA: A Question Answering Dataset for Source Code Comprehension

Chenxiao Liu, Xiaojun Wan

Abstract

Code comprehension is a fundamental task in software engineering, yet existing benchmarks often focus on coarse-grained summarization or simple extractive tasks. This paper introduces CodeQA, a large-scale dataset for free-form question answering on source code. By transforming code comments into over 190,000 QA pairs for Java and Python using syntactic and semantic analysis, the authors provide a rigorous benchmark for evaluating how well models understand the specific logic of code. Evaluation of state-of-the-art models like CodeBERT reveals a significant performance gap compared to human developers, particularly in technical correctness.

Introduction

While AI has made significant strides in code summarization—describing what a function does in general terms—true code comprehension remains a challenge. Summarization is often too coarse to prove a model understands the specific "how," "where," or "why" of a code snippet. Existing Question Answering (QA) datasets for code have historically been limited to extractive tasks (finding a specific token) or relied on rigid templates.

To address this, researchers from Peking University introduced CodeQA. This dataset focuses on free-form QA, where the answer is a natural language sentence that may not appear verbatim in the source code. This approach ensures that models must synthesize information rather than simply pointing to a span of text.

Methodology

The authors developed an automated pipeline to generate high-quality QA pairs by leveraging existing code comments (Javadocs and Python docstrings) as a ground-truth source of information. The process involves several key steps:

  1. Comment Selection & Cleaning: Noisy comments, such as license headers or "TODO" notes, were filtered out. Incomplete sentences were normalized to create a stable base for transformation.
  2. Syntactic & Semantic Transformation: Instead of simple templates, the researchers applied Dependency Parsing (DP) and Semantic Role Labeling (SRL) to the comments. By identifying actors, actions, and objects, they programmatically flipped descriptive sentences into questions. For example, "The code trims all occurrences of the character" is transformed into "What does the code trim?"
  3. Question Diversity: The pipeline generates a variety of question types, including Wh-questions (What, Where, When, Why, How) and Yes/No questions.
Figure 1: Examples of question templates and generated QA pairs based on syntactic roles.

Dataset Characteristics

The CodeQA dataset is split into two programming languages:

  • Java: 119,778 question-answer pairs from 56,545 code snippets.
  • Python: 70,085 question-answer pairs from 44,830 code snippets.

The dataset is categorized into four types of comprehension: Functionality (63%), Property (17%), Workflow (11%), and Purpose (9%). Notably, only a tiny fraction of answers (under 5% in Java) are direct "spans" of the code, forcing models to generate natural language responses.

Evaluation and Results

The researchers evaluated the dataset using four neural architectures: a standard Seq2seq model, a Dual Encoder, a Transformer, and CodeBERT. The results highlight a substantial "comprehension gap" between AI and human developers.

Figure 6: Performance metrics across different models on the Dev and Test sets, showing the significant gap between CodeBERT and Human performance.

Key findings from the evaluation include:

  • Pre-training is Not Sufficient: While CodeBERT significantly outperformed other baselines, it still lagged nearly 30 points behind human performance in BLEU scores.
  • Fluency vs. Correctness: Human evaluation revealed that while modern models are adept at generating fluent English (scoring 2.40/3.0), they frequently fail at technical correctness (scoring 1.89/3.0). Models often sound confident while hallucinating or missing the specific logic of the code.

Conclusion

CodeQA serves as a challenging new benchmark for the research community. The authors note that the dataset's quality is inherently tied to the quality of original code comments. Future work should focus on capturing the interaction between the formal logic of code and informal natural language, potentially through better structural encoding of the code's abstract syntax tree (AST).

Summary updated

BibTeX
@inproceedings{liu2021codeqa,
  author = {Chenxiao Liu and Xiaojun Wan},
  title = {{CodeQA: A Question Answering Dataset for Source Code Comprehension}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.findings-emnlp.223},
}
Figure