← Index

DoM: Math Problems to Computation Graphs

A PyTorch transformer that generates structured math programs, with correct and incorrect decodes to inspect.

FIG. 07 — Selected correct decode: an 18-operation payroll program. Aggregate scores come from the course report.

Problem

Math word problems require translating language into operations. A model can produce either a malformed program or a valid program that solves the wrong problem; those failures need separate evaluation.

Approach

Trained a decoder-only sequence-to-sequence transformer on MathQA and restricted decoding choices to valid graph structure. Compared generated computation graphs with reference programs.

What I built

Co-developed the tokenizer, data loader, model, training loop, and constrained decoding in PyTorch. Analyzed successful decodes alongside over-generation and missing-operation errors.

Result

The coauthored course report records 77.45% exact graph match, 84.78% 2-gram BLEU, and 2.72 average graph edit distance. Structural constraints do not guarantee the mathematical answer is correct.

Inspect the remaining errors

The constrained decoder can produce a valid graph with extra operations or omit steps the problem requires. Showing an incorrect decode beside a success separates structural validity from semantic accuracy.

FIG. 07A — Selected failure: a valid structure with missing operations.
Decoder-only transformer used to generate computation-graph tokens.
FIG. 07B — Tokenizer, decoder, and structured output pipeline.

Paper

  1. Page 1 of DoM: Math Problems to Computation Graphs
  2. Page 2 of DoM: Math Problems to Computation Graphs
  3. Page 3 of DoM: Math Problems to Computation Graphs
  4. Page 4 of DoM: Math Problems to Computation Graphs
  5. Page 5 of DoM: Math Problems to Computation Graphs

Scroll sideways to read · open the PDF

Stack

Links