Knowledgeable In-Context Tuning: Exploring and Exploiting Factual Knowledge for In-Context Learning (2024)

Abstract: Large language models (LLMs) enable in-context learning (ICL) by conditioning on a few labeled training examples as a text-based prompt, eliminating the need for parameter updates and achieving competitive performance. In this paper, we demonstrate that factual knowledge is imperative for the performance of ICL in three core facets: the inherent knowledge learned in LLMs, the factual knowledge derived from the selected in-context examples, and the knowledge biases in LLMs for output generation. To unleash the power of LLMs in few-shot learning scenarios, we introduce a novel Knowledgeable In-Context Tuning (KICT) framework to further improve the performance of ICL:1) injecting knowledge into LLMs during continual self-supervised pre-training, 2) judiciously selecting the examples for ICL with high knowledge relevance, and 3) calibrating the prediction results based on prior knowledge.We evaluate the proposed approaches on autoregressive models (e.g., GPT-style LLMs) over multiple text classification and question-answering tasks. Experimental results demonstrate that KICT substantially outperforms strong baselines and improves by more than 13% and 7% on text classification and question-answering tasks, respectively.

## introduction large language models (llms) have become an imperative infrastructure in the natural language processing (nlp) community @xcite . to enable pre-trained llms to perform well without any parameter updates, in-context learning (icl) has emerged as one of the flourishing research topics in many few-shot nlp tasks. it aims to generate predictions for target examples by conditioning on a few labeled samples (brown et al., 2020). as shown in figure 1 , the key component of icl is the text-based prompt (containing labeled examples) that functions as the demonstration. previous works have explored multiple aspects that affect the performance of icl @xcite , such as input-output mapping @xcite , extensive data resources @xcite @xcite , prediction calibration @xcite , and self-improvment @xcite . @xcite ; @xcite have investigated others, such as prompt format (e.g., "input:", "output:"), the selection of labeled data, and example permutation. @xcite ; @xcite have developed toolkits for llms to reason with icl prompts. in addition, to better elicit the llm to reason on complex tasks, chain-of-thought (cot) has been introduced to extend the icl with multiple rationales to express the thinking process @xcite @xcite @xcite . however, these works pay little attention to the influence of factual knowledge in icl, which is a non-negligible factor in nlp @xcite . to this end, we explore the effectiveness of icl from the perspective of factual knowledge. as seen in figure 2 , when entities and labels in text-based prompts are randomly replaced or removed, the average accuracy decreases significantly, indicating that performance degradation is universal across different model scales. further analysis reveals that: 1) more intrinsic factual knowledge acquired during the pre-training stage is typically beneficial for llms to improve effectiveness; 2) the factual knowledge (e.g., entities and labels) derived from selected in-context examples is crucial for the performance of icl; 3) llms tend to generate common words that may have high frequencies in the training corpora, resulting in biased predictions. after analyzing these knowledge facets, a natural question arises: how can we fully employ factual knowledge to further improve the performance of icl? to achieve this goal, we focus on causal autoregressive llms (e.g., gpt-2 @xcite and opt @xcite ) and present a novel knowledgeable in-context tuning (kict) framework, which involves knowledgeable guidance in pre-training, prompting, and prediction of these models. specifically, to endow llms with enhanced text generation abilities by better leveraging inherent knowledge, we introduce several knowledgeable self-supervised tasks during the pretraining stage to inject knowledge into llms. for text-based prompting, we propose a knowledgeable example retrieval algorithm to judiciously select in-context examples that have relevant knowledge to the target example. finally, during prediction, we utilize the knowledge-wise priors of label words from an underlying knowledge base (kb) to calibrate the prediction distributions generated by llms. each of the proposed techniques is plugand-play and can be freely combined, facilitating users to exploit knowledge for improving icl. to evaluate the effectiveness of the kict framework, we employ llms (e.g., gpt-style models) to conduct extensive experiments over multiple text classification and question-answering tasks. results demonstrate that each proposed procedure achieves substantial improvements. to sum up, we make the following main contributions: ## impact of knowledge on icl in this section, we investigate whether factual knowledge affects the performance of icl. ## the proposed kict framework the preliminary experiments demonstrate that factual knowledge has a substantial effect on icl. this suggests that we can exploit this knowledge to enhance performance across various processes in icl, including pre-training, prompting, and prediction. to achieve this goal, we introduce the kict framework, a novel knowledgeable in-context tuning framework designed to better leverage knowledge and unleash the power of llms in answer generation. within this framework, we introduce knowledgeable pre-training (kpt) with three carefully designed self-supervised tasks to infuse llms with factual knowledge. we then present a knowledgeable example retrieval (ker) algorithm to judiciously select in-context examples that are relevant to the given knowledge. finally, we employ a ## conclusion in this paper, we investigate and harness factual knowledge in icl, including inherent knowledge embedded in llms, pertinent knowledge derived from selected training examples, and knowledge biases affecting predictions. we introduce a novel knowledgeable in-context tuning (kict) framework to further enhance icl performance by comprehensively exploiting factual knowledge throughout the processes of pre-training, prompting, and prediction. experiments demonstrate that each introduced technique significantly improves upon strong baselines across classification and questionanswering tasks. future work will focuses on 1) exploring the reasoning capabilities and interpretability of knowledge within icl, and 2) extending our approach to encoder-decoder models.