Search

Search papers and lessons

Generative Language Modeling for Automated Theorem Proving

Stanislas Polu, Ilya Sutskever · 2020

GPT-f trains a Transformer to write the next step of a formal Metamath proof, then searches over those steps; the checker keeps only valid ones, and the best model proves about 56% of held-out theorems.

On this page

  • Colour = topic mix
  • Discrete math
  • Probability
  • Algorithms
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

GPT-f is a language model that writes mathematical proofs in a formal language. The authors train a Transformer to read a goal, a statement that still needs proving, and to write the next proof step. A search then expands the goals the model is most confident about, and a formal checker keeps only the steps that are valid. On the Metamath library the best model proves about 56% of a held-out set of theorems, where the previous best system proved 21%.

Builds on: Transformer, Language Model, Autoregressive Model, Value Function, Tree Search · Leads to: Let's Verify Step by Step

Why it mattered

The paper showed that a general text model, once it has been trained on enough formal proof steps, can do real formal reasoning. Before it, the best Metamath provers used several small recurrent networks, one to value goals, one to pick premises, and one to build substitutions. GPT-f replaced that stack with one decoder-only Transformer that writes each step as plain text.

The results left the lab. The authors contributed 23 shorter proofs to the Metamath library through community pull requests, and they report that the community found them valuable because proof length is something mathematicians care about. The authors say these were the first effective contributions of a deep learning system to a formal mathematics library. They also built an interactive proof assistant on the model. Users formalised more than 200 theorems and exercises with it, including a 1972 olympiad problem, and the assistant's suggestions were often close even when they were wrong.

The problem

Three things made formal theorem proving hard for neural networks.

First, the proofs are long. Metamath has no high-level tactics, so each step is a small logical move. The paper estimates that a Metamath proof is roughly 10 to 20 times the size of the informal argument it encodes, where Coq, HOL Light and Lean proofs are about 1 to 3 times. Long proofs mean more chances to go wrong.

Second, the search space explodes. A prover must pick a theorem to apply and the values to substitute into it. Most choices are dead ends, and the number of possible branches grows fast with depth.

Third, labelled data is scarce. The main library, set.mm, has about 38 thousand proofs, which is small compared with the text used to train language models. The proof checker can verify generated problems, so the authors built synthetic generators to create training data.

The question was whether a model trained on Metamath proof steps could learn enough to search effectively, and whether the search itself could be improved with a learned signal.

How it works

The system has two parts that feed each other: a language model that proposes proof steps, and a proof search that uses a checker to test them. Here is one tiny step traced from start to finish. The goal is the statement that three plus two equals five.

  1. The goal goes in as text. The model receives the goal as a string, written in the Metamath grammar. For this example it is the statement that (3 + 2) = 5.
  2. The model writes a proof step. A proof step is a theorem from the library plus a substitution, a choice of which expression fills each variable of the theorem. The model might choose the transitivity theorem for equality, with A set to (3 + 2), C set to 5, and B set to (4 + 1). Check: the theorem's conclusion A = C now reads (3 + 2) = 5, exactly the goal.
  3. The checker verifies the step. A small program confirms that the theorem's conclusion matches the goal after substitution and that the grammar is respected. If it passes, the two hypotheses of the theorem become new subgoals: (3 + 2) = (4 + 1) and (4 + 1) = 5. Check: each subgoal is a smaller question than the goal.
  4. A second step closes one subgoal. The statement (4 + 1) = 5 follows from the definition of the number five with no hypotheses, so that branch of the proof is finished. Check: no new subgoals are created.
  5. The search keeps going. The unsolved subgoal goes back into a queue. The search picks the next goal, asks the model for more steps, verifies them, and repeats until every branch is closed or the step budget runs out.

The search loop itself is short:

flowchart TD
  A["Queue of open goals, sorted by cumulative cost"] --> B["Take the goal with the lowest cost"]
  B --> C["Sample 32 proof steps from the model"]
  C --> D["Keep the steps the checker accepts"]
  D --> E["Add their subgoals to the tree and the queue"]
  E --> A

The authors call the whole procedure the GPT-f prover. Its verifier is a Metamath checker the authors wrote in Python, so that the search can call it without a slow round trip through an external program.

The math

The paper's ideas can be written in a few formulas. Symbols are named in words first.

A proof step is a pair of a goal g and a tactic s, where the tactic is a theorem and its substitutions. The model has parameters θ and assigns a probability to a whole proof step as text.

Step 1 in symbols: the model writes a proof step

The model reads the goal and then writes the proof step one token at a time, as an autoregressive model. Writing s_t for the t-th token of the step and s_{\lt t} for the tokens before it, the probability of the whole step is

pθ(s∣g)=∏t=1Tpθ(st∣g, s<t)p_\theta(s \mid g) = \prod_{t=1}^{T} p_\theta(s_t \mid g,\ s_{\lt t})

Training adjusts θ to make the true proof step likely. The loss is the negative log of that probability, summed over the tokens of the step. The goal tokens are present as context but do not contribute to the loss.

L(θ)=−∑t=1Tlog⁡pθ(st∣g, s<t)\mathcal{L}(\theta) = -\sum_{t=1}^{T} \log p_\theta(s_t \mid g,\ s_{\lt t})

Step 2 in symbols: sample many candidate steps

When the search expands a goal, it draws e = 32 samples s^{(1)}, \dots, s^{(e)} from the model at temperature 1, meaning the samples follow the model's probabilities without sharpening or flattening them. Duplicates are removed, and only the samples the checker accepts become children of the goal.

Step 3 in symbols: the cost of a path

Each goal sits at the end of a path of steps from the root. Let the path be goals g_0, g_1, \dots, g_k linked by steps s_1, \dots, s_k, with g_k = g. The paper adds up the log probabilities of the steps along the path. Written as a cost, using negative log probabilities so that a confident path has a small cost:

C(g)=−∑i=1klog⁡pθ(si∣gi−1)C(g) = -\sum_{i=1}^{k} \log p_\theta(s_i \mid g_{i-1})

The search expands the open goal with the smallest C(g). Because a deeper goal has more steps in its cost, the search tends to explore broadly before it goes deep.

Step 4 in symbols: the learned value

The authors replace the cost with a learned value score. For each goal they add a training example, the goal followed by the label P if the search later proved it and N if not. After training, the probability of P after a goal serves as a score for that goal:

fPθ(g)=pθ(P∣g)f_P^{\theta}(g) = p_\theta(\text{P} \mid g)

The value of a goal is then the product of this score over its siblings, the other goals produced by the same step:

Vθ(g)=∏g′∈siblings(g)fPθ(g′)V^{\theta}(g) = \prod_{g' \in \text{siblings}(g)} f_P^{\theta}(g')

A goal whose siblings all look provable gets a high value and is expanded early.

Evaluation in symbols

A statement counts as proved if at least one of a independent searches finds a proof within d expansions. The score of a model is the fraction of statements in a set that are proved:

Perfa,e,dvalid(θ)=#{statements proved}#{statements in the valid set}\text{Perf}^{\text{valid}}_{a,e,d}(\theta) = \frac{\#\{\text{statements proved}\}}{\#\{\text{statements in the valid set}\}}

The paper reports the valid set, about 1,000 theorems, during development and a held-out test set once at the end.

Results

The paper reports most results on the validation set. The table below gives the main milestones, using the numbers in the paper's key results table.

SystemValidation provedWhat changed
MetaGen-IL (previous best)21.16%Baseline
160m Transformer, augmented data28.96%Transformer instead of recurrent networks
700m Transformer31.58%More parameters
700m, pre-trained on WebMath42.56%Pre-training on code, arXiv mathematics and math forum posts
700m, plus learned value function47.21%Two rounds of value-guided data generation
700m, plus learned value, 32 attempts56.50%More search attempts per statement

The held-out test set gave 56.22% for the best configuration, with 256 expansions and 32 attempts per statement.

Three effects stand out.

Pre-training helps, and the source matters. A 700m model pre-trained on the WebMath mix reached 42.56%, against 31.58% trained from scratch. Pre-training on GitHub alone gave 41.55% and on CommonCrawl alone gave 39.61%, so the mathematics-heavy mix did best.

The learned value function helps on top of pre-training. Iterating the value function on the model's own proofs took the 700m model from 42.56% to 47.21%. The authors also found that overfitting the training set hurt this loop. They hypothesise that an overfit model becomes too optimistic about its training data, which weakens exploration. They therefore stopped training at the minimum of the validation loss.

More attempts help, with diminishing returns. For the best model, doubling the attempts per statement added 4.39 points going from 2 to 4, and 2.45 points going from 16 to 32. Table 12 of the paper lists the full curve.

The limits are just as important. The model is evaluated on one library, Metamath, and the test set was used once. Each full evaluation took about 1,000 GPU-hours on V100s, and each round of value-function data generation took about 20,000 GPU-hours in the authors' setup. Scaling from 700 million to 1.5 billion parameters did not help: the 1.5 billion model scored 42.39% against 42.56% for the 700 million model. And the synthetic arithmetic and algebra datasets, which were about 1% of training data, were a deliberate choice; the authors found that 5% hurt for the model sizes they tested.

Reading guide

Read the paper in this order. Each section depends on the concepts listed with it.

  • Section 1, Introduction. The motivation: reasoning is missing from the list of neural network successes, and formal proofs offer automatic checking and automatic data. The Go analogy points to Mastering Chess and Shogi by Self-Play with a General RL Algorithm and to Self-Play. Background on the general model type is in Language Model.
  • Section 3, Formal environment. How Metamath works and why a proof is a tree of goals. Read it with Formal Verification in mind, because the checker is what makes the search trustworthy.
  • Section 4.1 and 4.2, Model and training objective. A decoder-only Transformer trained as an Autoregressive Model, with the loss from the math section above. The tables report Perplexity next to accuracy, so you can see how well the model predicts held-out text as well as how often it proves theorems.
  • Section 4.3, Proof search. The queue of goals and the Tree Search. For contrast, Beam Search keeps a fixed number of candidates at each depth; the paper instead orders all open goals by cost.
  • Section 4.7, Learned value function. The reinforcement-style idea behind Value Function, trained on the model's own proofs in a loop. Read it with Monte Carlo Tree Search to see the family of methods it resembles.
  • Section 5, Experiments. Ablations, pre-training and the scaling tables. The tokenisation uses the same byte-pair scheme as GPT-3, described in Subword Tokenization.
  • Section 6, Output. The proof-shortening contributions and the interactive assistant. Read after the experiments; they show what the model is good for in practice.

Check yourself

QuestionWhat does the proofstep objective ask the model to produce, and what does it see as context?Show answer
The model sees the goal as context and is trained to produce the proof step, token by token. The goal tokens are masked out of the loss, so only the proof step is learned from. This makes the training example match the job the model has at proof time: given a goal, propose a step.
QuestionUsing Table 12, by how many points does the best model's score rise when attempts go from 4 to 32? Give the number.Show answer
The score goes from 47.29% at 4 attempts to 56.50% at 32 attempts. The difference is 56.50 minus 47.29, which is 9.21 percentage points.
QuestionWhy does the learned value function use the probability of a label P after a goal, rather than a separate output head that outputs a number?Show answer
Using the probability of the token P means the same network that writes proof steps also scores goals, with no extra head to add or train. The outcome label is a binary token, so its probability is a natural score between zero and one. Training is one more kind of example in the same format, and scoring costs one forward pass.
QuestionA new formal system has a checker that can verify proofs, but almost no human-written proofs. Using the paper's ideas, how would you build training data for a model?Show answer
Generate synthetic problems from rules where the checker can confirm the answer, such as arithmetic or algebraic identities, as the authors did. Train a model on them alongside whatever proofs exist. Then run search with the model, keep the proofs the checker accepts, and retrain on them, repeating the loop. The checker is what makes every generated example reliable.

Sources

Read the full paper

Stanislas Polu, Ilya Sutskever, 2020. arXiv:2009.03393