Large Language Models are In-context Teachers for Knowledge Reasoning (2024)

Abstract: In this work, we study in-context teaching(ICT), where a teacher provides in-context example rationales to teach a student to reasonover unseen cases. Human teachers are usually required to craft in-context demonstrations, which are costly and have high variance. We ask whether a large language model (LLM) can serve as a more effective in-context teacher for itself or otherLLMs, compared to humans. Inspired by the Encoding Specificity Hypothesis from human episodic memory, we hypothesize thatin-context exemplars crafted by the teacher should match the training data of the student. This hypothesis motivates us to propose Self-Explain where an LLM’s self-elicited explanations are used as in-context demonstrations for prompting it as they are generalized fromthe model’s training examples. Self-Explain is shown to significantly outperform using human-crafted exemplars and other baselines.Furthermore, we reveal that for ICT, rationales from different teacher LLMs or human experts that more resemble the student LLM’s self-explanations are better in-context demonstrations. This supports our encoding specificity hypothesis. We then propose Teach-Back that aligns a teacher LLM with the student to enhance the ICT performance. For example, Teach-Back enables a 7B model to teach the much larger GPT-3.5 in context, surpassing human teachers by around 5% in test accuracy on medical question answering.

## introduction knowledge reasoning, different from numerical reasoning, requires large language models (llms) to deduce the association between questions and answers that do not usually explicitly appear in the training corpus, although llms may have memorized all the facts involved in the question. such a compositionality gap @xcite between testing and pretraining makes knowledge reasoning difficult and beyond mere fact retrieval. however, llms have demonstrated impressive knowledge reasoning performance on diverse tasks @xcite with few-shot prompting. exemplars of reasoning are provided in the prompt as context to teach llms to reason through in-context learning (icl) @xcite at inference. llms will generate intermediate reasoning steps (known as chain-of-thought (cot) 1 @xcite ) for deducing the test cases. standard few-shot cot prompting requires humans to first craft high-quality demonstrations of reasoning for llms, as depicted in the upper part of figure 1 . however, this may bring some issues. on the one hand, in professional domains such as medicine, experts like physicians are needed to produce fine-grained rationales with correct jargon, which is time-consuming and expensive @xcite . on the other hand, different from labels, rationales can be phrased in varied ways, while all being correct @xcite . collecting reasoning examples through crowd-sourcing can thus have great uncertainty @xcite . the constructed rationales heavily depend on human annotators' own experience and thus, may be very subjective @xcite . more fundamentally, there is a limited understanding of the principles behind constructing effective rationale exemplars for in-context learning. currently, the majority of works depend on human-crafted demonstrations (usually by professionals) that are based on some heuristic rules @xcite @xcite . however, it is unclear whether those sophisticated rationales crafted by humans are equally the most sensible to llms. demonstrations of rationales from humans may not always be helpful @xcite , although they are often assumed to be gold standards @xcite . therefore, we are motivated to ask, can an llm teach itself or other models through in-context learning for knowledge reasoning, preferably better than humans? we consider a generic framework of incontext teaching (ict), where a teacher (e.g., human or llm) constructs example rationales that are then used as in-context demonstrations to prompt a student llm. in terms of how to construct exemplars for effective ict, we consider the encoding specificity hypothesis @xcite , which is initially proposed for we propose encoding specificity hypothesis to make large language models better in-context teachers than humans. we accordingly design self-explain for an llm itself to be the teacher and teach-back to improve the llm's capability of teaching another model in context. the encoding specificity hypothesis can be easily satisfied when the teacher model is the student model itself. we directly prompt the student model to explain the given answer to a question sampled from the same dataset as the test data as inspired by learning theory in cognitive science @xcite . those elicited self-explanations can represent the model's encoded knowledge for the test task and are then used as in-context demonstrations at inference. we refer to this approach as self-explain. on the other hand, when the teacher model is different from the student model (e.g., using a weak and small model to teach a much larger model @xcite )), we first let the teacher model learn from the student's self-explanations before eliciting the teacher's explanations (see the lower part of figure 1 ). we refer to this method as teach-back, which is how healthcare providers (i.e., teachers) reduce the communication gap with patients (i.e., student) for effective health education @xcite . our experimental results provide sources of evidence for our encoding specificity hypothesis. we find that the student model itself tends to be the best incontext teacher for it, surpassing human teachers or other llm teachers (w/o teach-back). our experiments across models of different sizes and reasoning abilities suggest that for ict, larger and stronger models are not necessarily better in-context teachers, though they may produce more reliable rationales. we show that in-context reasoning examples that more resemble the student's self-explanations can lead to better student performance. this also supports our encoding specificity hypothesis. furthermore, applying teach-back can significantly improve the ict capability of a teacher model for the student model and even outperform self-explain depending on the teacher model. for example, teach-back enables a small deployable 7b model to teach the much larger gpt-3.5 in context, surpassing human teachers by around 5% in test accuracy on medical question answering. in summary, our contributions are mainly in three folds: ## revisiting icl we first detail some annotations and give a formal setup of in-context learning. we denote the model parameters as θ, rationale as π and assume a labeled dataset d with distribution p * . given a test query x, the model will predict ỹ by conditioning on the query and incontext exemplars. we can then have, ## methodology the general framework of our proposed methods and our prompting format is shown in figure 2 . we first introduce self-explain, where the student and teacher are the same (section 3.1), as a straightforward implementation of the encoding specificity hypothesis. we then extend this approach to employing a different teacher model (section 3.2). ## related work in-context learning. in-context learning is the ability of language models to induce answers from given demonstrations without weights updating in supervised tuning. in-context exemplars are the key to icl which have dominating influence on the generation. quite a few works have been proposed to optimize the selection of exemplars @xcite @xcite . on the other hand, in the cases of no access to task labels, @xcite proposed a zeroshot icl that employs pseudo exemplars with random labels for classification tasks. chain-of-thought prompting without humancrafted exemplars. prompting with reasoning exemplars triggers llms to generate similar intermediate steps of thinking through icl, known as chain-of-thought (cot) @xcite . @xcite propose zero-shot cot prompting to elicit llms' reasoning without human-crafted exemplars. this method is then leveraged to prompt llms to generate cot exemplars by themselves for icl @xcite @xcite . different from our work, which focuses on eliciting rationales from llms, @xcite ; @xcite ; @xcite concentrate on selecting rationales generated according to @xcite . and chen et al. ( 2023 ) further incorporate pseudo task generation alongside self-generated cots. additionally, @xcite propose analogical prompting to solve emerging new tasks without 3 https://allenai.github.io/scispacy/ human-crafted demonstrations. importantly, these works mainly focus on prompting engineering for very large, closed-source lms (e.g., gpt-4). none of them formally investigate the fundamental in-context teaching among different lms. instead, our work proposes encoding specificity hypothesis to understand in-context teaching for llms, which is evidenced by experiments across different models. teaching via explanations. many past works have explored teaching student llms with teacher model's explanations through supervised fine-tuning @xcite @xcite . few have investigated in-context teaching. @xcite demonstrate that llms can learn from humancrafted explanations in context. instead of leveraging in-context exemplars, @xcite ; @xcite directly feed the teacher's explanations of test examples to the student model during inference. in this case, the taught model receives direct assistance with test examples, and thus, its generalization ability from the teacher is not evaluated. ## conclusion in this work, we investigate in-context teaching, where a teacher provides in-context example rationales to teach a student to reason over unseen questions. we introduce the encoding specificity hypothesis that incontext exemplars at test time should match the student model's related training examples. motivated by our hypothesis, we propose self-explain to let an llm teach itself with its self-explanations through in-context learning, which outperforms human-crafted chain-of-thoughts and other baselines in different reasoning tasks. we reveal that for in-context teaching, rationales by distinct teacher llms or human teachers that more resemble the student llm's selfexplanations are better demonstrations, which further supports the encoding specificity hypothesis. we then propose teach-back to align the teacher llm with the student, which can enhance the in-context teaching performance. prompting. they also demonstrate impressive performance on diverse models for knowledge reasoning without human guidance. the student model's performance with self-explain is consistently among the best. however, the student performance in teach-back does not necessarily surpass standard prompting with human cots, depending on the teacher model. for example, mistral-7b with teach-back enables different student models to reach optimal test performance, while teachers like llama2-7b are less effective. therefore, we suggest using self-explain as a starting point in real applications. in the future, we will further investigate the influence of the teacher model in teach-back on student performance and how finetuning affects the teacher model's self-explanations. overall, in this work, the main contribution of our proposed teach-back is that it can greatly improve the ability of one llm to teach a different student model. in addition, our work is limited to only one teacher. future work could explore many teachers, including mixture of experts. moreover, there are various emerging advanced prompting methods for different kinds of reasoning tasks, e.g., tree-of-thoughts @xcite or multi-round prompting @xcite . in this work, we do not consider these more advanced designs of prompting, but focus on commonly used cot prompting to eliminate the need of human-crafted cots. however, our approaches can be adapted to these methods e.g., by modifying the instructions used to elicit llms' rationales. the majority of these methods still require human-crafted demonstrations. we will further investigate whether llms can implement these advanced prompting methods without human-crafted exemplars under our framework in the future. "self-explain" is prompting gpt-3.5 with its selfexplanations elicited. "llm teacher" is using rationales generated by a separate model (mistral-7b) as teacher, while for "w/ teach-back", the teacher model has been first fine-tuned with gpt-3.5's selfexplanations.