Learning Program Embeddings to Propagate Feedback on Student Code

Chris Piech, Jonathan Huang, Andy Nguyen, Mike Phulsuksombati, Mehran Sahami, Leonidas Guibas

TL;DR

This paper introduces a novel neural network architecture that represents computer programs as linear operators acting on a latent feature space of program states. By embedding code into these continuous vector representations, the authors successfully automated the propagation of human-written feedback from a small set of graded assignments to millions of student submissions with high precision.

What Problem Does This Paper Address?

Massive Open Online Courses (MOOCs) can have millions of students, but providing personalized feedback remains a massive bottleneck. Traditional methods fall short: unit tests only check if a final answer is correct (ignoring style or intermediate logic), and Abstract Syntax Tree (AST) edit distances are often too coarse to distinguish between programs that look similar but behave differently.

The authors seek a way to "featurize" code that captures both functionality (what the code does) and style (how the code is written). The goal is "force multiplication"—allowing a teacher to grade a few hundred assignments and have those comments automatically and accurately applied to the remaining hundreds of thousands of submissions.

Methods

The core innovation is treating programs as linear mappings between program states.

  1. Embedding Hoare Triples: The authors use "Hoare triples"—a precondition ($P$), a program ($A$), and a postcondition ($Q$). They learn a non-linear encoder to map $P$ and $Q$ into a latent feature space ($f_P$ and $f_Q$). The program $A$ is then represented as a matrix $M_A$ such that $f_Q \approx M_A \cdot f_P$.
  2. Nonparametric Matrix Model (NPM): In this model, every unique program or subtree in the dataset is assigned its own matrix. The system jointly optimizes the state encoder/decoder and these program matrices to minimize prediction error.
  3. NPM-RNN: To capture stylistic elements, the authors use a Recursive Neural Network (RNN) that follows the structure of the program's AST. The representation of a code block is computed by combining the representations of its children with the functional matrix learned in the NPM phase.
  4. Feedback Propagation: Once programs are embedded as vectors, the authors treat feedback as a series of binary classification tasks. They also use active learning (k-means clustering) to identify which "exemplar" programs humans should grade first to maximize the reach of the propagation.
Figure 2. Diagram of the model for a program A implementing a simple “step forward” behavior in a small 1-dimensional gridworld. Two of the k Hoare triples that correspond with A are shown. Typical worlds are larger and programs are more complex.

Datasets

The model was evaluated on three distinct programming problems:

  • $\Omega_1$ (Hour of Code): A very large dataset (>11 million students) featuring a simple but conceptually tricky task involving nested logic (if/else inside a while loop).
  • $\Omega_2$ (Stanford CS1 - Karel): A basic task where a robot retrieves a "beeper" in a fixed grid world.
  • $\Omega_3$ (Stanford CS1 - Midpoint): A complex task requiring students to find the center of a grid of unknown size. This involves multiple valid strategies and higher algorithmic complexity.

Key Insights and Ideas

  • Programs as Matrices: The idea that a complex, non-linear program can be viewed as a linear operator in a high-dimensional latent space is powerful. It allows for composability: if program $C$ is just program $A$ followed by program $B$, then the matrix $M_C$ should be approximately $M_B \cdot M_A$.
  • Function vs. Style: While the NPM model is excellent at capturing what code does, the recursive RNN structure is necessary to capture how it does it. This distinction is crucial for pedagogical feedback, where two functionally identical programs might deserve different comments based on their efficiency or decomposition.
  • Complexity Scaling: The authors found that while simple parametric models (like a standard RNN) work well for simple code, the nonparametric approach (NPM) is far more robust as program complexity (measured by cyclomatic complexity) increases.
Figure 1. We learn matrices which capture functionality. Left: a student partial solution. Right: learned matrices for the syntax trees rooted at each node of placeRow.

Key Results

  • Force Multiplication: The system achieved staggering force multiplication factors while maintaining 90% precision. For the Hour of Code ($\Omega_1$), human effort was multiplied by 214x. For the complex Stanford assignment ($\Omega_3$), it achieved a 45x multiplier.
  • Predictive Accuracy: The NPM model predicted postconditions with high accuracy (up to 98% on training sets and 81-95% on test sets), significantly outperforming baselines.
  • Feedback Type Performance: The model was most effective at propagating functional feedback (44% recall at 90% precision) and strategic feedback (31% recall), but struggled more with purely stylistic annotations (8% recall).
Recall vs. Precision curves for the three problems, showing the NPM-RNN outperforming baselines.

Limitations and Future Work

  • User-Defined Variables: The current experiments were conducted in "grid world" environments without user-defined variables. Mapping arbitrary program memory into a vector space remains an open challenge.
  • Data Requirements: The nonparametric approach requires a large number of submissions per problem to learn effective embeddings, which might not be available for smaller, niche courses.
  • General Computation: The authors acknowledge that their current linear mapping approach cannot represent arbitrary computation (in the Church-Turing sense). They point toward "Neural Turing Machines" as a potential future direction for more expressive code reasoning.

Summary updated

BibTeX
@inproceedings{piech2015learning,
  author = {Chris Piech and Jonathan Huang and Andy Nguyen and Mike Phulsuksombati and Mehran Sahami and Leonidas Guibas},
  title = {{Learning Program Embeddings to Propagate Feedback on Student Code}},
  booktitle = {International Conference on Machine Learning},
  year = {2015},
  url = {https://openreview.net/forum?id=Bk-AVh-dZB},
}
Figure