Language Models can Exploit Cross-Task In-context Learning for Data-Scarce Novel Tasks (2024)

Abstract: Large Language Models (LLMs) have transformed NLP with their remarkable In-context Learning (ICL) capabilities. Automated assistants based on LLMs are gaining popularity; however, adapting them to novel tasks is still challenging. While colossal models excel in zero-shot performance, their computational demands limit widespread use, and smaller language models struggle without context. This paper investigates whether LLMs can generalize from labeled examples of predefined tasks to novel tasks. Drawing inspiration from biological neurons and the mechanistic interpretation of the Transformer architecture, we explore the potential for information sharing across tasks. We design a cross-task prompting setup with three LLMs and show that LLMs achieve significant performance improvements despite no examples from the target task in the context. Cross-task prompting leads to a remarkable performance boost of 107% for LLaMA-2 7B, 18.6% for LLaMA-2 13B, and 3.2% for GPT 3.5 on average over zero-shot prompting, and performs comparable to standard in-context learning. The effectiveness of generating pseudo-labels for in-task examples is demonstrated, and our analyses reveal a strong correlation between the effect of cross-task examples and model activation similarities in source and target input tokens. This paper offers a first-of-its-kind exploration of LLMs’ ability to solve novel tasks based on contextual signals from different task examples.

## introduction large language models (llms) have revolutionized the state of natural language processing for the past few years. with the ability of in-context learning (icl), one can adopt an llm to almost any task without costly gradient updates @xcite . at the same time, automated assistants, built on top of foundational llms, are * equal contribution named in alphabetical order being popularized @xcite . a crucial challenge with this escalating usage popularity is handling novel tasks. humongous models like gpt-4 are able to deliver up-to-par performance even in a zero-shot regime @xcite . however, the computational requirements of deploying such large-scale models counteract the practicality of their usage en masse. relatively smaller lms, on the other hand, suffer drastically in the absence of in-context examples. the availability of labeled examples usually varies across the use cases of the language model. for example, in an nlp research setup, expert users can quickly come up with a few handwritten examples. however, when we consider mass-scale usage of average users who are not experienced prompt engineers or need quick answers, the zero-shot performance of a model becomes extremely crucial. for example, assuming the popular usage of chatgpt, very few non-expert users would opt to write down examples while asking chatgpt to perform some tasks. this naturally raises the question of whether one can make an llm generalize from labeled examples of a predefined set of tasks to an input defining a novel task. in the world of biological neurons, such abilities are commonplace: inculcating specific limb usage into an untrained limb while training the opposite limb @xcite , or relatively easier adoption of newer skills from the culminated experience of older skills @xcite . drawing a blunt parallel between biological neurons and llms would be naive. however, one can find a supporting intuition in the mechanistic interpretation of the transformer architecture @xcite @xcite . one can argue that if information pathways necessary to solve a novel task are similar to those corresponding to some different task from a task library, an llm may gather useful information across tasks. earlier evidence found by @xcite also elicits intuitive motivation as they showed that llms can learn to infer from cross-lingual examples if proper alignment is provided. in this work foot_0 , we design a cross-task prompting setup (section 2) using three different llms: llama-2 7b and 13b, and gpt 3.5; we select 50 different pairs of tasks where one serves as a source (i.e., context example task) and the other as target. despite no examples from the target task presented in the context, llms can produce a staggering improvement over the zero-shot regime; on average, cross-task prompting improves performance by 107% for llama-2 7b, 18.6% for llama-2 13b and 3.2% for gpt 3.5 (section 3). with multiple source tasks, cross-task performance is even better than, if not comparable, usual in-task prompting (contribution #1). however, learning from examples of different tasks is heavily sensitive to the choice of source task for a given target and the llm is prone to copy the label space of the source task into the target. to circumvent this, we propose a pseudo-labeling based approach: in a data-scarce setup, cross-task prompting with majority voting is first employed to generate noisy, in-task examples; these are subsequently used for standard few-shot prompting (contribution #2). finally, we provide introductory analysis towards interpreting cross-task signal transfer by dissecting the model activations. we find that the cross-task signal transfer is abrupt and happens at later layers, with the effective layers widely varying for different target tasks (contribution #3). in a nutshell, this is the first exploration of llms' ability to learn to solve novel tasks based on the contextual signals of different task examples. ## prompting techniques task definition for a given task is a natural language instruction for the lm describing what is asked of it (see figure 1 ). since a cross-task setup would result in in-context examples from different tasks (with different label spaces), such a definition is necessary to discriminate. next, given two datasets d s and d t corresponding to two different tasks with task definitions d s and d t , respectively, we formalize the cross-task prompting as inferring the output ŷt for an input x @xmath0: in this setup, we denote d s and d t as source and target task datasets, respectively. note that the formalization is equivalent to 1-shot prompting where the only provided example input-output pair comes from a different dataset. drawing inspiration from these works, we set up the cross-task prompting regime with sampling examples x s from the source task dataset d s that are semantically similar to the target input x t . to extract semantically similar examples, we first utilize sentence-bert @xcite to extract the sentence embedding of target and source inputs foot_1 . following this, based on the cosine similarity between the embeddings, we select top source examples. in-task examples combined with cross-task prompting. so far, we have assumed the unavailability of any labeled target dataset. but, if we do have a labeled target example, could prepending a source task boost its prompting performance? to emulate such a scenario, a labeled example from the target dataset t t is sampled. this labeled example (x lt , y lt ), where x @xmath2, is then used to construct prompt. this mixed setup can be formalized as, examples of prompts are provided in ## results and analysis datasets and experimental setup. our corpus of tasks consists of ten source and five target tasks. definition: you are given a passage as context and a question related to the passage that can be answered as "true" or "false". based on the context, question and your reasoning ability answer in a "true" and "false". context: many organisms, the action potential is actually initially carried.... question: do all neurons have the same action potential? answer: false context: intersex is in some caused by unusual sex hormones.... question: can u be born with both male and female parts? answer: true context: the gregorian leap cycle, which has 97 leap days spread.... question: are there ever 53 weeks in a year? answer: true definition: given a question from a scientific exam about physics, chemistry, and biology, among others. the question is in multiple choice format with four answer options a., b., c. and d. using your knowledge about the scientific fields answer the question and provide the label a, b, c and d as answer. question: which of the following is not true for myelinated nerve fibers: a. impulse through ........ neural fibers b. membrane ...... of ranvier c. saltatory .... is seen d. local anesthesia ....... when the nerve is not covered by myelin sheath ## pseudo-label generation using cross-task prompting thus far we observe that cross-task prompting, though sometimes capable of even outperforming standard in-task prompting, is particularly sensitive to the choice of source task. furthermore, the performance does not scale with the number of source task examples provided. drawing inspiration from earlier works on pseudo-labeled examples to construct prompts @xcite , we propose a more practical method for potential usage of cross-task prompting. given a small unlabeled dataset d pl ⊂ d t , we assign a pseudo-label to the example using crosstask prompting. this is done using all source tasks available to us, and then a final y pl is assigned to x @xmath3. finally, this pseudo-labeled dataset d pl is used to construct the prompt context in an in-context prompting setup. ## interpretability analysis in this section, we focus on the internal workings of the llms using the hidden states of the model and build an understanding of why and how cross-task prompting works. what is an ideal source task? intuitively thinking of a source task that is similar to the target will result in better transfer of generalised signal from context to target inputs. to test this, we first compare the final layer outputs of the model corresponding to the source and target task definitions, d s and d t , respectively. figure 4 shows the cosine similarity between the final layer hidden states corresponding to d s and d t . we note that for 80% of the time, the source definition that is the most semantically similar to the target definition also serves as its best suitor, leading to the best performance in ## error analysis we observe four types of error occurring in crosstask prompting (c.f. sentence: net profit 6.08 vs 3.98 label: jj nn cd nnp cd definition: given a sentence ... label the sentence as "negative", "positive" or "neutral" sentence: consolidated net sales increased 16 % ... to a loss of eur0 .7 m in the prior year period. label: definition: given a sentence do token classification ... till the entity ends. sentence: total shares to be offered 2.5 million label: o o o o o o o definition: given a sentence ... label the sentence as "negative", "positive" or "neutral" sentence: the offer of some 30 million shares ... expected to be completed by oct. 9 , outokumpu said. label: n n n n n n n 3. definition: given a question answering task . in example #2, the source task is to classify each token into one named entity category (ner), and the target task is to predict the financial sentiment. the output in this case is found to be junk -it is a sequence of n's but n is not a pre-defined named entity category, neither is it a label for the target task. further, we observe that the correct label in this example is 'neutral' -the llm could not follow the target task definition provided and gets confused between the correct prediction label of the target task and the token classification task where the output is expected to be a sequence of labels, and instead outputs a sequence with the initial letter of the correct label. copying effect: we also notice the copying effect, which has been observed by @xcite , where the predicted label is the same as the label of the context example which is semantically very similar to the target input. in example #3, the target input is semantically very similar to the context ex-ample from the source task provided in the prompt, and consequently, the llm incorrectly outputs the same label as that of the context example. definition not followed: we observe that for some instances the llm does not adhere to the definition given in the form of task definition for the target task. in example #4, the llm is supposed to output one among the four options a, b, c, d, instead it outputs the text corresponding to the option dthough d is the correct answer in this case, the llm is not able to follow the definition properly. tanwar et al. (2023) showed that crosslingual icl can be elicited with proper alignment between the source and target language examples. raffel et al. (2020) introduced the t5 transformer model which has been trained to perform different text-processing tasks. zhang et al. (2022) proposed a task prefix guided multi-task pre-training framework to solve this problem. more recently, a new prompting method called meta-cot has been proposed by zou et al. (2023) which generalizes chain-of-thought prompting to include multi-task examples in the prompt and it has shown improvement in a number of tasks. ## conclusion in this paper, we addressed llms' adaptability to novel tasks. exploiting the inherent icl capabilities of these models, we established that llms can substantially enhance their performance in novel task scenarios, even when direct examples are lacking. this encouraging outcome unveils fresh possibilities for the practical integration of llms across a broader spectrum of applications. furthermore, our study demonstrated the significance of generating pseudo-labels using cross-task prompting, presenting a potential solution for situations where annotated data is scarce. the observed correlation between the impact of cross-task examples and the similarity in model activations between source and target input tokens offers valuable insights into the underlying mechanisms of this phenomenon.