Learning by Distilling Context

Charlie Snell, Dan Klein, Ruiqi Zhong

Introduction

Recent work has shown that language models significantly benefit from context tokens. When prompted with task definitions, language models can perform zero-shot learning (Wei et al., 2022a; Sanh et al., 2022), and the performance further improves with additional in-context examples and explanations (Chen et al., 2022; Scheurer et al., 2022). They also acquire the capability to perform more complex tasks by generating step-by-step reasoning in the context window before predicting the final answer (Nye et al., 2021b; Wei et al., 2022b; Zhou et al., 2022).

However, language models cannot internalize these performance gains, which disappear when the context tokens are gone. Consequently, we always need to pay extra computation for running inference on context tokens; this is undesirable, as sometimes the task instructions and the scratch-pad can be more than 10x longer than the actual task inputs. Furthermore, it is unclear how to leverage the context tokens when their total length exceeds the context window size. These shortcomings are analogous to how humans are slow at performing complex cognitive tasks (Wason & Evans, 1974) and can hold only a limited amount of information in the working memory (Baddeley, 1992).

Humans get around this by practicing. Consider, for example, learning to type your friends’ phone numbers. The first few times you type it, you need to consciously recall the number using working memory and slowly decide which button to press. After repeatedly typing the same number, it becomes a habit and you can type the number quickly without conscious reasoning. Through repeated practice, the knowledge of your friend’s phone number is “distilled” into your muscle memories.See declarative learning vs. procedural learning for a friendly but more in-depth discussion. https://en.wikipedia.org/wiki/Declarative_learning This mechanism for distilling knowledge is critical for learning complex tasks because it allows us to incrementally build up our knowledge and skills, so that we can learn to accomplish increasingly complex tasks.

We propose to apply a similar method, context distillation, to fine-tune language models. For example, as shown in Figure 2, to make language models internalize the step-by-step addition capability, we first synthesize a large number of “practice” addition questions; we then ask the model to follow the more informative instruction to reason step-by-step before generating the target answer; finally, we fine-tune the language model to directly predict the answer conditioned on a simpler student prompt. As a result, by practicing on a lot of addition problems, the ability to add is distilled into its parameters. We formally state our generalized context distillation framework in Section 2.

Section 3 shows that context distillation is a general method to train language models, and we can apply it to a wide range of settings: learning from abstract statements, learning from concrete examples, and learning from step-by-step reasoning. Section 3.1 (Figure 3) shows that context distillation can effectively internalize task instructions from Natural-Instructions-V2 (Wang et al., 2022b); it can also benefit from natural language explanations of why certain outputs are correct or incorrect; additionally, we can teach the student to associate numerical indices with certain tasks, and then we can sequentially re-assign these task indices, overwriting the student’s past associations. Section 3.2 (Figure 4) shows that context distillation can be used to internalize Text-to-SQL training examples from the SPIDER dataset (Yu et al., 2018) into Incoder (Fried et al., 2022), and it outperforms directly learning with gradient descent by 9% for 8-shot adaptation; additionally, we show that as we distill more training examples than can fit in the context window, we observe continual improvements in performance. Section 3.3 (Figure 4) shows that we can internalize step-by-step reasoning to perform 8-digit addition, and such a capability can transfer to downstream question answering tasks.

Overall, context distillation demonstrates promising potential as a general method to train language models. As discussed in Section 4, we predict that future models will be better able to learn from context than today’s models, and researchers will use these models to tackle increasingly complex tasks that require more extensive background knowledge and longer reasoning chains. Therefore, we anticipate our method to be increasingly useful in the future.

Context Distillation

We introduce the main components and the intuition of our context distillation framework in Section 2.1, describe our algorithm for single round distillation in Section 2.2, explain how to distill multiple contexts sequentially or simultaneously in Section 2.3, and describe various implementation details to make it efficient and stable in Section 2.4.

We explain our method by contrasting it with the classical distillation methods (Hinton et al., 2015a). These classical methods ask the teacher model with parameter θ\textscteacher\theta_{\textsc{teacher}} to generate a label yy for a given input xx, and train the student θ\textscstudent\theta_{\textsc{student}} to mimic the teacher by predicting yy conditioned on xx. Typically, θ\textscteacher≠θ\textscstudent\theta_{\textsc{teacher}}\neq\theta_{\textsc{student}} when the algorithm starts, and the distillation process is driven by the difference between their parameters. In contrast, under context distillation, θ\textscteacher=θ\textscstudent\theta_{\textsc{teacher}}=\theta_{\textsc{student}} when the training starts, and the distillation process is instead driven by the differences in the xx and yy that they see and predict.

To design such a difference that drives the distillation process, our framework requires the model developers to provide four components: a raw task input distribution D\mathcal{D}, a teacher template T\textscteacherT_{\textsc{teacher}}, a student template T\textscstudentT_{\textsc{student}}, and an answer extractor ff. We introduce them below.

D\mathcal{D} is a distribution of strings, which are typically the “core” inputs of the target task of interest. For example, if the target task is to classify movie review sentiment, the input distribution could be defined as random movie reviews. More generally, there are many ways to define a raw task input distribution: we can use a rule-based method to generate random strings, sample from a pool of unlabeled data, or conditionally sample from a language model. We explicitly distinguish raw task inputs from the whole “input prompt” to the language model, which is obtained after applying the templates below.

T\textscteacherT_{\textsc{teacher}} is a mapping from strings to strings, which transforms raw task inputs to the input prompts for the teacher model. As shown in Figure 1, the teacher template usually contains detailed instructions, explanations, and examples about the task.

T\textscstudentT_{\textsc{student}} is a mapping from strings to strings, which transforms raw task inputs to the input prompts for the student model. As shown in Figure 1, this template usually still contains minimal information about the task so that the request in the prompt is not under-specified. However, compared to the teacher prompt, it incorporates far fewer explanations and training examples of the task, and such a difference transfers this useful context information into the student parameters.

Answer Extractor f𝑓f.

ff is a mapping from token sequences to token sequences, which extracts the final answer (a sub-sequence of tokens) from the full teachers’ generation. As shown in Figure 1, ff strips away the intermediate reasoning process, and the students need to internalize the step-by-step reasoning process to directly predict what the teacher predicts at the end.

We now describe context distillation formally using the mathematical terms we just introduced.

2 Formal Description

Our algorithm first samples an xx from D\mathcal{D} and ask the language model to sample a completion yy conditioned on T\textscteacher(x)T_{\textsc{teacher}}(x); we then fine-tune the language model to predict f(y)f(y) conditioned on T\textscstudent(x)T_{\textsc{student}}(x). Throughout the distillation process, θ\textscteacher\theta_{\textsc{teacher}} is fixed.

Formally, let θ\textscstudent\theta_{\textsc{student}} and θ\textscteacher\theta_{\textsc{teacher}} be the parameters of a language model, and define Pθ(⋅∣\textscprompt)P_{\theta}(\cdot|\textsc{prompt}) to be the probability distribution of the completions conditioned on the prompt. We optimize

3 Combining Multiple Updates

We now introduce simultaneous distillation and sequential distillation, two straightforward variants that combine multiple context distillation operations, allowing us to internalize ensembles or sequences of contexts, enabling a form of learning that is not possible with just a single prompt.

To simultaneously perform KK different context distillation operations represented by D1…K,T\textscteacher/\textscstudent,1…K,f1…K\mathcal{D}_{1\dots K},T_{\textsc{teacher}/\textsc{student},1\dots K},f_{1\dots K}, we can optimize the total loss:

Simultaneous distillation is especially useful when the prompts contain independent instructions and in-context training examples, but their total length exceeds the language model context window size.

Sequential Distillation.

To perform KK context distillation operations sequentially, we can inductively define θ\textscstudent,0\theta_{\textsc{student},0} as the initial language model, and θ\textscstudent,k+1\theta_{\textsc{student},k+1} to be the parameters after fine-tuning with the loss function

with θ\textscstudent,k\theta_{\textsc{student},k} as the initialization. Sequential distillation is useful for incrementally updating the student model or overwriting previous updates. We can also compose these two variants arbitrarily.

Recursive Distillation.

Beyond the above two variants, Choi et al. (2022) explores a recursive variant, which is similar to sequential distillation, except that the student model becomes the new teacher in the next iteration. This allows us to incrementally update the model without maintaining a separate set of parameters for the student and the teacher.

4 Implementation Details

A naive method to optimize Equation 1 is to sample yy and directly fine-tune the student to predict the hard label of f(y)f(y): such a method wastes the token logit information and results in noisy gradients. Instead, we minimize the token-level KL divergence between the student and the teacher. However, this leads to another issue: the vocabulary space of language models is often on the order of 50-100k, and the full soft labels consume a lot of memory. Therefore, we approximate the soft label distribution by an empirical distribution of 100 token samples. Such a technique saves us a lot of memory while still delivering satisfactory performance.

Experiments

We apply context distillation to three types of settings. In Section 3.1, we apply context distillation to internalize abstract instructions and natural language explanations; additionally, we show that context distillation can associate multiple task instructions with a task id, and sequential distillation can overwrite previous updates. In Section 3.2, we apply context distillation to internalize concrete training examples, and we show that it outperforms directly learning with gradient descent on the SPIDER Text-to-SQL dataset; additionally, we show that simultaneous distillation can be used to internalize more training examples than the context window can fit. In Section 3.3, we apply context distillation to internalize the ability to perform 8-digit addition step-by-step; additionally, we show that such a capability can transfer to other downstream question-answering tasks even when the scratch-pad is not present. In all cases, the student’s input length is significantly shorter than the teacher’s, and we may reduce the context length by as much as 11 times, saving us a large amount of compute at inference time.

For each experiment, we report the teacher’s performance and the student’s performance before and after distillation. The student’s performance needs to improve after context distillation in order to support the claim that context distillation is successful. The teacher’s performance is generally an upper-bound on the student’s performance, except for the case of simultaneous distillation where multiple teacher templates are applied and no individual teacher can outperform the student.

We apply context distillation to internalize abstract instructions and explanations. In all experiments, unless mentioned otherwise, the answer extractor is the identity function and we use few-shot prompting to sample raw task inputs (see Figure 3).

We use Natural-Instructions-V2 for all the experiments in this section. Natural Instructions is an instruction-tuning dataset of 1600+ diverse language tasks, where each task is associated with a natural language task description, input-output examples, and explanations about why certain outputs are correct or incorrect (Wang et al., 2022b). We trained our teacher language model (TK-Instruct) by fine-tuning LM-adapted T5-11B (Raffel et al., 2020) on the Natural Instructions training set. The training details can be found in Appendix B.1. For evaluation, we select 5 tasks from the evaluation split where the teacher most significantly improves when prompted with natural language explanations, and 5 where the improvement is small. We use Natural Instruction’s official metric, Rouge-L, to calculate the performance averaged across the 10 tasks we selected.

Hypothesis 1: context distillation can internalize abstract task instructions. To test this hypothesis, we defined the student template as the identity mapping, i.e., the student only sees the raw task input, while the teacher template contains the task instruction, which consists of a task description, 2 positive in-context examples, and 2-negative in-context examples (Figure 3 teacher’s template). The teacher’s performance is 43.4 Rouge-L, establishing an upper bound for the student. Before context distillation, the student’s performance is 9.0, since it does not know what task it should perform. After context distillation, the student’s performance significantly increases to 34.7. Context distillation successfully internalized our abstract task instructions. Finally, we used 11.1 times fewer inference time tokens when evaluating the student verses the teacher.

Hypothesis 2: context distillation can learn from natural language explanations when they benefit the teacher. In this experiment, we use the same teacher template as the experiment above; in contrast, in this experiment, we define a student template that is exactly the same as the teacher, but without explanations (Figure 3 student template B). We run context distillation to internalize the effect of natural language explanations, using the task’s training split as D\mathcal{D} (see Appendix B.4).

Ideally, we want the student to fully internalize the effect of natural language explanations and match the teacher’s performance. To measure how much the student internalizes, we define two quantities for each task: 1) the in-context margin, which measures the performance increase after we add the explanations to the context, and 2) the distillation margin, which measures the performance increase after we perform context distillation. We plot the margins for each task in Figure 5, and we observe a positive and statistically significant correlation (r=0.75,p=1%r=0.75,p=1\%). Therefore, context distillation can learn from natural language explanations when they benefit the teacher.

Notice that for our current model, not all tasks benefit from internalizing natural language explanations. However, we anticipate that future language models be more responsive to natural language explanations (Kaplan et al., 2020; Scheurer et al., 2022), hence improving the performance of context distillation.

Hypothesis 3: sequential distillation can overwrite past updates. We study sequential distillation using four classification tasks, superglue_copa_text_completion, meta_woz_task_classification, tweetqa_classification and rocstories_title_classification. We define a new task id association challenge: each task is associated with an index, and when the student model sees an index, it needs to perform the corresponding task without looking at its instruction; we train the student model to do this via simultaneous context distillation, where the student sees the task index while the teacher sees the task instruction (Figure 3 student template A). After we use context distillation to train the student to associate each task-id with the corresponding instruction, we shuffle the task-id association, perform context distillation again with the new shuffled association, and then evaluate the model’s performance on the new association, which measures how well context distillation can overwrite previous updates.

We define two metrics for this task id association challenge. First, we will measure the average accuracy (correct association accuracy) of the student on the four tasks when the student is prompted with the corresponding index. Second, it is plausible that the student can learn to associate the task input distributions, rather than the index, with the corresponding instructions. For example, suppose that id “” corresponds to classifying sentiment and the task input distribution is movie reviews, while “” corresponds to whether it is sports-related and the raw input distribution is news articles, then the student might cheat by always classifying sentiment whenever it sees a movie review, regardless of what id it sees. Therefore, we also measure the average accuracy when we prompt the model with the wrong task id, and we want this number to be low (wrong association accuracy): for example, if the model sees “” and a news articles, it should have low accuracy at classifying whether it corresponds to sports, because “” corresponds to sentiment classification.

We experimented with two variants of simultaneous distillation: 1) the “naïve” one, where each Dk\mathcal{D}_{k} contains only the input distribution for one single task, and 2) the “mixed” one, where we define each Dk\mathcal{D}_{k} as a mixture of all the raw task input distributions. As shown in Table 1, under the “naïve” input distribution, the student model can cheat by associating the task input distribution, rather than the task id, with the task it needs to perform; on the other hand, the “mixed” variant of simultaneous distillation successfully over-writes the past task id association.

2 Learning from Concrete Examples

We show that context distillation can be used to internalize training examples, and therefore can be a potential alternative to directly learning from these examples with gradient descent; additionally, simultaneous distillation allows the model to learn from more in-context examples when their total length exceeds the context window length. In all experiments, the answer extractor is the identity function and we use few-shot prompting to sample raw task inputs (Figure 4).

We use the SPIDER text-to-SQL dataset (Yu et al., 2018) for our experiments. Each database in SPIDER is associated with a schema and a list of English questions annotated with SQL query. The task is to predict the SQL query given the schema and the question. We choose this task because prior work (Rajkumar et al., 2022) has demonstrated that SOTA models are able to effectively utilize in-context examples for this task, and we conjecture that our approach is more likely to succeed since this task requires complex cognitive reasoning. For the teacher language model, we chose Incoder-6.7B (Fried et al., 2022), which is pre-trained on code. For each experiment, we randomly sampled eight text-to-SQL pairs for each database as in-context examples and evaluate on the rest by calculating the exact set match accuracy.

Hypothesis 4: context distillation can outperform directly learning with gradient descent.

To test this hypothesis, we define the student template to be a database schema followed directly by the question, whereas the teacher template contains the database schema followed by four in-context examples (see Figure 4 teacher’s template-A). As we see in Table 2, context distillation outperforms learning via gradient descent on four examples by 8.6% in exact-set match accuracy, a margin which further increases by 0.4% when training on eight examples. Therefore, context distillation can be used as an alternative to directly learning from training examples with gradient descent.

For this experiment, we select four databases from the SPIDER training set which have particularly long database schema, such that it is possible to fit four training examples into Incoder’s context window but not eight. Therefore, we include 4 training examples in the student template (Figure 4, student’s template B.), which would lead to the best in-context learning performance ex-ante given the context window size. To internalize more training examples, we perform simultaneous distillation and sample teacher templates by including a random subset of four in-context examples out of eight (Figure 4, teacher’s template A and B). After context distillation, our student achieves an exact set match of 16.2±0.616.2\pm 0.6, which improves over the pre-distillation student performance of 14.22±0.814.22\pm 0.8, hence confirming our hypothesis.

3 Learning from Step-By-Step Reasoning

We show that context distillation can effectively internalize a skills acquired by generating step-by-step reasoning, and such a skill can benefit the model for other downstream tasks. Unless otherwise mentioned, in this section we use an ff that will extract the final answer from the teacher’s full output, as shown in Figure 2.

We define the input distribution D\mathcal{D} to be uniform over all possible 1 through 8 digit addition questions, identical to those used by Nye et al. (2021a); Zelikman et al. (2022). We report addition accuracy for each experiment.

Hypothesis 6: context distillation can internalize step-by-step reasoning.

To test this hypothesis, we obtain a teacher model that can use scratch-pad to perform step-by-step reasoning by fine-tuning the LM-adapted T5-small on a dataset of 500 addition expressions, where the model needs to first generate a scratch-pad before predicting the final answer. We then perform context-distillation with an ff that extracts the final answer from the teacher’s output as shown in Figure 2. As shown in Table 3, after distillation, the ability of the student to perform direct additions (without using scratch-pad) improves from 0% to 94.7%, implying that context distillation internalizes step-by-step reasoning.

We compare this to several other transfer learning and multi-task learning baselines that use the same amount of training data in Table 3. Under transfer learning, we first fine-tune the student model to predict the scratch pad, and then fine-tune it to directly predict the final answer. Under multi-task learning, we fine-tune the model to predict scratch-pad and the final answer independently. Both variants perform significantly worse (>20%>20\%) than context distillation. In addition to the gains in reasoning ability over baselines, we also saved inference time compute in our evaluations: specifically we used 8.0 times fewer tokens at inference time when evaluating the student compared to the teacher.

To test this hypothesis, we distill the addition scratch-pads on our TK-Instruct model, and evaluate capability transfer to other tasks. We obtain the teacher language model by fine-tuning TK-Instruct on a distribution of both natural instructions data and 500 addition scratchpad examples (see Appendix B.6), and we initialize the student with the original TK-Instruct checkpoint. For the context distillation training, we define the student template to be a description of the addition task followed by two direct answer in-context examples, and similarly the teacher template contains the task description and two in-context examples with scratch-pad answer. To prevent the student from catastrophically forgetting its in-context learning ability during distillation, we mix our 10k distillation data-points with a distribution of 65536 randomly selected examples from Natural Instruction-V2.

The student’s accuracy on directly answering 8-digit addition questions improves from 1% to 17%, while the student’s performance on Natural Instructions remains roughly the same (from RougeL 57 before distillation to 58 after), implying that the student did not lose its original capabilities to follow instructions. Additionally, we evaluate the student’s performance on a set of related reasoning tasks. We then use a template to synthesize simple questions that require knowledge to add two numbers, for example, “A has 7 turkies. B has 2 turkies. How many turkies do they have altogether?”. On this synthetic dataset, the student’s performance significantly increases from 17% to 30% after context distillation, implying that the capability to perform direct addition can transfer to other related applications.

Related Work

Many recent works show that language models can learn from abstract task definitions (Zhong et al., 2021; Mishra et al., 2022; Wei et al., 2022a; Sanh et al., 2022), natural language explanations (Scheurer et al., 2022; Wang et al., 2022b), and concrete in-context examples (Min et al., 2022; Chen et al., 2022). We anticipate the in-context learning performance to improve further in the future (Kaplan et al., 2020), thus increasing the upper bound of what context distillation can achieve.

Scratch Pad.

Many recent works show that language models perform better when it is required to generate a chain of reasoning steps before outputting the final answer (Zhou et al., 2021; Nye et al., 2021b; Cobbe et al., 2021; Wei et al., 2022b; Zhou et al., 2022; Lewkowycz et al., 2022). We anticipate context distillation to be increasingly useful, as the research community starts to tackle more difficult problems, which require more sophisticated skills and have longer problem descriptions and reasoning chains.

Distillation.

There has been a large literature on distilling knowledge in a neural network (Hinton et al., 2015b; Adriana et al., 2015; Liu et al., 2019; Yang et al., 2020; Xie et al., 2020). Most related to our work, different sub-variants of context distillation have been independently discovered by different researchers. Wang et al. (2021) emphasizes the aspect of creating a dataset without any human annotations and uses a language model to generate task inputs and their labels. Choi et al. (2022); Askell et al. (2021) formulated the method of context distillation (also referred to as prompt injection), which distills a fixed input prompt; their method is a special case of our framework with an identity student template and an identity output selector. Additionally, they focused more on the benefit of saving computational resources, while we considered it as a general learning method. Concurrent to our our work, Anonymous (2023) focuses on internalizing step-by-step reasoning, and they corroborated our findings on much large models and a much wider range of datasets.

Conclusion

We present context distillation as a general method for learning, which can internalize abstract statements, concrete examples, and step-by-step reasoning. Given that 1) it is general and delivers strong performance, 2) future models will have stronger in-context learning capability, and 3) future tasks will have longer descriptions and reasoning chains, we anticipate our methods to be increasingly useful in the future.

Acknowledgement

We thank Jacob Steinhardt, Sergey Levine, Kevin Yang, Nicholas Tomlin, and other members of the Berkeley NLP group for their helpful feedback. We thank the TPU Research Cloud (TRC) program for providing computational resources.

References

Appendix A Other applications

We show that context distillation could be applied to other applications, such as controlled text generation or factual knowledge editing.

By distilling prompts that describe the desired behavior (e.g. don’t output toxic language or only generate positive sentiment text), we can exert a form of control in language models. To test this, we prompt our TK-Instruct model to complete negative movie reviews from the IMDB sentiment classification dataset (Maas et al., 2011).

The teacher template contains the instruction to complete the movie review specifically to end the review on a positive note, and the student template contains the instruction just to complete the review without any other specification. After distillation, the student should learn to internalize the abstract control preference for positive movie reviews.

We evaluate our models by asking GPT-3 to verify that our model’s generation is indeed positive. As shown in Table 4, context distillation allows us to control our language model to generate positive reviews.

A.2 Factual Knowledge Editing with Context Distillation

Context distillation also provides a natural way to edit the factual knowledge implicitly internalized by language models, by distilling a prompt that states a new or edited declarative fact. This is in contrast to prior works (Mitchell et al., 2021; De Cao et al., 2021; Meng et al., 2022) on fact editing, which instead perform a constrained optimization procedure that directly learns an edit to the model parameters, corresponding to the factual knowledge update.

We use the challenging Counterfact dataset from Meng et al. (2022) to test our method’s fact editing ability. Each instance of the Counterfact task involves editing the object of a given factual relation. Ideally, the language models should consistently apply the new fact under significant paraphrases to the original relation and context changes; the model should also not update the unrelated knowledge. To measure this, the Counterfact dataset provides a set of paraphrase prompts (significant paraphrases of the original fact, which the LM should consistently edit), neighborhood prompts (un-related facts that share the same object as the original pre-edit fact, on which the model should not change their predictions), and attribute prompts (un-related facts which share the same object ad the new post-edit fact, which should not change).

We perform fact editing experiments on our TK-Instruct model. For a randomly selected fact corresponding to each of the 34 unique relations in the Counterfact dataset, we synthesize a teacher template, which includes a description of the fact to be edited and instructions not to edit unrelated facts. We also use GPT-3 to help us generate a new attribute, paraphrase, and neighborhood prompt for each fact edit to use as demonstrations of desired behavior in the prompt, alongside a natural language explanation of why the fact edit is or is not applied in each case. We generate the inputs P(x)P(x) using a few-shot prompt to TK-Instruct.

Unfortunately, our prompted TK-Instruct teacher model performs poorly on neighborhood prompts, which also leads to poor performance of the student model. We expect this issue to be largely resolved by context distilling larger and more capable language models. To demonstrate this, we evaluate GPT-3 on this task with the same prompt, which we can see in Table 5 performs much better on these neighborhood prompts. While we cannot perform context distillation on GPT-3 due to limitations in OpenAI’s API, we expect these improvements to carry over to the distilled model.

Appendix B Experiment Details

Following the procedure of (Wang et al., 2022a), we fine-tuned the 11B T5 LM-adapted model (Raffel et al., 2019), on Natural Instructions V2 (Wang et al., 2022a), a large dataset of 1600+ language tasks which includes, for each task, a task description, positive and negative in-context examples, and natural language explanations of why the output is right or wrong for each of the in-context examples. Prior work (Wang et al., 2022a) has used this dataset to train instruction-tuned models on prompts consisting of only 2-positive examples or only 2-positive and negative examples with explanations. To maximize the flexibility of our instruction-tuned model, we instead instruction-tuned on a distribution of randomized prompts, which consist of randomly chosen 0 to 3 positive examples, 0 to 3 negative examples, and whether there is an explanation or not. We trained the model for 9728 steps with a batch size of 16 and AdamW optimizer on 32 TPU-V3 cores. The model achieves a RougeL score of 5858 on the 2 positive, 2 negative with explanation test split, of unseen natural instructions tasks.

B.2 Finetuning Language Model Implementation Details

We run all experiments on 32 TPU-V3 cores, with the model parameters and optimizer states for fine-tuning sharded equally across all cores. Our codebase is built in Jax (Bradbury et al., 2018; Sabne, 2020) using the PJIT function to handle the model parallel training and inference.

B.3 General Experiment Details

For all experiments, except where denoted otherwise, we distill on 4096 examples for 1 epoch with batch size 16 with AdamW optimizer. We use a learning rate of 1e-5 with TK-Instruct and 1e-4 with Incoder. We use 0 weight decay for all experiments.

B.4 Distilling Abstract Statements Details

We present a scatter plot of the “In-context Margin” verses the “Distillation Margin” for our experiment on learning from natural language explanations in Figure 5.

Distilling task id associations details (hypothesis 3).

We present detailed, per-task results for our task id association experiment in Table 6.

B.5 Distilling Concrete Examples Details

For gradient descent we fit all training examples into a single batch and train for a 25 epochs using the AdamW optimizer with a learning rate of 1e-5. We report the performance of the epoch with the highest average exact set match score across all databases.

Distilling long contexts details (hypothesis 5).

To estimate the per-token log-probabilities of the yy sampled from the teacher ensemble for distillation, we average the probabilities of each yy under 8 teacher prompts. We estimate the teacher performance by performing greedy decoding on the ensemble of 8 prompts uniformly sampled from the set of all 4 choose 8 teacher prompts. For each database, we distill two students with different in-context examples in the prompt, and we report the average exact-set match accuracy for both of these students.

B.6 Distilling Step-by-Step Reasoning Details

All baselines were trained for 1000 epochs – except “Scratchpad then Direct” which was trained for 1000 epochs to predict scratchpads and then 1000 epochs to directly predict the answer – with a batch size of 8, a learning rate of 3e-4, and AdamW optimizer. We report performance at the end of training on 10k unseen addition problems.

Transfering step-by-step reasoning details (hypothesis 7).

Since TK-Instruct cannot successfully do scratchpad addition from a few shot prompt, to initialize the teacher, we first fine-tune TK-Instruct on the same distribution of 500 scratchpad examples from the previous experiment mixed in with 4096 randomly selected examples from the “2 positive” split of Natural Instructions-V2 training set, such that the teacher doesn’t lose its ability to respond to prompts. We train the teacher for 32 epochs, at which point it achieves 97% accuracy on 2000 held-out scratchpad addition problems. Our student is trained for 3 epochs on a dataset consisting of 10k distillation examples mixed in with 65536 randomly selected examples from the same split of Natural-Instructions-V2 training set as the teacher.