CS1QA: A Dataset for Assisting Code-based Question Answering in an Introductory Programming Course

Changyoon Lee, Yeon Seonwoo, Alice Oh

Introduction

In introductory programming courses (CS1), students frequently seek help from Teaching Assistants (TAs) via chat platforms. However, providing timely and accurate support is labor-intensive. While automated Question Answering (QA) systems offer a potential solution, existing models often fail when faced with the "messy" reality of student programming.

Most code-based QA datasets, such as those derived from GitHub or StackOverflow, focus on "expert" code that is functional and well-structured. In contrast, student code is frequently incomplete, syntactically broken, or logically flawed. Furthermore, student questions are often vague (e.g., "Why doesn't this work?"). To address this, the CS1QA dataset was developed to bridge the gap between natural language questions and noisy, real-world student source code.

An example of a student-TA interaction in the CS1QA dataset, highlighting a logical error in a Python loop.

The CS1QA Dataset

The CS1QA dataset consists of over 9,000 annotated question-answer pairs collected from an introductory Python course at KAIST. Unlike previous datasets, CS1QA captures the dynamic interaction between students and TAs in a real-world classroom setting. It includes 9,237 annotated pairs featuring questions, answers, question types, and relevant code lines. Additionally, it provides 17,698 unannotated chat sessions for potential semi-supervised learning research.

Comparison of CS1QA with other popular code-based datasets, highlighting its unique real-world classroom source.

Research Tasks and Methodology

The authors defined three primary benchmarks for the dataset:

  1. Question Type Classification: Categorizing the intent of the question (e.g., "Logical Error," "Syntax Usage," or a TA's "Reasoning" probe).
  2. Code Line Selection: Identifying specific lines in the student's code relevant to the question—essentially "pointing" to the problem area.
  3. Answer Retrieval: Finding a similar previously answered question and returning its answer.

To establish a baseline, the researchers evaluated three transformer-based models: RoBERTa (trained on natural language), CodeBERT (pretrained on both natural language and code), and XLM-RoBERTa (multilingual).

Key Insights: Why Student Code is Different

A significant finding was that CodeBERT did not significantly outperform RoBERTa. Typically, models pretrained on code have a distinct advantage in programming tasks. However, because student code is often non-idiomatic and full of errors, the code-specific pretraining provided less benefit than expected. This suggests that models need to be specifically adapted to handle "broken" code rather than just "clean" code.

Furthermore, the study revealed that context is essential. For "Code Understanding" questions (e.g., "What does this function do?"), model performance improved significantly when the student's code was provided as context. This confirms that the model must "read" the code to interpret the student's intent correctly.

Results and Challenges

  • Type Classification: The best-performing model (RoBERTa) achieved 76.65% accuracy. While decent, models struggled with "Understanding" type questions until the dataset was augmented with synthetic templates.
  • Code Line Selection: This task proved difficult, with a top F1 score of 57.57%. Models were often misled by keyword matching, selecting every line containing a mentioned variable rather than just the problematic ones.
  • Answer Retrieval: This yielded a low BLEU-1 score of 13.07. The results suggest that simple retrieval is insufficient; because code context changes a question's meaning, systems likely need to generate bespoke answers rather than just retrieving old ones.

Conclusion

CS1QA highlights the complexity of assisting students in a programming environment. While AI excels at writing functional code, understanding the nuances of a student's struggling code remains a significant challenge. This dataset provides a crucial benchmark for developing more robust, human-centric AI tutors capable of navigating the messy reality of the classroom.

Summary updated

BibTeX
@inproceedings{lee2022cs,
  author = {Changyoon Lee and Yeon Seonwoo and Alice Oh},
  title = {{CS1QA: A Dataset for Assisting Code-based Question Answering in an Introductory Programming Course}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2022},
  doi = {10.18653/v1/2022.naacl-main.148},
}
Figure