Unveiling the Generalization Power of Fine-Tuned Large Language Models (2024)

Abstract: While Large Language Models (LLMs) have demonstrated exceptional multitasking abilities, fine-tuning these models on downstream, domain-specific datasets is often necessary to yield superior performance on test sets compared to their counterparts without fine-tuning. However, the comprehensive effects of fine-tuning on the LLMs’ generalization ability are not fully understood.This paper delves into the differences between original, unmodified LLMs and their fine-tuned variants. Our primary investigation centers on whether fine-tuning affects the generalization ability intrinsic to LLMs. To elaborate on this, we conduct extensive experiments across five distinct language tasks on various datasets.Our main findings reveal that models fine-tuned on generation and classification tasks exhibit dissimilar behaviors in generalizing to different domains and tasks.Intriguingly, we observe that integrating the in-context learning strategy during fine-tuning on generation tasks can enhance the model’s generalization ability.Through this systematic investigation, we aim to contribute valuable insights into the evolving landscape of fine-tuning practices for LLMs.

## introduction the transformative impact of in-context learning (icl) @xcite @xcite @xcite in llms, as demonstrated by models like @xcite and gpt-3 @xcite , marks a significant advancement in the field of artificial intelligence. this learning paradigm allows llms to adapt to * *this research/paper was partially supported by the center for perceptual and interactive intelligence (cpii) ltd. under the innovation and technology commission's innohk scheme. there are some works studying the properties of fine-tuning and icl for llms. for example, @xcite reveal that multi-task fine-tuning can enhance an llm's zero-shot and icl capabilities. it indicates that fine-tuning, when applied across multiple tasks, does not merely improve performance on those seen tasks but also augments the model's inherent learning abilities. the work of @xcite highlights that in terms of the out-of-domain generalization in classification tasks, few-shot fine-tuning and icl exhibit similar levels of generalization. @xcite find that fine-tuning may overly tailor the model to task-specific formats, potentially compromising its adaptability to other new tasks. in this paper, we conduct a comprehensive study on how task-specific (not multi-task or few-shot) fine-tuning affects the generalization ability of llms. to provide a thorough analysis, we design a series of experiments encompassing a diverse range of datasets and tasks, covering both classification and generation tasks. for each task, we designate a specific dataset as the training set. the remaining selected datasets are subsequently divided into two groups: in-domain datasets, closely aligned with the training set in terms of content and structure, and out-of-domain datasets, which possess significant differences. with these datasets, our research investigates two critical questions: i) the ability of fine-tuned llms to adapt to both in-domain and out-of-domain test sets, and ii) the impact of finetuning on the icl ability of llms across different types of tasks. we find that models fine-tuned on text genera-tion and classification tasks exhibit different behaviors when evaluated on test sets. specifically, we observe that models fine-tuned for classification tasks tend to exhibit positive transfer when applied to out-of-domain datasets of the same finetuning/test task type. in contrast, models fine-tuned on generation tasks frequently experience negative transfer under similar conditions. interestingly, while fine-tuning the llms on generation tasks generally does not detrimentally affect their performance on classification tasks, the reverse is not true; models fine-tuned on classification tasks typically fail to work on generation tasks. moreover, we experimentally observe that integrating the icl strategy during fine-tuning on generation tasks can enhance an llm's generalization ability. we also investigate other factors, such as training data size and the number of in-context examples. we hope this study offers comprehensive insights into finetuning strategies for llms, not only in enhancing task-specific performance but also in fostering broader generalization abilities. ## fine-tuning with in-context learning on generation tasks helps improve the generalization ability of llms in sec. 4.2, our analysis reveals that llms finetuned on classification tasks exhibit robust generalization capabilities under out-of-domain scenarios. however, for generation tasks, the fine-tuned models consistently fall short compared to baseline. in this section, we aim to show that fine-tuning with in-context learning (fticl) can help improve llms' out-of-domain generalization for generation tasks. fticl leverages the strengths of both fine-tuning and icl. specifically, instead of directly forwarding the original input into llms during fine-tuning, fticl prepends in-context examples to the input and forwards the llms with this newly constructed input. note that this strategy has also been adopted to mitigate other fine-tuning issues. for example, @xcite find that fticl leads to a substantial improvement in terms of input length generalization. in our experiment, we fine-tune the fticl models using 2,000 samples. for each generation task, we train two models with 1 or 2 in-context examples prepended in input, respectively. the results are presented in figure 4 and figure 5 . the following findings regarding generalization are organized in terms of the same or different fine-tuning/test tasks. ## conclusion this study comprehensively investigates the effects of fine-tuning on the llms' generalization ability. we conduct systematic experiments by evaluating the fine-tuned llms across various training data and language tasks. experimental results indicate that dissimilar generalization ability after fine-tuning arises from the nature of generation or classification tasks. further, we show that finetuning with in-context learning can enhance the generalization capability for generation tasks. we hope our findings can inspire future advancements in understanding and effectively utilizing llms to solve new tasks.