arrow
Return

CodeContrast: A Contrastive Learning Approach for Generating Coherent Programming Exercises

delete2025-01-13
delete0
delete
OA
AI
N
Nicolás Torres
DOI:10.3390/educsci15010080delete
deleteOriginal
deleteOriginal request for help
deleteShare
deleteSave
Abstract

Abstract

En 中文
Generating high-quality programming exercises with well-aligned problem descriptions, test cases, and code solutions is crucial for computer science education. However, current methods often lack coherence among these components, reducing their educational value. We present CodeContrast, a novel generative model that uses contrastive learning to map programming problems, test cases, and solutions into a shared feature space. By minimizing the distance between matched components and maximizing it for non-matched ones, CodeContrast learns the intricate relationships necessary to generate coherent programming exercises. Our model architecture includes three encoder networks for problem descriptions, test cases, and solutions. During training, CodeContrast processes positive triplets (matching problem, test case, solution) and negative triplets (non-matching combinations) and uses a contrastive loss to position positive triplets close in the feature space while separating negative ones. Comprehensive evaluations of CodeContrast-through automatic metrics, expert ratings, and student studies-demonstrate its effectiveness. Results show high code correctness (92.3% of test cases passed), strong problem-solution alignment (BLEU score up to 0.826), and robust test case coverage (85.7% statement coverage). Expert feedback and student performance further support the pedagogical value of these generated exercises, with students performing comparably to those using manually curated content. CodeContrast advances the automated generation of high-quality programming exercises, capturing relationships among programming components to enhance educational content and improve the learning experience for students and instructors.
Keywords:
contrastive learning
programming exercise generation
computer science education
code generation
educational content creation

Journal

Education Sciences cover
Education Sciences
IF:
2.6
Papers:
3.1K
Citations:
1.2W

Organization

U
Universidad Tecnica Federico Santa Maria
Scholars:
3.0K
Papers: 3.1K
Citations: 25