1 Introduction
Computerassisted education promises open access to worldclass instruction and a reduction in the growing cost of learning [2]. A major barrier to this promise of scalable education is the need to automatically provide feedback on student work.
Learning to provide feedback has proven to be a hard machine learning problem. Despite dozens of projects that combine massive education data with cuttingedge deep learning in NeurIPS and beyond
[16; 1; 28; 23; 15; 10], most approaches fall short. Five issues have emerged: (1) student work is Zipf distributed and as such most incorrect solutions are unique even in large corpora, (2) student work is hard and expensive to label, (3) we want to provide feedback (without historical data) for even the very first student, (4) there is a high human cost to inaccurate predictions, and (5) predictions must be explainable to instructors and students. These challenges are typical of many humancentred AI problems, such as diagnosing rare diseases.Rather than labelling student solutions, experts are much more adept at thinking “generatively”: they can easily imagine the misconceptions a student might have, and construct the space of solutions a student with these misconceptions would produce. Recently, Wu et al. [26]
used this intuition to show that a neural network trained on samples from a teacherwritten probabilistic context free grammar (PCFG) describing student decisions outperforms a datahungry supervised neural network and a deep generative model
[24]. While groundbreaking, it is difficult for experts to write cognitive models in the form of PCFGs when assignments are complex and openended. Further, the inference techniques of [26] do not scale well to very large grammars. The technical contributions of our work are to address these issues by introducing a more flexible generative model class for describing assignment solutions and providing an inference technique able to handle this class.In this paper we introduce a probabilistic program based grammar; an expressive class that allows for the functional transformations and complex variable dependencies supported by probabilistic programming languages (PPL). However, with added power, this class presents a challenging inference problem. In response, we develop Neural Approximate Parsing (GGNAP) with two important ideas: (1) to handle complex contextsensitivity, GGNAP learns to parse as a form of compiled inference, and (2) to handle the longtailed nature of these generative distributions, GGNAP is trained via “adaptive" sampling that ensures sufficient resolution in the tails. While we explore it for the education domain, we believe GGNAP will be useful for many simulationbased modelling applications.
When we apply GGNAP to openaccess datasets we are able to grade student work with close to expert humanlevel fidelity, substantially improving upon the state of the art across a spectrum of public education datasets: introduction to computer programming, short answers to a US citizenship test and graphicsbased programs. We show a 50%, 160% and 350% improvement above the state of the art, respectively. When used with human verification in a real classroom, we are able to double grading accuracy while reducing by half the grading time. Moreover, the grading decisions made by our algorithm are auditable and interpretable by an expert teacher. Our algorithm is “zeroshot" and thus works for the very first student. Since predicted labels correspond to meaningful cognitive states, not merely grades, they can be used in many ways: to give hints to students without teachers, or to help teachers understand their class, etc.

1.1 Datasets
We consider four educational contexts. Fig. 0(a) shows example solutions for each problem.
Code.org (Block Coding) Wu et al. [26] released a dataset of student responses to 8 exercises from Code.org, involving drawing shapes with nested loops. We take the most difficult problem—drawing polygons with an increasing number of sides—which has 302 human graded responses with 26 labels regarding looping and geometry (e.g. “missing for loop” or “incorrect angle”).
Powergrading (Language)
Powergrading [1] contains 700 responses to a US citizenship exam, each graded for correctness by 3 humans. Responses are in natural language, but are typically short (average of 4.2 words). We focus on the most difficult question, as measured by [17]: “name one reason the original colonists came to America". Responses span economics, politics, and religion.
PyramidSnapshot (Graphics)
PyramidSnapshot is a university CS1 course assignment intended to be a student’s first exposure to variables, objects, and loops. The task is to build a pyramid using Java’s ACM graphics library. The dataset is composed of images of rendered pyramids from intermediary “snapshots" of student work. Yan et al. [28] annotated 12k unique snapshots with 5 categoies representing “knowledge stages" of understanding.
Liftoff (Java)
Liftoff is another assignment in a CS1 course. Students write a program that prints a countdown from 10 to 1 followed by the phrase "Liftoff". We use GGNAP with human verification to grade 176 solutions from a semester of students and measure accuracy and grading time.
1.2 The Grading Task
There are two important machine learning tasks related to grading. First, autopredicting feedback, or labelling a given student solution with meaningful mistakes. Second, verifiable nearest neighbour, an alternative when the cost of grading errors is high, in which the algorithm produces a nearest neighbour example whose feedback can be verified with respect to the expert grammar. This system can work with a humanintheloop, who focuses on the differences between solutions, to achieve superhuman grading precision while reducing grading time.
1.3 Generative Grading
We approach these grading problems by having an expert describe the decisions students make and their resulting answer to an assignment. If we can instantiate these expert priors as a real generative model (e.g. grammar), then we possess a simulator from which we can sample infinite amounts of labelled data, allowing for zeroshot (in terms of real data) learning. While generating solutions to large problems is difficult, representing the prior as a hierarchical set of decisions allows decomposition of this hard task into simpler ones, making it surprisingly easy for experts to express their knowledge. The challenge is then defining a robust enough class of probabilistic models (Sec. 3.2) that can capture the complexities of expert priors (and student behaviour), and constructing the machinery needed to infer student thinking from their solutions (Sec. 3.3). Figure 2 shows a pictorial representation of the generative model we use for the Powergrading task and samples that it produces. Theoretical inspiration for our grammars derives from Brown’s “Repair Theory" which argues that the best way to help students is to understand the generative origins of their mistakes [4].
2 Neural Parsing for Inference in Grammars
In this section, we define the class of grammars called Probabilistic Program Grammars and describe several motivating properties that make them useful for generative grading.
2.1 Probabilistic Program Grammar
We aim to describe a class of grammars powerful enough to easily encode any instructor’s knowledge of the student decisionmaking process. While it is easy to reason about context free grammars, context independence is a strong restriction that generally limits what instructors can express. As an example, imagine capturing the intuition that students can write a for loop two ways:
Clearly, the decision for the for loop header (i < 0; i++), and print statement are dependent on the start index (i = 0) and the choice of variable name (i) as are future decisions like offbyone. Coordinating these decisions in a contextfree grammar requires a great profusion of nonterminals and production rules, which are burdensome for a human to create. Generally, the ability to express arbitrary functional relationships between variables in the grammar is crucial for real world applications. For instance, for capturing method decomposition in programming code or tense and sentence structure in natural language—basic building blocks for a good generative model in education.
We thus introduce a broader class of grammars called Probabilistic Program Grammars (PPGs) that enable us to condition choices on previous decisions and a globally accessible state. A Probabilistic Program Grammar is more rigorously defined as a subclass of general probabilistic programs, equipped with a tuple denoting a set of nonterminals, a set of terminals, a start node, a global state, and a set of probabilistic programs, respectively. A production from the grammar is a recursive generation from the start node to a sequence of terminals based on production rules. Unlike PCFGs, a production rule is described by a probabilistic program
so that a given nonterminal can be expanded in different ways based on samples from random variables in
, the shared state , and contextual information about other nonterminals rendered in the production. Further, the production rule can also modify the global state , thus affecting the behaviour of future nonterminals. Lastly, the PPG can transform the final sequence of terminals into an arbitrary space (e.g. from strings to images), to yield the production . Each derivation is associated with a trajectory of nonterminals^{1}^{1}1Note that the length of the trajectory can vary for different . encountered during execution. Here, denotes a unique lexical identifier for each random variable encountered in order andstores the specific value that was sampled. Define the joint distribution (induced by
) over trajectories and productions as . We refer to the procedure of generating a sample as .Given such a grammar, we are interested in parsing: this is the task of mapping a production to the most likely trajectory, that could have produced . This is a difficult search problem: the number of trajectories grows exponentially even for simple grammars, and common methods for parsing by dynamic programming (Viterbi, CKY) are not applicable in the presence of contextsensitivity and functional transformations. To make this problem tractable, we present deep neural networks to approximate the posterior distribution over trajectories. We call this approach neural approximate parsing with generative grading, or GGNAP.
2.2 Neural Inference Engine
The challenge of doing inference over trajectories is a difficult one. Trajectories can vary in length and contain nonterminals with different support. To approach this with neural nets, we decompose the inference task into a set of easier subtasks. The posterior distribution over a trajectory given a yield can be written as the product of individual posteriors over each nonterminal
using the chain rule:
(1) 
where denotes previous nonterminals . Eqn. 1 shows that we can learn each posterior separately. With an RNN, we efficiently represent the influence of previous nonterminals
autoregressively using a shared hidden representation over
timesteps. To encode the production , we use standard machinery (e.g. CNNs for images, RNNs for text). To allow for nonterminals with different support, we define three layers for each random variable : (1) an index embedding layer that maps indexto a fixed dimension vector, (2) a value embedding layer that maps the value of
to a fixed dimension vector and (3) an inference layer that transforms the RNN hidden state into parameters of the posterior for the next nonterminal . Thus, the input to the RNN is fixed, being the concatenation of the value embedding, index embedding, and production encoding.To train the GGNAP, we optimize the objective,
(2) 
where are all trainable parameters and represents the posterior distribution defined by the inference engine^{2}^{2}2Since we are given , we can parameterise to be from the correct distributional family.
. The second equality is a Monte Carlo estimate using a dataset of samples
from . At test time, given only a production , GGNAP recursively samples for and uses this sample as the input to the next RNN step, like in usual sequence generation models [8].2.3 Relationship to Viterbi Parsing
In [26], the authors released PCFGs for two exercises from Code.org (P1 and P8) that produce code. These grammars are large: P1 has 3k production rules whereas P8 has 263k. Given a PCFG,
PCFG  Trajectory Acc. 

Code.org P1 (MAP)  0.943 
Code.org P1 (bestof10)  0.987 
Code.org P8 (MAP)  0.917 
Code.org P8 (bestof10)  0.921 
PCFG  Parser  # Production Rules  Cost (Sec.) 

Code.org P1  Viterbi  3k  0.79 1.2 
Code.org P1  NAP  3k  0.17 0.1 
Code.org P8  Viterbi  263k  182.8 40.2 
Code.org P8  NAP  263k  0.25 0.2 
we compare GGNAP to Viterbi (CYK) in terms of retrieving the correct trajectory for productions from the grammar. We measure trajectory accuracy: the fraction of nodes that are in both parses.
Using 5k samples from each PCFG, we found trajectory accuracies of 94% and 92% for P1 and P8 respectively, meaning that Viterbi and GGNAP agree in almost all cases. Further, if we draw multiple samples from the GGNAP posterior and take the best one, we find improvements of up to 4%. In exchange for being approximate, GGNAP is not restricted to PCFGs, can invert transformations on productions, and is orders of magnitude faster than Viterbi (0.3 vs 183 sec).
2.4 Verifiable Nearest Neighbour Retrieval
Given a production from a grammar , the GGNAP algorithm can provide a verifiable certificate for its predicted parsing. Let refer to the inferred trajectory for and refer to the true (unknown) trajectory. If we repeatedly call while fixing the values for each encountered random variable to , then we should be able to generate the exact production , showing with certainty that . In practice, very few samples are needed to recover . On the other hand, if an observation is not in the grammar (like some real student programs), is not welldefined and the inferred trajectory will be incorrect. However, will be still specify a production that we can interpret as an approximate nearest neighbour to in . Intuitively, we expect and to be “similar" semantically as specified by the nonterminals in . In practice, we can measure a domainspecific distance between and e.g. token edit distance for text.
2.5 Nearest Neighbour Baseline
We present a strong baseline that is also capable of performing verifiable approximate parsing. This algorithm is simply a
nearest neighbour classifier: we generate and store a dataset
with hundreds of thousands of unique productions as well as their associated trajectories. At test time, given an input to parse, we can find its nearest neighbour in the stored samples and return its associated trajectory. If the neighbour is an exact match, the prediction is verifiable. We refer to this baseline as GGkNN. Depending on the grammar,
will be in a different output space (images, code, text) and thus the distance metric used for GGkNN will be domain dependent.2.6 Adaptive Sampling
As both GGkNN and GGNAP require a dataset of samples for training, we must be able to generate unique productions from a grammar efficiently. For GGkNN specifically, the number of unique productions strictly defines the quality of the model. However, due to the nature of Zipfs, generating unique data points can be expensive due to oversampling of the most common productions. Furthermore, a second concern is that we do not want to completely ignore the prior distributions defined by the grammar. Otherwise we would sample very unlikely (albeit unique) productions that do not describe student behaviour.
To balance competing interests, we present a novel method called Adaptive Grammar Sampling that downweights the probabilities of decisions proportional to how many times they lead to duplicate productions. This algorithm has many useful properties and is based on MonteCarlo Tree Search and the WangLandau algorithm from statistical physics. We consider this an interesting corollary and refer the reader to the supplement. Fig.
7 shows an example of how much more efficient this algorithm is compared to simply sampling naively from the Liftoff grammar by plotting the GoodTuring estimates (probability of encountering an unseen program) over the number of samples made so far. In practice, adaptive sampling has a parameter that can be toggled to control how fast we explore the Zipf, allowing us to preserve likely productions from the head and body.3 Results
For the task of inferring student understanding, we find that GGNAP beats the previous stateoftheart (SOTA) by a significant margin in all four educational domains. Further, it approaches (or surpasses) human performance (see Fig. 4). Below, we first describe GGNAP’s performance on labelled datasets as compared to previous work followed by its performance when used for grading student code in a real classroom.
To evaluate our models, we separately calculate performance for different regions of the Zipf: we define the head as the most popular solutions, the tail as solutions that appear only once or twice, and the body as the rest. As solutions in the head can be memorised, we focus on the body and tail.
3.1 Autonomous Grading
In each domain, we are given a dataset of student programs and labelled feedback. By design, we include each of the labels as a nonterminal in the grammar, thereby reducing prediction to parsing.
Code.org
GGNAP sets the new SOTA on the dataset, beating [26] in both the body and tail, and surpassing human performance (historically measured as F1). There is a rich history of previous work involving supervised classifiers [26; 23] that struggled with the tiny amount of labelled data, resulting in poor performance. Even some zeroshot approaches like [26], which trains an RNN on synthetically labelled samples from an expertdesigned PCFG, are significantly below human quality. The potential impact of a humanlevel autonomous grader is large: Code.org is used by 610 million students worldwide, and has unsuccessfully launched initiatives in the past to crowdsource feedback for student solutions. Instead of thousands of human hours of teacher work, GGNAP could provide the same quality of feedback at scale.
Powergrading
For this open dataset of short answer responses, GGNAP outperforms the previous SOTA with an F1 score of 0.93, an increase of 0.35 points. We close the gap to human performance, measured to be F1 = 0.97 (which generously considers the majority of the three raters to be the gold label). Earlier work either used handcrafted features for natural language [6] or the latest supervised neural network architecture [17]. With 700 labelled data points, these methods heavily overfit to the training set. Further, since the Powergrading task is unique in that it contains natural language, the PPG we designed had to explain variations both in writing style and in semantic understanding. The strong performance of GGNAP suggests that even beyond education, the idea of representing expert priors as expressive simulators can be generalised to many domains.
PyramidSnapshot
As in the last two cases, GGNAP is the new SOTA, outperforming baselines (kNN between images and a VGG classifier) from [28] that are trained on 200 labelled images by about a 50% gain in accuracy. Unlike other datasets, PyramidSnapshot includes student’s intermediary work, showing stages of progression through multiple attempts at solving the problem. With our nearhuman level performance, instructors could use GGNAP to measure student cognitive understanding over time as students work. This builds in a realtime feedback loop between the student and teacher that enables a quick and accurate way of assessing teaching quality and characterising both individual and classroom learning progress. From a technical perspective, since PyramidSnapshot only includes rendered images (and not student code), GGNAP was responsible for parsing student understanding from unstructured images, a feat not possible with simpler grammars like PCFGs.
3.2 Human Guided Grading
While good performance on benchmark datasets is promising, a true test of an algorithm is its effectiveness in the real world. For GGNAP, we would like to gauge its impact on grading accuracy and speed in a real classroom setting. We hired a cohort of expert graders (teaching assistants from a large private university with similar experience) to each grade 30 real student solutions to Liftoff, a university course assignment. For each student solution, we also retrieve the autograded nearest neighbour using GGNAP. (As an aside, GGNAP excels at finding semantically relevant neighbours compared to baseline methods. Fig. 5 compares the token edit distance between the student program and the nearest neighbours retrieved by GGNAP versus GGkNN, finding significantly better matches with the former.) For control, half the graders proceed normally, assigning a set of feedback labels measuring understanding of looping concepts by analysing student solutions. The other half of graders additionally have access to (1) the feedback assigned to the nearest neighbour by GGNAP and (2) a code diff between the student program and the nearest neighbour. Some example feedback labels include “off by one increment", “uses while loop", or “confused > with <". All grading is done on a web application that keeps track of the time taken for the grader to grade a problem.
We found that the average time (to grade 30 problems) for graders with GGNAP is 507 sec. Without GGNAP, the average time is 1130 sec, a more than double increase. With GGNAP, 3 grading errors were made with respect to goldstandard feedback given by the course Professor. Without GGNAP, 8 errors were made. By halving both the number of errors and the amount of time, GGNAP can have a large impact in classrooms today, saving instructors and teaching assistants unnecessary hours and worry over grading assignments.
4 Related Work
“Rubric sampling” [26] first introduced the concept of encoding expert priors in grammars of student decisions, and was the inspiration for our work. The authors design PCFGs to curate synthetically labelled datasets to train a supervised classifier. Our approach builds on this, but GGNAP operates on a more expressive family of grammars that are context sensitive. Due to this complexity, new innovations were required to effectively do inference. From Code.org, we see that expressivity is responsible for pushing GGNAP past human level performance. Further, our paradigm adds an important notion of verifiability lacking in previous work. Rubric sampling as previously presented suffers from the blackbox nature of neural networks.
Inference over grammar trajectories is similar to “compiled inference" for execution traces in probabilistic programs. As such, our inference engine shares similarities to PPL literature [14]
. By limiting ourselves to a class of grammars, we get a nice interpretation of compiled inference as a parsing algorithm. Further, we show the promise of compiled inference in much larger probabilistic programs (with skewed prior distributions). Previous work
[14; 27; 13] usually involve 4 or 5 random variables whereas our grammars grow to hundreds.The design of PPGs also draws on many influences from natural language processing. For starters, our neural inference engine can be viewed as an encoder (or “inference network") in a RNNbased variational autoencoder
[3]that specifies a posterior distribution over many categorical variables. Further, the index embedding layer serves as a unique identifier similar to the positional encoding in transformers
[21]. Finally, the verifiable properties of GGNAP have strong ties to explainable AI [19; 9; 12], especially in the healthcare domain [25; 18] where interpretability is paramount.5 Discussion
Highlighting feedback in student solutions
Rather than predicting feedback labels, it would be even more useful to provide “dense" feedback that highlights the section of the code or text responsible for the student misunderstanding. To achieve this, we use GGNAP to infer a trajectory, for a given production . For every nonterminal , we want to measure its impact on . If for each we have an associated production rule with an intermediate output , then highlighting amounts to finding the part of which was responsible for. Fig. 6 shows a random program with automated, segmentspecific feedback given by GGNAP. This level of explainability is sorely needed in both online education and AI and could revolutionise how students are given feedback at scale.
Automatically improving grammars
Building PPGs is an iterative process, requiring time for improvements in design. A user wishing to improve a PPG would like a sense of where their grammar is lacking. Fortunately, given a set of difficult examples where GGNAP does poorly, we can deduce the set of nodes in the PPG that consistently led to mistakes. To illustrate this, we took the Liftoff PPG which crucially contains a node that decides between incrementing up or down in a “for" loop, and removed the option of incrementing down. If we train GGNAP on the smaller PPG, we will fail to parse examples that “increment down". In this case, the set of nodes that consistently led to mistakes all related to incrementation. At this time, an expert can quickly diagnose the issue.
Need for probabilistic program grammars
In practice, we have experienced the benefits of having a grammar which allows for the full expressivity of a computer program. One nonobvious benefit of having state is the ability to break independence assumptions between mistakes. If a PCFG describes different places where a student could err, as tends towards infinity it will be increasingly improbable to produce a sample with only one mistake, which we know to be a very common case among students. A PPG allows for a natural way to have a continuous ability for students which can model the binomial phenomena of either making many mistakes or only a few. Adding ability as a state alone increased the F1 scores for Code.org by 0.1 points.
Not only experts can write good grammars.
Writing a good grammar does not require immense experience. For instance, the PyramidSnapshot grammar that sets the new SOTA was written by a firstyear undergraduate. Further, grammars are reusable: similar assignments will share nonterminals and some invariances (e.g. all the ways of writing i++ are the same everywhere).
6 Conclusion
In this paper we make novel contributions to the task of providing automated student feedback that beats numerous stateoftheart approaches and shows significant impact when used in practice. The ability to finely predict student decisions opens up many doors in education. This work could be used to automate feedback, visualise student approaches for instructors, and make grading easier, faster, and more consistent. Although more work needs to be done on making powerful grammars easier to write, we believe this is an exciting direction for the future of education and a huge step in the quest for combining machine learning and humancentred artificial intelligence.
References
 Basu et al. [2013] S. Basu, C. Jacobs, and L. Vanderwende. Powergrading: a clustering approach to amplify human effort for short answer grading. Transactions of the Association for Computational Linguistics, 1:391–402, 2013.
 Bowen [2012] W. G. Bowen. The ‘cost disease’in higher education: is technology the answer? The Tanner Lectures Stanford University, 2012.
 Bowman et al. [2015] S. R. Bowman, L. Vilnis, O. Vinyals, A. M. Dai, R. Jozefowicz, and S. Bengio. Generating sentences from a continuous space. arXiv preprint arXiv:1511.06349, 2015.
 Brown and VanLehn [1980] J. S. Brown and K. VanLehn. Repair theory: A generative theory of bugs in procedural skills. Cognitive science, 4(4):379–426, 1980.

Chang et al. [2005]
H. S. Chang, M. C. Fu, J. Hu, and S. I. Marcus.
An adaptive sampling algorithm for solving markov decision processes.
Operations Research, 53(1):126–139, 2005. doi: 10.1287/opre.1040.0145. 
Daxenberger et al. [2014]
J. Daxenberger, O. Ferschke, I. Gurevych, and T. Zesch.
Dkpro tc: A javabased framework for supervised learning experiments on textual data.
In Proceedings of 52nd Annual Meeting of the Association for Computational Linguistics: System Demonstrations, pages 61–66, 2014.  Glorot and Bengio [2010] X. Glorot and Y. Bengio. Understanding the difficulty of training deep feedforward neural networks. In Proceedings of the thirteenth international conference on artificial intelligence and statistics, pages 249–256, 2010.
 Graves [2013] A. Graves. Generating sequences with recurrent neural networks. CoRR, abs/1308.0850, 2013. URL http://arxiv.org/abs/1308.0850.
 Hancock et al. [2018] B. Hancock, P. Varma, S. Wang, M. Bringmann, P. Liang, and C. Ré. Training classifiers with natural language explanations. arXiv preprint arXiv:1805.03818, 2018.
 Hu and Rangwala [2019] Q. Hu and H. Rangwala. Reliable deep grade prediction with uncertainty estimation. arXiv preprint arXiv:1902.10213, 2019.
 Kingma and Ba [2014] D. P. Kingma and J. Ba. Adam: A method for stochastic optimization. arXiv preprint arXiv:1412.6980, 2014.
 Koh and Liang [2017] P. W. Koh and P. Liang. Understanding blackbox predictions via influence functions. In Proceedings of the 34th International Conference on Machine LearningVolume 70, pages 1885–1894. JMLR. org, 2017.
 Lake et al. [2015] B. M. Lake, R. Salakhutdinov, and J. B. Tenenbaum. Humanlevel concept learning through probabilistic program induction. Science, 350(6266):1332–1338, 2015.
 Le et al. [2016] T. A. Le, A. G. Baydin, and F. Wood. Inference compilation and universal probabilistic programming. arXiv preprint arXiv:1610.09900, 2016.
 Liu et al. [2019] J. Liu, Y. Xu, and L. Zhao. Automated essay scoring based on twostage learning. arXiv preprint arXiv:1901.07744, 2019.
 Piech et al. [2015] C. Piech, J. Bassen, J. Huang, S. Ganguli, M. Sahami, L. J. Guibas, and J. SohlDickstein. Deep knowledge tracing. In Advances in neural information processing systems, pages 505–513, 2015.
 Riordan et al. [2017] B. Riordan, A. Horbach, A. Cahill, T. Zesch, and C. M. Lee. Investigating neural architectures for short answer scoring. In Proceedings of the 12th Workshop on Innovative Use of NLP for Building Educational Applications, pages 159–168, 2017.
 Ross and DoshiVelez [2018] A. S. Ross and F. DoshiVelez. Improving the adversarial robustness and interpretability of deep neural networks by regularizing their input gradients. In Thirtysecond AAAI conference on artificial intelligence, 2018.

Selvaraju et al. [2017]
R. R. Selvaraju, M. Cogswell, A. Das, R. Vedantam, D. Parikh, and D. Batra.
Gradcam: Visual explanations from deep networks via gradientbased
localization.
In
Proceedings of the IEEE International Conference on Computer Vision
, pages 618–626, 2017.  Simonyan and Zisserman [2014] K. Simonyan and A. Zisserman. Very deep convolutional networks for largescale image recognition. arXiv preprint arXiv:1409.1556, 2014.
 Vaswani et al. [2017] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin. Attention is all you need. In Advances in neural information processing systems, pages 5998–6008, 2017.
 Wang and Landau [2001] F. Wang and D. Landau. Efficient, multiplerange random walk algorithm to calculate the density of states. Physical review letters, 86:2050–3, 04 2001. doi: 10.1103/PhysRevLett.86.2050.
 Wang et al. [2017] L. Wang, A. Sy, L. Liu, and C. Piech. Learning to represent student knowledge on programming exercises using deep learning. In EDM, 2017.
 Wu and Goodman [2018] M. Wu and N. Goodman. Multimodal generative models for scalable weaklysupervised learning. In Advances in Neural Information Processing Systems, pages 5575–5585, 2018.
 Wu et al. [2018a] M. Wu, M. C. Hughes, S. Parbhoo, M. Zazzi, V. Roth, and F. DoshiVelez. Beyond sparsity: Tree regularization of deep models for interpretability. In ThirtySecond AAAI Conference on Artificial Intelligence, 2018a.
 Wu et al. [2018b] M. Wu, M. Mosse, N. Goodman, and C. Piech. Zero shot learning for code education: Rubric sampling with deep learning inference. arXiv preprint arXiv:1809.01357, 2018b.
 Wu et al. [2016] Y. Wu, L. Li, S. Russell, and R. Bodik. Swift: Compiled inference for probabilistic programming languages. arXiv preprint arXiv:1606.09242, 2016.
 Yan et al. [2019] L. Yan, N. McKeown, and C. Piech. The pyramidsnapshot challenge: Understanding student process from visual output of programs. In Proceedings of the 50th ACM Technical Symposium on Computer Science Education, SIGCSE ’19, pages 119–125, New York, NY, USA, 2019. ACM. ISBN 9781450358903. doi: 10.1145/3287324.3287386. URL http://doi.acm.org/10.1145/3287324.3287386.
Appendix A Model Hyperparameters
For reproducibility, we include all hyperparameters used in training GGNAP. Unless otherwise stated, we use a batch size of 64, train for 10 or 20 epochs on 100k samples from a PPG. The default learning rate is 5e4 with a weight decay of 1e7. We use Adam
[Kingma and Ba, 2014] for optimization. If the encoder network is an RNN, we use the Elman network with 4 layers, a hidden size of 256, and a probability of dropping out hidden units of 1%. If the encoder network is a CNN, we train VGG11 [Simonyan and Zisserman, 2014] with Xavier initialization [Glorot and Bengio, 2010]from scratch. For training VGG, we found it important to lower the learning rate to 1e5. The neural inference engine itself is an unrolled RNN: we use a gated recurrent unit with a hidden dimension of 256 and no dropout. The value and index embedding layers output a vector of dimension 32. These hyperparameters were chosen using grid search.
Appendix B Adaptive Grammar Sampling
In the text, we introduced a nearest neighbour baseline (KNN) for verifiable parsing. The success of KNN is highly dependent on storing a set of unique samples. With Zipfs, i.i.d. sampling often oversamples from the head of the distribution, resulting in a low count of unique samples and poor performance. To build a strong baseline, we must sample uniques more efficiently.
Further, training the neural inference engine requires sampling a dataset from a PPG . These samples need to cover enough of the grammar to allow the model to learn meaningful representations and, moreover, they again need to be unique. The uniqueness requirement is paramount for Zipfs since otherwise models would be overwhelmed by the most probable samples.
Naively, we can i.i.d. sample a set of unique observations and use it train NAP. However, again, due to the Zipfian nature, generating unique data points can be expensive as gets large due to having to discard duplicates. To sample efficiently, a simple idea is to pick each decision uniformly (we call this uniform sampling). Although this will generate uniques more often, it has two major issues: (1) it disregards the priors, resulting in very unlikely productions, and (2) it might not be effective as multiple paths can lead to the same production.
Ideally, we would sample in a manner such that we cover all the most likely programs and then smoothly transition into sampling increasingly unlikely programs. This would generate uniques efficiently while also retaining samples that are relatively likely. To address these desiderata, we propose a method called Adaptive Grammar Sampling (Alg. 1) that downweights the probabilities of decisions proportional to how many times they lead to duplicate productions. We avoid overly punishing nodes early in the decision trace by discounting the downweighting by a decay factor . This method is inspired by MonteCarlo Tree Search [Chang et al., 2005] and shares similarities with WangLandau from statistical physics [Wang and Landau, 2001].

b.1 Properties of Adaptive Sampling
In the main text, we expressed the belief that adaptive grammar sampling increases the likelihood of generating unique samples. To test this hypothesis, we sampled 10k (nonunique) Java programs using the Liftoff PPG and track the number of uniques over time. Fig. 7a shows that adaptive sampling has linear growth in number of unique programs compared to sublinear growth with i.i.d. or uniform sampling. Fig. 7b compute the GoodTuring estimate, a measure for the probability of the next sample being unique, and found adaptive sampling to “converge" to a constant while other sampling methods approach zero. Interestingly, adaptive sampling is customisable. Fig. 7c show the log probability of the sampled trajectories over time. With higher reward or a smaller decay rate , adaptive sampling will sample less from the head/body of the Zipf. In contexts where we care about the rate of sample exploration, adaptive sampling provides a tuneable algorithm to search a distribution.
Appendix C Grammar Descriptions
We provide an overview of the grammars for each domain, covering the important choices.
Code.org P8
This PPG contains 52 decisions. The primary innovation in this grammar decision is the use of a global random variable that represents the ability of the student. In this turn will affect the distributions over values for nonterminals later in the trajectory such as deciding the loop structure and body. The intuition this captures is that high ability students make very few to no mistakes whereas low ability students tend to make many correlated misunderstandings (e.g. looping and recursion).
CS1: Liftoff
This PPG contains 26 decisions. It first determines whether to use a loop, and, if so, chooses between “for" and “while" loop structures. It then formulates the loop syntax, choosing a condition statement and whether to count up or count down. Finally, it chooses the syntax of the print statements. Notably, each choice is dependent on previous ones. For example, choosing an end value in a for loop is sensibly conditioned on a chosen start value.
Powergrading: Short Answer
This PPG contains 53 nodes. Unlike code, grammars over natural language need to explain variance in both semantic meaning and prose. This is not as difficult for short sentences. In designing the grammar, we inspect the first 100 responses to gauge student thinking. Procedurally, the grammar’s first decision is choosing whether the production will be correct or incorrect. It then chooses a subject, verb, and noun. These three choices are dependent on the correctness. Correct answers lead to topics like religion, politics, and economics while incorrect answers are about taxation, exploration, or physical goods. Finally, the grammar chooses a writing style to craft a sentence. To capture variations in tense, we use a conjugator
^{3}^{3}3Python’s mlconjug library: https://pypi.org/project/mlconjug. as a functional transformation on the output.PyramidSnapshot
The grammar contains 121 nodes, the first of which decides between 13 “strategies" (e.g. making a parallelogram, right triangle, a brick wall, etc.). Each of the 13 options leads its own set of nodes that are responsible for deciding shape, location, and colour. Finally, the trajectory of decisions is used to render an image. The first version of the grammar was created by peaking at 200 images. A second version was updated by viewing 50 more.
Appendix D NAP Architecture
Fig. 8 visualizes the architecture for the neural inference engine in NAP. Critically, NodeEmbeddingLayer, IndexEmbeddingLayer, and InferenceLayer are specific to each nonterminal to support arbitrary dimensionality and distributions for random variables. The EncoderNetwork is responsible for transforming unstructured images and text to vector space.
Appendix E Grading UI
We show an image of the userinterface used in the field experiment. This is the view a grader (with access to NAP) would see. The real student response is give on the left and the nearest neighbour given by GGNAP on the right. A differential between the two images is provided, inspired by Github design. On the very right is a set of labels that the grader is responsible for assigning values to.
Appendix F Improving the Grammar
In the discussion of the main text, we introduced an experiment to test if we could detect nodes at which we were failing to parse outofdistribution examples: we took the Liftoff PPG (which crucially contains a node that decides between incrementing up or down in a “for" loop), and removed the option of incrementing down. If we train GGNAP on the smaller PPG, we will fail to parse examples that “increment down". In this case, the set of nodes that consistently led to mistakes all related to incrementation. Fig. 10 shows the distribution over which nodes GGNAP believes to be responsible for the failed parse. The top 6 nonterminals that GGMAP picked out related to looping and incrementation. As an expert, this is enough of a diagnosis to improve the grammar.
Comments
There are no comments yet.