G UIDING T RANSFORMERS TO P ROCESS IN S TEPS
Anonymous authors
Paper under double-blind review
A BSTRACT
Neural networks have matched or surpassed human abilities in many tasks that humans solve quickly and unconsciously, i.e., via Kahneman’s “System 1”, but have not been as successful when applied to “System 2” tasks that involve conscious multi-step reasoning.
In this work, we argue that the kind of training that works for System 1 tasks is not sufﬁcient for System 2 tasks, propose an alternative, and empirically demonstrate its effectiveness.
Speciﬁcally, while learning a direct mapping from inputs to outputs is feasible for System 1 tasks, we argue that algorithmic System 2 tasks can only be solved by learning a mapping from inputs to outputs through a series of intermediate steps.
We ﬁrst show that by using enough intermediate steps a 1 -layer 1 -head Transformer can in principle compute any ﬁnite function, proving the generality of the approach.
We then show empirically that a 1 -layer 1 -head Transformer cannot learn to compute the sum of binary numbers directly from the inputs, but is able to compute the sum when trained to ﬁrst generate a series of intermediate results.
This demonstrates, at a small scale, how a ﬁxed-size neural network can lack the expressivity to encode the direct input-output mapping for an algorithmic task and yet be fully capable of computing the outputs through intermediate steps.
Finally, we show that a Frozen Pretrained Transformer is able to learn binary addition when trained to compute the carry bits before the sum, while it fails to learn the task without using intermediates.
These results indicate that explicitly guiding the neural networks through the intermediate computations can be an effective approach for tackling algorithmic tasks.
I NTRODUCTION
Daniel Kahneman has pointed out that there is a fundamental difference in how humans solve the following two tasks (Kahneman, 2011):
(1) complete the phrase “bread and ...”
; (2) complete the equation “ 17 × 24 = ...”.
The answer to (1) comes to mind instantly, with no mental effort, and is a result of a computation that one is not consciously aware of and could not explain.
The answer to (2) requires time and effort to come up with, and is a result of a sequence of computations that one consciously carries out.
The former mode of cognition is what Kahneman calls System 1, the latter System 2.
We currently have separate tools for solving each of these two kinds of problems on a computer, but it is not yet clear how to build a single system capable of both modes of cognition simultaneously.
Many tasks that exercise System 2 in humans involve executing some fully-speciﬁed algorithm and thus are quite straightforward to solve using conventional computer programs.
However, classical programming is not applicable to System 1 tasks as these typically correspond to functions that we do not know how to implement.
Instead, System 1 tasks are usually tackled by approximating the target functions from observed input-output pairs.
Whether such a learning-based approach could be successfully extended to System 2 tasks is an open question, and one that we aim to explore in this paper.
We argue that the classical System 1 paradigm of training neural networks to approximate functions from inputs and outputs corresponding to a given task is not a scalable approach for tackling tasks from the System 2 domain.
We claim that, given only inputs and outputs, neural networks will not receive enough supervision to converge to a solution when trained to perform algorithmic tasks that humans solve via System 2.
To circumvent this, we propose to supplement the training data with intermediate results that would be helpful to compute before arriving at the ﬁnal output.
By modifying the training data in this way, we are effectively changing the training objective — instead of having to learn any arbitrary way of mapping inputs to outputs, the neural networks are now trained to compute the outputs from the inputs through a particular sequence of intermediate steps.
We hypothesize that such additional guidance might be necessary in order for neural networks to learn algorithmic tasks, and we empirically evaluate this hypothesis.
Much of existing work in applying neural networks for System 2 tasks has been focused on making neural architectures more aligned with the execution of algorithms.
While ﬁne-tuning the model architectures may ultimately lead to superior System 2 capabilities (after all, the architecture of a calculator allows it to perform arithmetic at a super-human level), we instead explore the challenge of extending the capabilities of existing state-of-the-art System 1 models — namely, the Transformer — towards the System 2 domain.
In particular, we take inspiration from the human ability to solve algorithmic tasks by writing down symbols on paper and propose to formulate such tasks as sequence-to-sequence problems where the target sequence includes both the outputs and all the intermediate symbols that a human would write (or more).
That is, instead of modifying the models, we experiment with modifying the data.
Our main contributions can be summarized as follows:
• We show that it is possible to hand-code a 1 -layer 1 -head Transformer to compute any ﬁnite function if enough intermediate steps are used; • We show that a 1 -layer 1 -head Transformer can be trained to perform binary addition if the target sequences include intermediate results, whereas it fails to learn the task when predicting the outputs directly from the inputs; and • We show that a Frozen Pretrained Transformer can be trained to perform binary addition if the target sequences include intermediate results, whereas it fails to learn the task when predicting the outputs directly from the inputs.
R ELATED W ORK
The need of bridging the gap between System 1 and System 2 capabilities in current deep learning models has recently been emphasized by Yoshua Bengio (Bengio, 2019; Bengio et al., 2021).
The work of Bengio and colleagues addresses the higher-level cognition in its broadest sense, seeking to model and incorporate into current systems concepts such as consciousness (Bengio, 2017), causality (Bengio et al., 2020), agency (Thomas et al., 2018), and global workspace (Goyal et al., 2021).
In
Goyal & Bengio (2020), they question the paradigm of classical statistical learning and propose to shift from training models on curated datasets towards training agents in complex non-stationary environments.
In contrast to that, our approach lies within a conventional learning framework (namely, sequence-to-sequence modeling with Transformers), and addresses System 2 in a slightly narrower sense (namely, as algorithmic execution).
A considerable fraction of recent work in applying neural networks for algorithmic tasks has been concerned with modifying or augmenting neural architectures to make them more suitable for algorithmic execution.
One very common approach involves trying to bring components from classical computer architecture into the neural setting: Neural Turing Machines give neural networks access to dynamic external memory (Graves et al., 2014; 2016), Stack-augmented RNNs augment the networks with an inﬁnite pushdown stack (Joulin & Mikolov, 2015), Neural Random Access Machines use registers and introduce the ability to manipulate and dereference pointers (Kurach et al., 2016), while Neural Arithmetic Logic Modules represent neural versions of the ALU (Trask et al., 2018;
Madsen & Johansen, 2020).
A parallel but closely related line of research frames these new kinds of augmented architectures as neural controllers endowed with access to external interfaces and applies reinforcement learning techniques to train them to solve algorithmic tasks by interacting with the interfaces (Zaremba & Sutskever, 2015; Zaremba et al., 2016).
The approach of using variable amount of computation per input, known as Adaptive Computation
Time (ACT), has been introduced by Graves (2016).
Universal Transformers (Dehghani et al., 2019) integrate ACT into the Transformer architecture, allowing each output symbol to be a result of a variable number of applications of a single Transformer layer.
While these works are, like ours, motivated by the apparent necessity of intermediate processing in certain tasks, they use learned ponder time and learned ponder content whereas our work uses given ponder time and given ponder content.
The main advantage of learned ponder time and content is that the model is free to discover and learn to perform the intermediate computations that it ﬁnds most useful.
This also means that the researcher does not need to know the correct intermediate steps to train the model and can thus tackle a potentially larger class of problems.
The main disadvantage of learned ponder time and content is that the amount of supervision per forward pass decreases as the model uses more intermediate steps, and the signal can quickly become too weak for the model to train at all.
It is also worth noting that intermediate steps are typically given when humans are taught to perform algorithmic tasks (rather than being asked to infer intermediate computations by just looking at input-output pairs), which might be an important argument for given ponder content.
The idea of providing supervision beyond input-output examples has already appeared in several projects, although, in our view, it still remains largely underexplored.
Reed & de Freitas (2016) train
Neural Programmer-Interpreters by providing supervision on the correct action sequences (execution traces) of the recurrent controller, Mirman et al.
(2018) train differential Neural Computational
Machines with extra supervision on the movements of the read-write heads, and Mirman et al.
(2018) train Neural Execution Engines with extra supervision on the attention masks.
While the added training signal does lead to better sample efﬁciency and improved generalization, a major limitation of all of these approaches, as acknowledged by Mirman et al.
(2018), is that the extra supervision needs to be highly specialized as it applies to very speciﬁc components of each architecture.
Our approach of supplementing the target sequences with intermediate results is completely architectureindependent and thus does not share this limitation.
Veli ˇ ckovi ´ c et al.
(2020) use extra supervision at the data level as well, though their work is focused speciﬁcally on tasks involving graph-structured inputs and is thus based on neural network architectures that are tailored for processing graphs.
In contrast to that, we adopt a general sequence-to-sequence modeling framework, with an intention to imitate a human executing an algorithm on a piece of paper.
Our main goal is to explore how and whether powerful existing System 1 models could be used in the System 2 domain, rather than to ﬁnd a neural architecture that would be most suitable for executing algorithms.
We therefore use vanilla decoder-only Transformers in our experiments.
M OTIVATION
The distinguishing characteristic of System 1 tasks is that they can be solved instantly and unconsciously, in something akin to a single “forward pass” through a human neural network.
It thus seems plausible that all input-output mappings corresponding to System 1 tasks are in principle computable via a single forward pass through a sufﬁciently large artiﬁcial neural network.
Recent success in deep learning shows that training bigger models on more data indeed makes it possible to solve more and more System 1 tasks, and it is not unreasonable to expect this trend to continue.
When it comes to solving System 2 tasks, however, scaling up appears to be a dead-end.
Consider the problem of completing the sentence “The ﬁrst digit of the n -th Fibonacci number is ...”, where n is replaced by some positive integer.
Since a single forward pass through a neural network (no matter how large) involves a constant amount of computation, there will be some number N ∈ N such that for all n > N the correct output is not computable.
It follows that the only viable approach for solving these kinds of algorithmic tasks is to arrive at the output through intermediate steps.
The main value of introducing intermediate steps is that it gives control over the level of model expressivity required to implement a solution to a particular task.
No matter how many atomic operations separate the outputs from the inputs in a given algorithmic problem, performing those exact operations in sequence would make each execution step only as complex as a single atomic operation.
This is arguably the main reason why a human brain can “implement” something like integer multiplication even though it does not contain a circuit for multiplying arbitrarily large numbers directly — the key is that a complex problem can be decomposed into simpler ones until each sub-problem becomes solvable “atomically” via System 1.
By the same token, a neural network that is not expressive enough to compute some output through 0 intermediate steps may be expressive enough to compute the same output through l intermediate steps for some l > 0 , since each of the l steps would involve computing a simpler function.
Since many System 2 tasks are algorithmic, their outputs can be made arbitrarily distant from the inputs (in terms of the number of atomic operations separating the two), which implies that step-by-step processing is the only scalable approach for solving them.
The necessity of intermediate processing does not by itself imply the amount of guidance that the neural networks should receive during training.
The exact intermediate computations can either remain unspeciﬁed and be inferred by the model, or be ﬁxed and provided as part of the training data.
Although there are pros and cons to both alternatives (as we have outlined in section 2), we see the latter as more promising and choose to include the intermediate results in the target sequences used during training.
Our position is based on the following three observations: ﬁrst, it is natural to provide complete supervision over the intermediate computations when teaching humans to perform algorithmic tasks; second, learned intermediates create the vanishing supervision problem (the longer the ponder time, the less training signal is received per forward pass); and third, for all algorithmic tasks the exact intermediate results are fully known anyway.
While manually increasing the amount of supervision goes against the tradition of minimizing the reliance on expert knowledge that arguably lead to most of the recent achievements in the System 1 domain, Systemtasks represent a structurally different class of problems for which a different set of constraints may apply.
The arguments laid out above have the following important implications:
• Expressiveness : a neural network implementing only some very basic atomic operations should in principle be capable of expressing arbitrarily complex functions as long as enough intermediate steps are used; • Training : a neural network that fails to learn some algorithmic task when trained without intermediate processing may be able to learn the same task if enough intermediate steps are used; and • Composability : a neural network that is pretrained on some general-purpose task and does not contain a circuit implementing some algorithmic computation directly may nevertheless be able to solve the same task by computing the output through simpler operations which it does contain circuits for.
We establish the ﬁrst of these implications in Section 4 and we empirically validate the latter two in Sections 5 and 6.
Even though demonstrating a single example where a statement holds does not prove it in general, our empirical results conﬁrm that the hypothesized phenomena do occur in the particular contexts we considered in this work and thus serve as evidence in favor of the latter two implications.
E XPRESSIVENESS
Human beings are able to solve algorithmic problems, such as integer multiplication, by writing down sequences of symbols, usually with outputs at the end, where each new symbol is a result of some basic operation applied to some of the symbols preceding it.
Intuitively, it seems that the
Transformer architecture should have just the right ingredients for emulating this kind of processing: it is typically used for generating sequences of symbols by iteratively predicting the next one, and its attention mechanism allows each predicted symbol to be a function of selected preceding ones.
We prove this intuition by demonstrating that it is possible to construct a 1 -layer 1 -head Transformer to compute any ﬁnite function through intermediate steps by emulating NOR circuits.
The full details are included in Appendix A, but the general argument goes as follows:
(1) Since NOR is a universal gate, for every ﬁnite function f : { 0 , 1 } n → { 0 , 1 } m there is a Boolean circuit made up of NOR gates that computes f .
(2) By sorting the gates of such a NOR circuit according to their topological order, we can represent the circuit as a sequence of binary symbols ( s 1 , . .
, s n + l + m ) , where ( s 1 , . . . , s n ) are the inputs, ( s n + l +1 , . .
, s n + l + m ) are the outputs, and, for each i > n , s i =
NOR ( s j i , s k i ) with j i , k i < i .
(3) Given ( s 1 , . . .
, s n ) , we can correctly complete the sequence with a 1 -layer 1 -head decoderonly Transformer if its attention matrix A satisﬁes A i,z = 0 .
5 if z ∈ { j i , k i } and A i,z
=otherwise (the model attends to the correct pair of symbols at each step) and the positionwise feed-forward module computes the NOR of the two symbols attended to. [Figure]
[Figure] We present a concrete setting of all of the weights of a 1 -layer 1 -head decoder-only Transformer that makes (3) possible in Appendix A, conﬁrming the ﬁrst implication from Section 3.
While implementing NOR gates is sufﬁcient for the proof due to the universality of the NOR gate, a slight modiﬁcation to the weights of the feed-forward module allows us to choose between NOR,
AND, and
XOR operations at each position in the output sequence.
As a concrete example, we used this construction to implement addition of ﬁxed-length bit strings (with guaranteed perfect accuracy), proving that addition, with the right number of intermediates, is in the space of programs computable by a 1 -layer 1 -head Transformer.
In particular, for each position i along the inputs, letting a i and b i denote the input bits and c i denote the carry bit (obtained from the previous position, i.e., from the sum a i − 1 + b i {+− 
+}
+ c
i − 1 ), we compute
[Equation]
where e i is the i -th bit of the sum and c i +1 is the carry bit for the next position (deﬁning c 1 = 0 ).
We can thus represent the addition of, say, 3-bit numbers a 1 a 2 a 3 and b 1 b 2 b 3 (in little-endian order, where a 1 is the least signiﬁcant bit) as the sequence (
[Equation]
or, by reordering the symbols to put the sum at the end and intermediates in between the inputs and the outputs,
[Equation]
which is the representation that we actually use in our training experiments.
Figure 1 shows the attention matrices corresponding to both representations (row i of the attention matrix indicates which symbols are attended to when predicting the i -th symbol from the output sequence).
As can be veriﬁed from the ﬁgure, the hand-coded Transformer does indeed implement the correct attention patterns corresponding to two different representations of the Boolean circuit for binary addition.
T RAINING
One of our core hypotheses in this work is that in many System 2 tasks the outputs will be too many atomic operations away from the inputs to be computable in a single forward pass, regardless of how much the neural networks are scaled up, and that introducing intermediate computation is one way of solving the issue.
If true, this phenomenon should manifest at small scale as well: a shallow model may lack the expressivity to learn a direct mapping from inputs to outputs for a relatively simple task but be expressive enough to learn the mapping from inputs to outputs through intermediates, as decomposing the problem would reduce the minimum required complexity of a single operation to the point where each individual step becomes computable in a single forward pass.
We evaluate this hypothesis empirically by training a 1 -layer 1 -head decoder-only Transformer on the task of binary addition.
(We use the minGPT implementation for our experiments (Karpathy, 2020).)
We chose to investigate binary addition primarily because of its simplicity.
Conveniently, there are very clear candidates for what intermediate computations to use – e.g., we can supplement the training data with the carry bits (which are usually explicitly computed when a human is adding numbers on a piece of paper), or the values of all non-output gates in a Boolean circuit implementing binary addition (which is what we did in a previous section and do here as well).
This means that, even if the task is decomposed into the most elementary operations (i.e., binary Boolean gates), each output symbol would be associated with at most 4 intermediate computations and so the gap between the inputs and outputs that is left for storing the intermediate results will not be disproportionately large. We chose to investigate the 1 -layer 1 -head Transformer for three main reasons. First, we know from Section 4 that this model is sufﬁcient for emulating the Boolean circuit for binary addition and we know what the target attention patterns look like (Figure 1). Second, using only a single layer and a single attention head enhances the interpretability of the model as this makes it possible to unambiguously determine its attention patterns (there is only a single attention matrix we need to look at).
Finally, recall that the goal of our experiment is to test whether a model that is unable to learn a task without the use of intermediate computations could learn the same task if intermediates were used.
Thus, even though binary addition may well be a simple enough problem for a large transformer to solve without any intermediate steps at all, our aim here is to artiﬁcially restrict the expressivity of the transformer to a point where it is unable to learn the task without using intermediate steps so that we could then add intermediate computations and test whether this makes the task learnable.
As the results of this section demonstrate, reducing both the number of layers and the number of heads of the Transformer to 1 is sufﬁcient to achieve this.
We frame binary addition as a task of sequence completion — that is, the model receives a preﬁx of 2 n symbols representing the two input numbers and has to predict the subsequent l + n symbols, where l is the number of intermediate symbols and the last n symbols represent the sum (ignoring the overﬂow bit).
We train the model in 3 different regimes:
(1) Weak supervision : the model is trained to predict the sum immediately after the inputs, i
e., l = 0 .
A single training example for n = 3 would have the form a 1 a 2 a 3 b 1 b 2 b 3 e 1 e 2 e 3 , with loss computed on the model’s predictions of e 1 e 2 e 3 .
(2) Medium supervision : the model is trained to predict the sum after l = 4 n +1 intermediates, with loss computed only on the sum and not the intermediates.
A single training example for n = 3 would have the form a 1 a 2 a 3 b 1 b 2 b 3 d 1 d 2 d 3 f 1 f 2 f 3 c 1 g 1 c 2 g 2 c 3 g 3 c 4 e 1 e 2 e 3 , with loss computed on the model’s predictions of e 1 e 2 e 3 .
(3) Strong supervision : the model is trained to predict both the sum and the l = 4 n + 1 intermediates obtained by decomposing binary addition down to logic gates as explained in section 3.
A single training example for n = 3 would have the form
a 1 a 2 a 3 b 1 b 2 b 3 d 1 d 2 d 3 f 1 f 2 f 3 c 1 g 1 c 2 g 2 c 3 g 3 c 4 e 1 e 2 e 3 , with loss computed on the model’s predictions of d 1 d 2 d 3 f 1 f 2 f 3 c 1 g 1 c 2 g 2 c 3 g 3 c 4 e 1 e 2 e 3 .
In all three regimes we use teacher-forcing during training, meaning that when predicting the i -th symbol of the sequence the model sees the correct target symbols at all positions up to i .
During testing, the model receives only the two input numbers (e.g., a 1 a
a 3 b 1 b 2 b 3 )
and is used to generate the completion (e.g., e 1 e 2 e 3 for weak supervision and x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 e 1 e 2 efor medium and strong supervision) autoregressively using greedy sampling.
[Table] We run experiments with n ∈ { 8 , 16 , 24 , 32 , 40 , 48 } .
For each n , we perform a grid search over 5 × 2 × 3 × 3 = 90 hyperparameter settings and run 4 randomly initialized trials for each of those.
The hyperparameters we vary are the embedding dimension (chosen from { 32 , 64 , 128 , 256 , 512 } ), the number of training examples (chosen from { 1000 , 10000 } ), the positional encodings (either ﬁxed and deﬁned via the sine and cosine functions as in the original Transformer (Vaswani et al., 2017), ﬁxed and set to the hand-coded values as in Appendix A, or learned), and the training regime (weak, medium, or strong supervision).
In Table 1, we report the maximum accuracy achieved with weak, medium, and strong supervision over all hyperparameter settings and random trials for each n .
We measure the exact-match accuracy against the target output bits representing the sum of the input numbers.
The test set consists of 10000 examples not seen by the model during training.
The results in Table 1 show that, for n ≥ 16 , a 1 -layer 1 -head Transformer is not able to learn binary addition from weak or medium supervision while it can learn to solve the problem when strong supervision is used, supporting the second implication from Section 3.
This experiment thus serves as a demonstration of a concrete problem for which the use of intermediate steps is the key factor determining whether a neural network will be able to solve a task or not.
This supports our main hypothesis that constant-size neural networks incapable of encoding the input-output mappings corresponding to algorithmic tasks may be capable of solving these same tasks by encoding the mappings from inputs to outputs through a series of intermediate steps.
We also include a visualization of the attention patterns of a Transformer trained with strong supervision in Figure 2 (speciﬁcally, we plot the attention matrix averaged over 100 evaluations on random inputs), along with the target patterns taken from the hand-coded model.
As indicated by the considerable resemblance between most of the corresponding rows from the two plots, the trained Transformer does indeed learn to compute the intermediate results correctly and make use of them when predicting the outputs.
This conﬁrms that guiding Transformers through particular chains of intermediate computations can be instrumental in training them to perform algorithmic tasks.
Finally, for more context on the impact of hyperparameters on performance, Figures 3 and 4 compare the maximum test accuracies achieved with different positional encodings and sizes of the training dataset, respectively.
We ﬁnd that the best performance is achieved by using the sinusoidal positional encodings as used in the original Transformer (Vaswani et al., 2017), and that the smaller dataset of 1000 examples is sufﬁcient to achieve the best performance in most cases (the only exception being the strong supervision case with n = 40 ).
C OMPOSABILITY
Lu et al.
(2021) have demonstrated that the weights of large pretrained Transformers encode generalpurpose computations which can be leveraged to solve tasks from a diverse set of modalities.
They show that it is possible to achieve competitive accuracies on a range of tasks by ﬁne-tuning only the input layer, the output layer, and the layer-norm parameters of a pretrained GPT-2 model while freezing all of the remaining weights in the “body” of the model (which comprise more than 99 .
9% of the parameters).
This restricted version of the model is called a Frozen Pretrained Transformer (FPT).
While it is demonstrated that FPT is able to achieve perfect accuracy on symbol manipulation tasks like bit memory or bitwise XOR, these tasks only involve elementary single-step computations and thus fall into the domain of System 1.
The question we are interested in is whether the weights of a pretrained language model contain circuits for solving non-trivial multi-step algorithmic tasks, and if not, whether solutions to such tasks can be assembled by composing simpler circuits that are [Figure] [Figure] 48 n 0.
a cc u r a c y
[Figure]
[Figure] [Figure] a cc u r a c y [Figure]
[Table] contained within the weights. If the weights could encode a direct input-output mapping, ﬁne-tuning the FPT on example inputs and outputs would be sufﬁcient for priming the model to perform the task. However, if the solution could only be composed out of pieces, we would expect FPT to learn the task only when ﬁne-tuned to produce enough intermediate results before the output such that the individual computations are expressible via the pretrained weights.
We investigate this by training a FPT on binary addition in the weak, medium, and strong supervision regimes analogous to those described in Section 5, though, in contrast to the previous experiments, we only use the carry bits as the intermediates (FPT is a full-size multi-layer Transformer and thus may require fewer intermediate steps than a 1 -layer 1 -head model).
For instance, with n = 3 , FPT would receive a 1 a 2 a 3 b 1 b 2 b 3 as input and have to predict e 1 e 2 e 3 in the weak supervision regime and c 2 c 3 c 4 e 1 e 2 e 3 in the strong supervision regime (using the same notation as before).
We train on 10000 examples for up to 100 epochs using teacher forcing and test on 10000 unseen examples without teacher forcing.
We report the exact match accuracies (against the sum bits) over the test examples in Table 2.
As we can see, FPT fails to learn binary addition in the weak and medium supervision regimes while it is able to solve the task when being trained to compute the carry bits ﬁrst.
This suggests that binary addition may not be directly implemented in the weights of a pretrained language model but can nevertheless be expressed as a combination of more granular operations, supporting the third implication from Section 3.
This result seems to be an analog of a similar feature of the System 2 learning capabilities of humans — while it may not be possible to teach a child to compute each digit of the sum in one unconscious step, the same child can easily learn to compute the correct outputs by explicitly calculating and keeping track of the carries.
Once again, we see that guidance over intermediate computations is what a neural network’s ability to solve an algorithmic task appears to hinge on.
C ONCLUSION
In this work, we have argued that the only way for ﬁxed-size neural networks to solve algorithmic
System 2 tasks is by computing the outputs through intermediate steps.
If neural networks are going to be trained to perform such tasks from data, the actual intermediate results will either be given or have to be inferred.
We here focused on the regime with given intermediates, called strong supervision.
Our experiments demonstrated that a 1 -layer 1 -head Transformer and a Frozen Pretrained
Transformer can learn to perform binary addition only if strong supervision is used, supporting our hypothesis that guidance over intermediate computations can be necessary for solving algorithmic tasks.
We believe that strong supervision will be an integral part of any scalable attempt to use a learningbased approach for tackling algorithmic tasks from the domain of System 2.
We speculate that the usefulness of strong supervision might even extend beyond the space of algorithmic tasks, since any cognitive task that is characterized by distinct periods of thought leading to concrete intermediate results would become easier to learn if examples of those intermediate results were given during training.
This leads us to believe that the idea of providing explicit guidance over intermediate computations might point to fruitful directions for future research.
A A PPENDIX
A 1 -layer 1 -head decoder-only Transformer is a parameterized function mapping sequences of symbols to next symbol probabilities, with parameters given by
[Equation]
Given an input sequence of b symbols ( s 1 , s 2 , . . .
, s b ) from some vocabulary V
[Equation]
the Transformer outputs b vectors h ( i ) prob ∈ [0 , 1] |V| for i ∈ { 1 , 2 , . .
, b } interpreted as conditional PMFs for next symbol prediction and computed via the following deﬁnitions:
[Equation]
where d is the embedding dimension, and Mask is an autoregressive attention mask, i.e., a d × d matrix with all elements above the main diagonal equal to −∞ and all of the remaining elements equal to 0 .
Predictions are made by interpreting the entries of h ( i ) prob as next-symbol probabilities, that is,
[Equation]
for each j ∈ { 1 , 2 , . . .
, |V|} , where V j represents the j -th symbol from the vocabulary.
Let n and m be some positive integers and let ( s 1 , s 2 , . .
, s n + m ) be a sequence of binary symbols where, for each i > n , s i =
NOR ( s j i , s k i ) for some j i , k i < i .
We are going to show a concrete setting of the weights of a 1 -layer 1 -head decoder-only Transformer such that, given ( s 1 , s 2 , . . .
, s n ) , it autoregressively predicts ( s n +1 , s n +2 , . . .
, s n + m ) as the completion of the sequence.
Speciﬁcally, given any (cid:15) ∗ > 0 , we can hand-code the parameters θ such
Choose any (cid:15) ∗ > 0 .
Let b = n + m − 1 be the block size, d = 3 + b be the embedding dimension, and deﬁne constants
[Equation]
Let the parameters of a Transformer be hand-coded according to the following deﬁnitions:
W emb ∈ R 2 ×
d with ( W emb ) j,k =   − 1 if ( j, k ) ∈ { (1 , 1) , (2 , 2) , (1 , 3) , (2 , 3) } if ( j, k ) ∈ { (1 , 2) , (2 , 1) } otherwise , (17)
W pos ∈ R b × d with ( W pos ) j,k = (cid:26)
if k = j +0 otherwise , (18) γ ln1 ∈ R d with ( γ ln1 )
j = 1 , (19) β
ln1 ∈ R d with ( β ln1 )
j = 0 , (20)
W query ∈ R d × d with ( W query )
j,k = (cid:26) ( d/ 4) − 1 / 2 cif k ∈ { j j , k j } otherwise , (21) b query ∈ R d with ( b query )
j =(22)
W key ∈ R d × d with ( W key )
j,k = (cid:26)
if j = k +0 otherwise , (23) b key ∈ R d with ( b key )
j =(24)
W value ∈ R d × d with ( W value )
j,k = (cid:26) ( d/ 4) − 1 /if
( j, k ) ∈ { (1 , 4) , (2 , 5) } otherwise , (25) b value ∈ R d with ( b value )
j =(26) γ ln2 ∈ R d with ( γ ln2 )
j
= 1 , (27) β ln2 ∈ R d with ( β ln2 )
j = 0 , (28)
W ff1 ∈ R
d × 4 d with ( W ff1 ) j,k =   − ( d/ 4) 1 /if ( j, k ) =
(4 , 6) ( d/ 4) 1 /if ( j, k ) =
(4 , 7) otherwise , (29) b ff1 ∈ R 4 d with ( b ff1 )
j =   − 2 d 2 (cid:15) if j =1 − 4 (cid:15) if j = otherwise , (30)
W ff2 ∈ R 4 d × d with ( W ff2 )
j,k =   if ( j, k ) ∈ { (6 , 6) , (7 , 7) } − 1 if ( j, k ) ∈ { (6 , 8) , (7 , 9) } otherwise , (31) b ff2 ∈ R d with ( b ff2 )
j =(32) γ ln3 ∈ R d with ( γ ln3 )
j = 1 , (33) β ln3 ∈ R d with ( β ln3 )
j = 0 , (34)
W out ∈ R d ×with ( W out ) j,k = (cid:26) δ − 1 d 2 cif ( j, k ) ∈ { (7 , 1) , (6 , 2) } otherwise .
Choose any i ≥ n .
After the token embedding and positional encoding layers, the hidden representation corresponding to symbol i is given by
[Equation]
Since
[Equation]
after layer normalization the hidden representation is turned into
[Equation]
Then, since the only nonzero elements of h ( j ) ln1 are (cid:16) h
( j ) ln1 (cid:17) 1 , (cid:16)
h
( j ) ln1 (cid:17) 2 , (cid:16)
h
( j ) ln1 (cid:17) 3 , and (cid:16)
h ( j ) ln1 (cid:17)
+ i , and the ﬁrst three rows of W key are zero vectors, we get that the key corresponding to symbol j is given by
[Equation]
if k = j
[Equation]
otherwise .
[Equation]
41) and the query corresponding to symbol j is given by
[Equation]
We thus have that the key matrix K (i.e., a matrix whose j -th row is the j -th key vector k ( j ) ) will be a b × d matrix whose ﬁrst b columns are equal to ( d/ 4) 1 / 2 times the identity matrix and all the remaining elements are 0 .
Consequently, the attention weights that will be used for computing the hidden representation corresponding to the i -th symbol are given by
[Equation]
where
[Equation] [Equation]
Then, since c 1 =
[Equation] [Equation]
[Equation] [Equation]
[Equation]
we have that, for k ∈ { j i +1 , k i +1 } ,
[Equation]
This shows that that the hidden representation corresponding to symbol i after the attention module can be made arbitrarily close to the average of the value vectors corresponding to symbols j i +
and k i +1 .
Since the ﬁrst two elements of h ( j ) emb are sign ( s j ) and − sign ( s j ) , we get that the value vector corresponding to symbol j is given by
[Equation]
The hidden representation corresponding to symbol i after the attention module is then given by
[Equation]
51) and we have that
[Equation]
that is,
[Equation] [Equation]
[Equation]
with ( h i att )
= − ( h i att ) 4 , and ( h i att ) j = 0 for all j / ∈ { 4 , 5 } .
The hidden representation corresponding to symbol i after the ﬁrst residual connection is given by
[Equation]
Since ( h i att ) 5 = − ( h i att ) 4 and all other entries of h ( i ) att are zero, and h ( i ) emb has a mean of 0 , we have that
[Equation]
[Equation]
Also, since h ( i ) att can contain non-zero entries,
[Equation]
i
[Equation]
61) and since the entries of h ( i ) res1 cannot exceed ( d/ 4) 1 / 2 ,
[Equation]
Then, since
[Equation]
63) we have that
[Equation]
64) for all j ∈ { 1 , 2 , . . .
, d } , which implies that
[Equation] [Equation]
[Equation] [Equation]
(cid:15)
[Equation] [Equation]
[Equation]
Since ( d/ 4) 1 / 2 > 1 , it follows that
[Equation]
Using the deﬁnition of W ff1 and b ff1 and the fact that ( d/ 4) 1 / 2 > 1 , we get that
[Equation] [Equation]
and
[Equation] [Equation]
Since (cid:15) = 1 5+
[Equation]
< 1 4+2 d 2 , we have that δ = 1 − 4 (cid:15) + 2 d 2 (cid:15) > 0 , and thus
[Equation]
71) and
[Equation] [Equation]
Then, using the deﬁnition of W ff2 and b ff2 , we get that
[Equation]
7 = ReLU
[Equation] [Equation]
if
[Equation]
(74) while (cid:16) h
( i ) ff2 (cid:17) 8 =
[Equation]
i
[Equation]
6 , (cid:16) h
( i ) ff2 (cid:17) 9 = − (cid:16) h
( i ) ff2 (cid:17) 7 , and (cid:16) h
( i ) ff2 (cid:17)
j = 0 for all j ∈ { 10 , 11 , . . .
, d } .
Since
[Equation]
75) we have that
[Equation]
Also, since the entries of h ( i ) res2 cannot exceed d 2 ,
[Equation]
Then, since
[Equation]
, (78) we have that
[Equation]
(79) for all j ∈ { 1 , 2 , . . .
, d } .
It then follows that
[Equation]
80) s
[Equation]
and (cid:16) h
[Equation]
≥
[Equation]
Let z
= h
( i
[Equation]
ln
[Equation]
Then, using the deﬁnition of W out and the fact that c 2 = (cid:108) ln (cid:16) 1 − (cid:15) ∗ (cid:15) ∗ (cid:17)(cid:109) ≥ ln (cid:16) 1 − (cid:15) ∗ (cid:15) ∗ (cid:17) , we get that s i +
= 1 = ⇒
z
1 = (cid:16) h ( i ) ln2 (cid:17) 7 (cid:0)
δ − 1 d 2 c 2 (cid:1) =
and z 2 = (cid:16) h ( i ) ln2 (cid:17) 6 (cid:0) δ − 1 d 2 c 2 (cid:1) ≥ c 2 , (83) =
⇒ e z 2 ≥ 1 − (cid:15) ∗ (cid:15) ∗ (84) =
⇒ e z 2 − e
z
+ e z 2 (cid:15) ∗ > 1 − (cid:15) ∗ (85) =
⇒ e z 2 > e z 2 − e z 2 (cid:15) ∗ + 1 − (cid:15) ∗ (86) =
⇒ P
θ ( s i +1 = 1) =
( Softmax ( z ))
= e ze z
+ e z 2 =
e ze z 2 + 1 > 1 − (cid:15) ∗ , (87) and
[Equation]
We conclude that, for each i ≥ n , P θ ( s i +1 =
NOR ( s j
[Equation]
, s k
[Equation]
)) > 1 − (cid:15) ∗
[Equation]