Search

Search papers and lessons

Solving Quantitative Reasoning Problems with Language Models

Aitor Lewkowycz, Anders Andreassen, David Dohan et al. · 2022

Minerva keeps training large language models on arXiv papers and math-heavy web pages, then samples many answers and keeps the most common one, reaching state of the art on math benchmarks in 2022.

On this page

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

TL;DR

Minerva is a set of language models that were trained further on about 38.5 billion tokens of arXiv papers and web pages full of mathematics, so they learn to write step-by-step solutions in natural language with correct LaTeX formulas. At answer time the model samples many solutions and keeps the final answer that appears most often. In 2022 this gave state of the art on the MATH, GSM8k and MMLU-STEM benchmarks, without a calculator or any other tool.

Builds on: Autoregressive Model, Chain-of-Thought Prompting, Fine-Tuning, Transformer · Leads to: LLaMA: Open and Efficient Foundation Language Models

Why it mattered

Before Minerva, models that solved math word problems well usually relied on a calculator or a program, or were trained on a narrow dataset for one benchmark. Minerva showed that a general language model, given a large amount of technical text, could solve competition-style and university-style problems in ordinary written form, with the working shown. The paper reports 50.3 percent on the MATH dataset of high-school competition problems with the largest model and voting over 64 samples, where the previous published best was 6.9 percent. Later papers still compare themselves with these numbers. The LLaMA paper, for example, reports Minerva's GSM8k results next to its own.

The problem

By 2022 a large language model could already write fluent text and answer many questions, but it did badly on problems that need several correct steps. The model has to read the question, recall facts, carry out arithmetic, and keep track of symbols over a long answer. A single mistake anywhere ruins the final answer. Two gaps were obvious:

  1. Training data. Most pretraining text has little LaTeX, so the model rarely sees a formula written out correctly.
  2. Evaluation. The usual way to score a generative model is to take one answer per problem, the greedy one. Single answers hide what the model could do if it tried several times.

The paper addresses both: it changes the training text and it changes how answers are chosen at inference time.

How it works

Here is the whole pipeline for one question, in order.

  1. Start from a pretrained model. Take PaLM, a decoder-only Transformer that was already trained on general text. Minerva comes in three sizes: 8 billion, 62 billion and 540 billion parameters.
  2. Continue training on math. Keep training with the usual next-token objective (Autoregressive Model) on the technical dataset. The model now sees many formulas, proofs and worked solutions. The paper calls this "finetuning", but it is not the same as Fine-Tuning on a labelled task: it is more training on a new kind of text.
  3. Prompt with examples. Put a fixed prompt in front of the question. It contains a few solved problems, so the model learns from context what a solution looks like (In-Context Learning). Each solution writes its reasoning out before the answer, as in Chain-of-Thought Prompting.
  4. Sample answers. Generate one answer greedily (always taking the single most likely next token, so the output is the same every time), or generate k answers with some randomness. For the random case the paper uses nucleus sampling with temperature 0.6 and top-p 0.95. Temperature is the knob described in Softmax Temperature; nucleus sampling keeps only the smallest set of next tokens whose probabilities add up to 0.95 and draws from that set.
  5. Extract the final answer. Each solution ends with a marked final answer. Read that answer out of each sample. Note that the reasoning itself is not checked.
  6. Vote. Group the samples by their final answer and pick the group with the most members. This is majority voting, the method that Self-Consistency Improves Chain of Thought Reasoning in Language Models introduced for chain-of-thought prompting.
flowchart LR
  Q[Question] --> P[Prompt with solved examples]
  P --> S1[Sample 1: reasoning, answer 12]
  P --> S2[Sample 2: reasoning, answer 7]
  P --> S3[Sample 3: reasoning, answer 12]
  S1 --> V[Count final answers]
  S2 --> V
  S3 --> V
  V --> O[Output the most common answer: 12]

A tiny trace: the model writes three solutions to a question. Two end in 12 and one ends in 7. The vote counts 12 twice and 7 once, so the output is 12. If the model had written only the 7 solution, the output would have been 7.

The math

The reasoning is never scored. Only the final answer is compared with the ground truth, so the math below is about answers.

Step 1 in symbols: the data mix

The mix has three parts: 47.5 percent math-heavy web pages, 47.5 percent arXiv papers, and 5 percent general natural language. The math parts hold about 38.5 billion tokens in total: 17.5 billion from web pages and 21.0 billion from arXiv. The general text is a small share of the mix, so the model keeps its everyday language while it learns mathematics.

Step 2 in symbols: the models

Table 2 of the paper lists the continued-training budget. The ratio of training tokens to parameters is a simple number to compare:

tokensparameters:164B8.63B≈19.0,109B62.5B≈1.7,26B540.35B≈0.048.\frac{\text{tokens}}{\text{parameters}}:\qquad \frac{164\text{B}}{8.63\text{B}} \approx 19.0,\qquad \frac{109\text{B}}{62.5\text{B}} \approx 1.7,\qquad \frac{26\text{B}}{540.35\text{B}} \approx 0.048.

The largest model saw only about 0.05 tokens per parameter in this continued training, far fewer than the 8B model. It was still the strongest model in the paper.

Step 4 in symbols: sampling

Let the model sample kk answers a1,…,aka_1, \dots, a_k. For a candidate answer aa, the vote count is

c(a)=∑i=1k1[ai=a],c(a) = \sum_{i=1}^{k} \mathbf{1}[a_i = a],

where 1[⋅]\mathbf{1}[\cdot] is 1 when the statement is true and 0 when it is false. Majority voting outputs the answer with the largest count:

a^=arg⁡max⁡a c(a).\hat{a} = \arg\max_{a} \, c(a).

Step 6 in symbols: pass@k versus majority vote

The paper contrasts majority voting with pass@k. A problem counts as solved by pass@k if at least one of the kk samples is correct. If each sample were correct independently with probability pp, then

pass@k=1−(1−p)k.\text{pass@}k = 1 - (1 - p)^{k}.

Majority voting needs more: the correct answer must be the most common one, not just present somewhere in the list. That is why majority voting saturates while pass@k keeps rising. The gap between the two curves grows with kk, which is why the paper reports both.

Results

The main numbers are in the paper's Table 3. Each row is a model; the columns are four benchmarks. "Greedy" rows take one answer per problem. "maj1@k" rows vote over k samples. Minerva 540B with voting scores 50.3 percent on MATH, 30.8 on OCWCourses, 78.5 on GSM8k and 75.0 on MMLU-STEM. The best published results before it were 6.9 on MATH, 74.4 on GSM8k and 54.9 on MMLU-STEM. Two things stand out. Scale helps: at every setting the 540B model beats the 62B model, which beats the 8B model. Voting helps more than scale in several rows: Minerva 62B with voting (43.4 on MATH) beats Minerva 540B with one answer (33.6 on MATH).

The paper also checks the limits. Its error analysis finds that most failures of the smaller model are reasoning errors or calculation errors. Its false positive estimate on MATH is about 8 percent, so roughly one in twelve correct final answers is reached by faulty working. The memorization analysis compares solutions with the training text by overlap: most solutions do not closely match training text, though a few do.

Limits the authors state: there is no automatic check of the reasoning; the model has no calculator or Python interpreter, so heavy arithmetic is weak; and because training used a large corpus, the team has little direct control over what the model learned.

Reading the numbers: three graded examples

Example
Example 1: a vote on five samples

Question: a problem whose correct answer is 7. The model writes five solutions with final answers 12, 12, 7, 12, 5.

  1. Count each answer. 12 appears three times. 7 appears once. 5 appears once.
  2. The most common answer is 12, so majority voting outputs 12.
  3. The correct answer 7 is in the list, so pass@5 counts this problem as solved.
  4. The example shows the gap between the two rules: the vote is wrong while pass@5 is right.
Example
Example 2: the gain from voting on MATH

Minerva 62B on the MATH dataset (Table 3). Greedy decoding gives 27.6 percent. Majority voting over k=256k = 256 samples gives 43.4 percent.

  1. The gain is 43.4 minus 27.6, which is 15.8 percentage points.
  2. Relative to the greedy score, the gain is 15.8 divided by 27.6, about 0.57, so voting is about 57 percent better.
  3. The same model answers 27.6 percent of problems with one shot and 43.4 percent with a vote, so the extra sampling costs compute but needs no new training.
  4. Read the result carefully: the gain is over the same model, not over another system.
Example
Example 3: a realistic question, with the last step left to you

Minerva 540B on OCWCourses, the set of undergraduate science and math problems from MIT OpenCourseWare. The paper gives 17.6 percent for greedy decoding and 30.8 percent for majority voting over 64 samples.

  1. The gain is 30.8 minus 17.6, which is 13.2 percentage points.
  2. Voting raises the score by about 75 percent in relative terms (13.2 divided by 17.6), a real effect on hard college problems that still leaves most of them unsolved.
  3. The paper measured false positives on MATH, not on OCWCourses. A vote can pick an answer that is right but reached by bad reasoning, and the automatic check cannot see the reasoning, so read this score with the same caution.

Try it: Minerva 540B on MMLU-STEM gives 63.9 percent greedy and 75.0 percent with majority voting over 16 samples. What is the gain in percentage points?

Answer: 75.0 minus 63.9 is 11.1 percentage points.

Common mistakes and tradeoffs

It is tempting to think that majority voting checks the reasoning. In fact it only counts final answers. Ten wrong solutions that agree on one wrong number will beat one correct solution, because the vote never reads the working. The paper estimates a false positive rate of 8 percent on MATH, which is low but not zero, and it rises with difficulty.

It is also tempting to think that more samples always help. In fact pass@k keeps climbing with kk, but the vote is close to its best much sooner. Spend samples where they change the answer, not for their own sake.

It is tempting to read "finetuning" in this paper as the same thing as Fine-Tuning for a labelled task. In fact the continued training is on raw technical text, with the next-token objective, and it uses no answer labels at all.

Use the approach when the answer can be extracted and compared automatically, and when you can afford several samples per question. Do not use it when the answer is a long essay, when no check exists, or when a wrong answer is costly and no human reviews the working. Alternatives include a verifier that scores each solution, as in Training Verifiers to Solve Math Word Problems, or a program that runs the calculation, which Minerva deliberately did not use.

Reading guide

The paper's sections, and the lessons you need for each:

Recap: a pretrained transformer is trained further on math text; prompted with solved examples, it writes chain-of-thought solutions; sampling many answers and taking a majority vote gives the final answer. Read next: Self-Consistency Improves Chain of Thought Reasoning in Language Models for the voting method alone, and LLaMA: Open and Efficient Foundation Language Models, which compares itself with Minerva on these benchmarks.

Check yourself

QuestionRecall: what does majority voting output, given samples with final answers 4, 9, 9, 3, 9?Show answer
  1. It appears three times, more than any other answer. Majority voting ignores the order and the reasoning; it only counts final answers.
QuestionComputation: a model gets the right answer on each sample with probability p = 0.2, independently. What is pass@k for k = 5, using pass@k = 1 - (1 - p)^k?Show answer

1 - 0.8^5 = 1 - 0.32768 = 0.67232, about 67 percent. Compare this with the single-sample rate of 20 percent to see what the extra samples buy.

QuestionWhy: the paper finds that majority voting saturates faster than pass@k. Explain why, in terms of what each measure needs.Show answer

Pass@k needs only one correct sample among the k. More samples always give more chances, so it keeps rising. Majority voting needs the correct answer to win the count. Once the vote has settled on the most common answer, extra samples rarely change the winner, so the curve flattens.

QuestionApplied: a team uses Minerva-style voting on a homework checker. The checker only reads final answers. What is the main risk, and what would reduce it?Show answer

A wrong chain of reasoning that happens to end on the right number is counted as correct, and a wrong number that many samples agree on can win the vote. Reduce it by checking the working, for example with a verifier model or a program that recomputes the steps, and by spot-checking a sample of accepted solutions by hand.

Sources

Read the full paper

Aitor Lewkowycz, Anders Andreassen, David Dohan et al., 2022. arXiv:2206.14858