LIME: Learning Inductive Bias for Primitives of Mathematical Reasoning
Yuhuai Wu, Markus Rabe, Wenda Li, Jimmy Ba, Roger Grosse, Christian Szegedy
Introduction
Inductive bias is essential for successful neural network learning. Many of the breakthroughs in machine learning are accompanied by new neural architectures with better inductive biases, such as locality bias in convolutional neural networks (LeCun et al., 1999), recurrence and memory in LSTMs (Hochreiter & Schmidhuber, 1997), and structural bias in graph neural networks (Scarselli et al., 2008). However, explicitly encoding inductive biases as new neural architectures can be difficult for abstract concepts such as mathematical reasoning. Attempts to design elaborate architectures for reasoning often fall short of the performance of the more generic transformer architecture. In this work, we aim to avoid the search for new architectures and investigate whether one can learn useful inductive bias for mathematical reasoning through pretraining.
Large-scale unsupervised pretraining of language models revolutionized the field of natural language processing (NLP), improving the state-of-the-art in question answering, name entity recognition, text classification, and other domains, e.g. (Radford et al., 2018; Devlin et al., 2019; Yang et al., 2019; Liu et al., 2019; Raffel et al., 2020; Brown et al., 2020). As a result, pretraining has become a common practice for modern neural network based NLP. A popular explanation for the benefit of pretraining is that the model can learn world knowledge by memorizing the contents of the natural language corpus, which can be useful in downstream tasks, such as question answering and text classification. However, there is another potential advantage of pretraining—it may distill inductive biases into the model that are helpful for training on downstream tasks (Brown et al., 2020; Warstadt & Bowman, 2020). We focus on the latter and design pretraining tasks that are intentionally devoid of world knowledge and only allow the model to learn inductive bias for reasoning.
Inspired by the logician Charles Peirce (Peirce, 1992), we consider the following three reasoning primitives:
Deduction: the ability to deduce new truths from given facts and inference rules.
Induction: the ability to induce general inference rules from a set of known facts.
Abduction: the ability to explain the relationship between the evidences and inference rules.
To endow the models with an inductive bias for mathematical reasoning, we design a synthetic task for each of the three reasoning primitives. We hypothesize that the transformer networks are flexible enough to learn strong inductive bias from the three synthetic reasoning tasks, which helps to improve the performance on downstream tasks. Although such inductive bias may be useful in general reasoning tasks (e.g., NLP tasks), in this work, we focus on mathematical reasoning benchmarks, for which we expect to observe the largest gains. We call training on these tasks LIME – an acronym for “Learning Inductive Bias for Mathematical rEasoning”. Note that there is only a limited amount of pretraining data available for formal mathematical benchmarks, therefore the study of generic pre-training techniques is particularly important for the success of machine learning in mathematical reasoning.
We demonstrate that LIME pretrained models provide significant gains across four large mathematical reasoning benchmarks: IsarStep (Li et al., 2021), HOList Skip-tree (Rabe et al., 2021), MetaMathStep (Polu & Sutskever, 2020), and LeanStep (de Moura et al., 2015). Notably, LIME improved the top-1 accuracy from to IsarStep, and from to on LeanStep. Compared to traditional pretraining tasks, LIME has two major differences. First, LIME requires only a fraction of the computational cost of downstream tasks. With only about two hours of training on a single modern GPU, one already obtains all the benefits, in contrast to days of training on a large natural language corpus with hundreds of GPUs/TPUs. Secondly, LIME does not load the input embeddings or the weights in the output layer for finetuning on downstream tasks. This allows one to use the same pretrained model for a variety of downstream tasks, which can have vastly different vocabularies due to language or tokenization differences.
Our method can also be regarded as a form of curriculum learning, in which the model is taught basic, extremely generic but general skills before being trained on the specific problem domain.
To summarize, the contributions of the paper are:
Providing the first method to design inductive biases in the form of datasets for mathematical reasoning.
Demonstrating significant improvements in the reasoning performance of transformer models on three large mathematical reasoning benchmarks with negligible extra computation cost.
By showing how pretraining brings benefits other than learning content knowledge, disentangling the study of its working mechanism.
Related Work
There has been increasing interest in applying deep learning methods to Interactive Theorem Provers (ITP) (Bansal et al., ; Bansal et al., 2019; Gauthier et al., 2020; Huang et al., 2019; Yang & Deng, 2019; Wu et al., 2021; Li et al., 2021; Polu & Sutskever, 2020). The work that is most related to ours is GPT- (Polu & Sutskever, 2020). The authors performed pretraining on several natural language corpora and showed significant improvements for an ITP system – MetaMath. Different from ours, they used GPT-style large-scale language modeling pretraining, which dominates the computation cost compared to the downstream task. We, on the other hand, propose pretraining on a few lightweight synthetic tasks costing only a minor fraction of the computation spent on the downstream task.
Lample & Charton (2020) have demonstrated that transformer models can be used for symbolic mathematics by successfully predicting the integrals of formulas from a randomly generated dataset. Similar observations are made for logical problems relevant to verification: that transformer networks can learn the semantics of logics (Hahn et al., 2020). Rabe et al. (2021) have shown that mathematical reasoning can emerge from self-supervised training alone. Li et al. (2021) show that language models can learn to synthesize missing high-level intermediate propositions given a local context. Piotrowski & Urban (2020) used RNNs in automated theorem provers for first-order logic. Wang et al. (2020) explored the use of machine translation to translate between synthetically generated natural language descriptions of proofs and formally represented proofs. Urban & Jakubův (2020) present initial experiments on generating mathematical conjectures with a Transformer model.
Saxton et al. (2019) suggest a dataset for the analysis of mathematical reasoning skills. In contrast to the datasets considered here, their dataset is synthetic, focuses on calculation with concrete numbers, and only contains relatively few symbolic tasks.
Language Model Pretraining
The advent of the transformer architecture (Vaswani et al., 2017) and the BERT style pretraining (Devlin et al., 2019) represented a huge improvement in the quality of language modeling. Since then, an explosion of research activity in the area pushed the quality of language models through better pretraining tasks. Where BERT (Devlin et al., 2019) masks out a fraction of the input tokens, later works demonstrated the advantages of masking out subsequences (Song et al., 2019; Dong et al., 2019; Joshi et al., 2020; Raffel et al., 2020; Conneau & Lample, 2019) and whole sentences (Zhang et al., 2020).
Besides the choice of pretraining tasks, the scale of language models is also an important factor. Language models improve in quality and develop new abilities as they grow larger while trained on the same data (Radford et al., 2018; Raffel et al., 2020; Brown et al., 2020).
Inductive Biases in General
There have been works studying learning inductive biases in other contexts. In particular, McCoy et al. (2020) studied whether one can learn linguistic inductive biases on synthetic datasets via meta-learning. Papadimitriou & Jurafsky (2020) shows inductive biases learned in music data can be useful for natural language. They further designed several synthetic tasks and showed similar kind of improvements for natural language tasks. From a more theoretical point of view, Xu et al. (2020) formalize an aspect of inductive (architectural) bias under the context of GNNs, with a notation called architectural alignment. The architecture is aligned when the architecture can perfectly simulates the ground truth solution. But their work is limited to showing alignment in combinatorial problems, whose ground truth solutions are known. In contrast, our work tries to learn architectural bias by relying on the flexible Transformer architecture and training on synthetic datasets.
Inductive Biases for Mathematics
Previous work studying inductive biases for logical reasoning has focused on encoding bias in the neural architecture. Initial works focused on encoding the tree structure of expressions using TreeRNNs (Evans et al., 2018). Graph neural networks are shown to provide a much stronger performance than tree models in premise selection (Wang et al., 2017) and theorem proving (Paliwal et al., 2020). GNNs also scale to larger formulas in SAT (Selsam et al., 2019; Selsam & Bjørner, 2019; Han, 2020), QBF (Lederman et al., 2020), and #SAT (Vaezipoor et al., 2021). Crouse et al. (2019) have shown that pooling mechanisms can have an impact on the performance of GNNs on logical formulas as well. Closely related, Hellendoorn et al. (2020) have shown that it can be helpful to hard-code the tree structure of programs in the attention mask of transformers. Schlag et al. (2019) developed an architecture for encoding relational information using tensor product representation for mathematical reasoning.
Methods
In this section, we first discuss the primitives of reasoning, inspired by Peirce’s views, and design one synthetic task for each reasoning primitive.
In Peirce’s view, there are exactly three kinds of reasoning: deduction, abduction, and induction. Deduction is known as the workhorse for mathematics. It is the process of deriving new facts by applying logical inference rules to known facts or premises. On the other hand, abduction and induction can be thought of as the inverses of deduction. If we call the premise used in deduction as Case, its logical rule as Rule, and its conclusion as Result, then abduction is equivalently the inference of a Case from a Rule and a Result, while induction may be said to be the inference of a Rule from a Case and a Result. We summarize the three reasoning primitives in the following table:
To give an example, we let Rule be “All the beans in this bag are white”, Case be “These beans are from this bag”, and Result be “These beans are white”. Deduction is to derive the fact that these beans are white (Re) from knowing all the beans from this bag are white (R) and these beans are from this bag (C). Abduction explains why the beans are white (Re) from knowing that all the beans in the bag are white (R) – because these beans must be from the bag (C). Lastly, induction aims to provide a general principle to observing the fact that the beans are white (Re) and they come from this bag (C), which is that all the beans in the bag must be white (R). We refer to Peirce (1992) and Bellucci & Pietarinen (2015) for more elaborate discussions on the primitives of reasoning.
Mathematical reasoning exhibits nontrivial uses of these reasoning primitives. Deduction happens when one needs to derive new valid statements from the given premise (Case) and theorems in the library (Rule). Abduction is used to postulate conjectures from the known facts and theorems, allowing one to decompose the challenging theorem into subgoals for proof. Induction, the ability to extract general principles from known facts and theorems is also one of the major activities of mathematical reasoning. It is used when one derives theorems from special cases and proposes new definitions and general frameworks to encapsulate existing knowledge.
2 LIME Synthetic Tasks For Reasoning Primitives
We design three synthetic tasks inspired by the three reasoning primitives. As discussed in the previous section, all of the reasoning primitives consist of three essential elements: Rule, Case, and Result. Inspired by this, we first design a method to generate those elements. Once they are generated, we can construct tasks that predict one element from the other two. In the following, we describe one simple way to generate those three elements, though we acknowledge that there are many other possible approaches.
We require two types of symbols: 1. math symbols, 2. rule symbols. In general, these symbols can take any forms (e.g., integer representations). But for the ease of discussion, we will think of math symbols as the union of those operators used in mathematics (e.g., “”) and lower case letters (e.g., , , …), and rule symbols as upper case letters (e.g., , , …). We now construct Rule, Case, and Result in order:
Rule is a randomly sampled string that consists of i) rule symbols and ii) math symbols. The length of the string is randomly sampled from a range. For instance, a randomly sampled rule can be: with rule symbols , , and .
Case is a dictionary that represents substitutions. For each rule symbol used in the Rule string, we sample a random string of random length that consists of math symbols. This forms a dictionary, whose keys are all rule symbols, and the values are the corresponding sampled string. To illustrate, following the previous example, for each , and , we sample a random string to form a dictionary as: .
Result is the outcome of the substitution. For each rule symbol in the Rule string, we replace it with the corresponding value stored in the Case dictionary. This gives rise to the Result string. As per the previous example, we now substitute with , with , and with into the Rule string, generating the Result string: .
After Rule, Case, and Result are generated, we can construct three tasks for deduction, abduction, and induction respectively. We define the three synthetic tasks as follows:
Deduct: Source: Rule string and Case dictionary.
Abduct: Source: Rule string and Result string.
Induct: Source: Case dictionary and Result string.
We also consider a task called Mix, which is a uniform mix of three tasks. Namely, during generation, we randomly select a task and sample an example from that task. To formulate them as sequence to sequence tasks, we represent the Case dictionary also as a string, e.g., “”. An example of Abduct using the examples of Rule, Case, and Result above is to predict the target from the source .
Pre-training on our synthetic tasks can be seen as a form of skip-component learning. There are three essential components: Rule, Case and Result, and we skip one of them and use the remaining two elements to reconstruct the missing one. Past work has shown that learning to predict missing words (Devlin et al., 2019), subsequences (Song et al., 2019; Raffel et al., 2020), or subtrees (Rabe et al., 2021) are strong pre-training tasks.
3 Symbol-Agnostic Representation
In order to solve the synthetic tasks, the model needs to distinguish which set of symbols can be substituted (rule symbols). As a result, the model may memorize information about the symbols that is irrelevant to the inductive biases encoded in the task. To prevent such memorization, we propose a way to make the synthetic tasks agnostic to the choice of symbols.
We first note that the choice of symbols is irrelevant to our synthetic tasks. To avoid symbol-specific memorization, for each training and evaluation example, we randomly sample two sets of symbols to be used in Rules and in the rest of the example. But for the Abduct task, the model needs to know which symbols are replaced by the Rule part of the example and which symbols are in the Result language. We simply list the split of the symbols used in the example at the beginning of the input string, marked by two special symbols,
Source:
In our implementation, we use integers to represent symbols. Specifically, for each example, we sample two disjoint sets of integers from the set
Experiments
In this section, we present results on four large mathematical reasoning tasks that are especially useful in the context of automated theorem proving. Our results show significant gains in learning inductive biases from synthetic tasks. We have selected four tasks to cover various different styles of interactive theorem provers: The HOL-Light (skip-tree) corpus was created from very high-level tactic-based proofs, but it is less interpretable than IsarStep’s declarative style corpus. We also evaluate on model’s ability to conjecture unseen lemma strings with Lean theorem prover, which is host to some of the most sophisticated formalized mathematics. Lastly, we evaluate the next proof-step prediction task on the set.mm library of MetaMath, which consists of very granular, basic proof steps. Namely, the proof steps are more predicable and average proof lengths have significantly increased.
We generate datasets of our synthetic tasks for pretraining: Deduct, Abduct, Induct, Mix. For pretraining of IsarStep, we used a vocabulary size
Fine-tuning
For all the downstream tasks in this section, when loading the pretrained models for fine-tuning, we do not load in the vocabulary embeddings nor the output layer weights. For the downstream task IsarStep and MetaMathStep, we used four Nvidia Tesla T4 GPU with
Architecture
All experiments used the transformer base model from (Vaswani et al., 2017), i.e. 512 hidden size, 2048 filter size, 8 attention heads. For the IsarStep and MetaMathStep task, we used 6 layers for both the encoder and decoder, implemented using fairseq (Ott et al., 2019). For the HOList skip-tree experiment, we used a somewhat modified transformer architecture with 8 encoder and 4 decoder layers of the same size as above in which the self-attention and attention over the encoder output were merged.
Evaluation
During training, we kept track of the best validation tokenized BLEU score https://github.com/pytorch/fairseq/blob/master/fairseq/tasks/translation.py#L396, and we used the model with validation BLEU for evaluation on the test set. We report top-1 and top-10 accuracies. We consider an output sequence as correct if it matches the target sequence exactly. We performed a beam search with width 10. The top-1 accuracy is then defined as the percentage of the best output sequences that are correct. The top-
2 IsarStep
The IsarStep task is taken from (Li et al., 2021). IsarStep is a task of predicting the missing intermediate propositions given surrounding propositions to bridge the gap between the goal and the current state of the proof. The dataset was mined from the public repository of formal proofs of the Isabelle proof assistant (Paulson, 1994). Unlike HOList and MetaMath, IsarStep contains mostly declarative proofs, a proof style close to humans’ prose proofs. The dataset has a broad coverage of undergraduate and research-level mathematics and computer science theorems. There are 820K, 5000, 5000 sequence pairs for the training, validation, and test sets with a maximum of 800 tokens in source sequences and 200 tokens in the target sequences. Following (Li et al., 2021), during training, we use 512 as the maximum length for both the source and target, and truncated those that exceed the length to 512. For reporting, we evaluate all 5000 test examples regardless of their lengths.
The results on the IsarStep task for four pretrained models and the baseline transformer model without pretraining is shown in Table 1. We also include another baseline, HAT transformer introduced in (Li et al., 2021), which is a specially designed hierarchical transformer architecture tailored to this task. We see the pretrained model achieved substantial improvement over the model trained from scratch as well as HAT. Notably, the model that was pretrained on Abduct improved the top-10 accuracy from
3 HOList Skip-Tree
As the second mathematical reasoning benchmark, we consider the HOList skip-tree evaluation tasks by Rabe et al. (2021). These tasks include two variants of type inference, predicting under which assumptions theorems hold, and completing equalities. All source expressions for these tasks are taken from the validation set of the theorem database of the HOList proof logs (Bansal et al., ). The evaluations are done on a random sample of 1000 instances from the full evaluation sets. We initialized the model parameters with the pretrained weights and then repeated the experiments by Rabe et al. (2021). That is, we trained the models for up to 1M parameter updates on the training set with batch size 256 and repeat the evaluation every 100K steps. In Table 2 we present the best result from these 10 evaluation runs. We see a significant improvement in these reasoning tasks when the models are initialized with the pretrained weights. Notably, on equation completion and missing assumptions task, we improved the beam search (with width
4 MetaMathStep
Compared to other ITPs, MetaMath is a low-level proving system: each proof step makes only a small step towards the goal. As such, each proof contains many more proof steps than in other ITPs: with
In this task, the model is asked to generate PROOFSTEPS given a GOAL, namely, the GOAL string is the source input, and PROOFSTEPS is the target output. We follow (Polu & Sutskever, 2020) and use their string representation for the GOAL and the PROOFSTEPS. Instead of using subword tokenization in Polu & Sutskever (2020), we use a character-level representation for our task. Following Polu & Sutskever (2020), we split theorems into train/valid/test theorems of size
5 LeanStep: Unseen Next Lemma Prediction Task
Lastly, we look at a mathematical benchmark based on Lean 3 theorem prover. Lean has an extremely active community and is host to some of the most sophisticated formalized mathematics in the world, including scheme theory (Buzzard et al., 2019), forcing (Han & van Doorn, 2020), perfectoid spaces (Buzzard et al., 2020), and condensed mathematics (Scholze, 2020). We extracted a similar style of dataset as MetaMathStep from Lean, that is, we predict the next lemma to apply given the current goal state (or commonly known as the tactic state in Lean). Unlike MetaMathStep, we focus on predicting lemmas that have not been seen during training time. Namely, in this task, we evaluate the model’s capability of conjecturing a novel lemma string given a goal. Specifically, we extracted
Ablation Studies
In this section, we perform ablation studies. Additional ablation studies can be found in Appendix C.
Here we investigate how LIME compares to pretraining on natural language or existing formal reasoning datasets. In this set of experiments, we pretrained three models on Mix, MetaMathStep, and on the WMT 2016 English-to-Germany (WMT En-De) translation task, and then we fine-tuned and evaluated these models on the IsarStep task. We pretrained the model on MetaMathStep and WMT EN-DE for
2 Do we need vocabulary embeddings for fine-tuning?
As mentioned earlier, we did not load in the vocabulary embeddings from the pretrained models when we switched to fine-tuning on downstream tasks. Even without loading the vocab embeddings, the pretrained models still improved the performance. In this ablation study, we investigate how much this decision has affected the results and whether vocabulary embeddings can help improve the performance even further. We performed the comparisons on IsarStep. The task contains a token vocabulary of size 28336. We generated new synthetic tasks for the same vocabulary size, such that we can load the vocabulary embeddings and output layers when initializing the model for IsarStep. Table 7 shows that this led to similar performance. This aligns with our expectation that the model should not learn content specific knowledge that is potentially stored in the vocabulary. These weights turn out to be non-essential for the final performance, supporting the evidence that the transformer learns inductive biases from the pretraining task.
3 Does LIME help LSTMs?
In this section, we investigate if LIME also helps other architectures than transformers. In particular, we applied LIME to two LSTM based architectures: 1. vanilla LSTM, 2. LSTM with attention mechanism. The vanilla LSTM is a stacking LSTM with 4 layers, each with 1000 cells, and 1000-dimensional embeddings. The LSTM with attention architecture is taken from (Luong et al., 2015), also with 4 layers, 1000 cells and 1000-dimensional embeddings. We evaluate on the IsarStep task, and compared a model trained from scratch and a model pre-trained on LIME abduct task. We used the same training protocol as described in 4.1. The results are shown in Table 8, along with the results on transformer. We observe that LIME improved LSTM as well as LSTM with attention, but the improvements were small compared to transformer. Specifically, if we compare Top-1 accuracy, we can see that LIME improved LSTM from
Does LIME encode Induction, deduction and abduction?
Although LIME has shown to achieve substantial improvements across various benchmarks, it is not entirely clear that the specific synthetic tasks necessarily enforce the reasoning ability of induction, deduction and abduction. We would like to note that deduction, induction, and abduction are high-level and philosophical concepts, and serve only as an inspiration for us to design the synthetic tasks. We do not expect the model will necessarily learn exactly these three capabilities. After all, we have chosen a particular implementation of "Case", "Rule" and "Result". Furthermore, we also design tasks mimic proof steps in formal theorem proving (see the rewrite task in Appendix B.1), which also achieved excellent results. Nevertheless, we believe LIME is a first step towards building reasoning inductive biases, and provides many inspirations and directions for future work.
Conclusion
In this work, we encoded inductive biases for mathematical reasoning in the form of datasets. We created three synthetic tasks inspired by three reasoning primitives of deduction, induction, and abduction. We demonstrated that pretraining on these tasks (LIME) significantly improved the performances across four mathematical reasoning benchmarks. Notably, LIME requires negligible computation compared to the downstream task, unlike being the dominating factor in previous pretraining methods. Our work naturally poses many future research questions. Could the primitive tasks provide similar gains for NLP tasks? Are there similar primitive tasks for natural language reasoning? We also look forward to disentangling the effects of pretraining between learning content knowledge and inductive bias for all downstream tasks to better understand pre-training.
Acknowledgments
YW is supported by a Vector Institute research grant. Li is supported by the ERC Advanced Grant ALEXANDRIA (Project 742178), funded by the European Research Council. YW and CS would like to thank Rif A. Saurous for discussions and proofreading.
References
Appendix A Synthetic Task Generation Pseudocode
Appendix B Other synthetic tasks
In this section, we give descriptions of other variants of the synthetic tasks we considered than the ones introduced in the main paper.
We propose a rewrite task, inspired by the rewrite tactic used in interactive theorem provers. The Rewrite task requires the model to rewrite a string according to a rule transformation. One example of the task is:
“
We further introduce a multi-step version of the rewrite task: Rewrite_multistep. In this task, the source may contain more than one rewrite rule, and the target is the result of applying all the rewrite rules in a sequence. This task is motivated from the need to perform multi-step planning in mathematical reasoning tasks. During pre-training, for each training example, we uniformly sample the number of rewrite steps from 1 to 5.
B.2 Other variants of Induct Task
We introduce three other variants of the Induct task.
Induct_v2: We move the Case dictionary from the source input to the target output. This makes the task significantly harder, which requires the agent to synthesize a rule and a possible explanation (Case) to explain the Result.
Induct_v3: Instead of providing the Case dictionary, we provide two Result strings, coming from the same Rule. Namely, we sample two Case dictionaries, and applying each to the Rule string to obtain two Result strings. Both Result strings are used as source, and the target is the Rule string.
Induct_rewrite: We also create a “induction” version of the Rewrite task. In this task, the source is the LHS string concatenated with the RHS string, that is the result of the rewrite. The target is the rewrite rule that is used to do the rewrite.
B.3 A full comparison of all synthetic tasks
In this section we present a full comparison for all synthetic tasks. We followed the training protocol in 4.1 and evaluate the method on IsarStep. The results are reported in Table 9. We can see that the Rewrite_multistep achieved the best performance across all synthetic tasks, surpassing the baseline by
Appendix C More Ablation Studies
In this section, we investigate whether the vocabulary size