Abstract
Developers often have questions about semantic aspects of code they are working on, e.g., "Is there a class whose parent classes declare a conflicting attribute?". Answering them requires understanding code semantics such as attributes and inheritance relation of classes. An answer to such a question should identify code spans constituting the answer (e.g., the declaration of the subclass) as well as supporting facts (e.g., the definitions of the conflicting attributes). The existing work on question-answering over code has considered yes/no questions or method-level context. We contribute a labeled dataset, called CodeQueries, of semantic queries over Python code. Compared to the existing datasets, in CodeQueries, the queries are about code semantics, the context is file level and the answers are code spans. We curate the dataset based on queries supported by a widely-used static analysis tool, CodeQL, and include both positive and negative examples, and queries requiring single-hop and multi-hop reasoning. To assess the value of our dataset, we evaluate baseline neural approaches. We study a large language model (GPT3.5-Turbo) in zero-shot and few-shot settings on a subset of CodeQueries. We also evaluate a BERT style model (CuBERT) with fine-tuning. We find that these models achieve limited success on CodeQueries. CodeQueries is thus a challenging dataset to test the ability of neural models, to understand code semantics, in the extractive question-answering setting.
Introduction
While Large Language Models (LLMs) have become impressive coding assistants, their ability to perform deep semantic reasoning is still questionable. Most existing code question-answering (QA) datasets are limited, often focusing on binary "yes/no" questions or restricting context to a single method. In real-world development, questions are often complex, such as: "Is there a class whose parent classes declare a conflicting attribute?" Answering this requires understanding inheritance and attribute resolution across an entire file.
There is a significant gap in datasets that require extractive QA—identifying specific code spans—based on file-level context and multi-hop reasoning. This paper introduces CodeQueries, a new large-scale dataset designed to push the boundaries of AI's understanding of code semantics.
The CodeQueries Dataset
The researchers took a programmatic approach to building a high-quality labeled dataset by leveraging CodeQL, a powerful static analysis tool. They identified 52 semantic queries covering correctness, security, and maintainability, and applied them to a large corpus of Python code (ETH Py150).
Unlike datasets that provide only a final answer, CodeQueries provides answer spans (the specific code triggering the query) and supporting-fact spans (the evidence, such as base class definitions). To prevent models from simple pattern matching, the dataset includes "plausible but negative" examples—code that appears problematic but is logically sound. In total, the dataset contains 34,662 positive and 52,613 negative examples.
Experimental Methodology
To assess the difficulty of CodeQueries, the authors evaluated two primary baseline approaches: GPT-3.5-Turbo (zero-shot and few-shot) and CuBERT (a BERT-style model).
Handling file-level context is challenging due to token limits. For CuBERT, the researchers employed a novel two-step procedure:
- Relevance Classifier: Identifies and selects important code blocks from the file.
- Span Predictor: Analyzes the selected blocks to identify answer and supporting-fact spans.
Key Results and Insights
The results demonstrate that CodeQueries is a highly challenging benchmark. In a few-shot setting using BM25 retrieval, GPT-3.5-Turbo achieved only a 32.66% exact match on positive examples. Fine-tuned CuBERT performed better, reaching 52.61%, but still left significant room for improvement.
Several key insights emerged from the evaluation:
- Multi-hop Reasoning is Hard: Models performed significantly worse on the 15 queries requiring multi-hop reasoning compared to single-hop queries.
- The Power of Negative Examples: Including negative examples in prompts is critical. GPT-3.5’s performance on negative examples jumped from ~27% to ~70% (at Pass@10) simply by adding one negative example to the few-shot prompt.
- Evidence-Based Verification: By requiring the prediction of "supporting facts," CodeQueries ensures models are "right for the right reasons," providing a more robust measure of semantic understanding.
Conclusion
CodeQueries highlights a significant bottleneck in current AI code understanding: the ability to perform extractive, multi-hop reasoning over large contexts. While fine-tuning and few-shot prompting provide some gains, the limited success of state-of-the-art models suggests that new architectures or training paradigms may be needed. Future work will look to expand the dataset to other programming languages and move beyond file-level context to full repository-level reasoning.
Summary updated