Steering Large Language Models for Machine Translation with Finetuning and In-Context Learning (2023)

Abstract: Large language models (LLMs) are a promising avenue for machine translation (MT). However, current LLM-based MT systems are brittle: their effectiveness highly depends on the choice of few-shot examples and they often require extra post-processing due to overgeneration. Alternatives such as finetuning on translation instructions are computationally expensive and may weaken in-context learning capabilities, due to overspecialization. In this paper, we provide a closer look at this problem. We start by showing that adapter-based finetuning with LoRA matches the performance of traditional finetuning while reducing the number of training parameters by a factor of 50. This method also outperforms few-shot prompting and eliminates the need for post-processing or in-context examples. However, we show that finetuning generally degrades few-shot performance, hindering adaptation capabilities. Finally, to obtain the best of both worlds, we propose a simple approach that incorporates few-shot examples during finetuning. Experiments on 10 language pairs show that our proposed approach recovers the original few-shot capabilities while keeping the added benefits of finetuning.

## introduction large language models (llms) have shown remarkable performance on a wide range of nlp tasks by leveraging in-context learning @xcite . in particular, when provided with fewshot examples, these models have demonstrated impressive capabilities for performing machine translation (mt) without requiring explicit supervision on parallel data @xcite . however, this approach exhibits several drawbacks: performance is highly dependent on the quality of examples @xcite , outputs are plagued by overgeneration @xcite , and inference costs are greatly increased by processing all input pairs. when parallel data is available, llms can alternatively be finetuned on translation instructions @xcite . this method generally outperforms few-shot prompting and eliminates the need for in-context examples. however, it remains unclear whether finetuned models can benefit from the desirable properties of in-context learning, such as on-the-fly domain adaptation @xcite . additionally, traditional finetuning @xcite incurs a high computational overhead due to the cost of updating all the model weights. in this paper, we provide a closer examination of the impact of finetuning and few-shot prompting for adapting llms to perform translation. our experiments encompass 10 language pairs on general and specific domains, comprising over 100,000 generated translations ( §2). our main findings are: this method matches the performance of traditional finetuning at a fraction of the computational cost, by training 50 times fewer parameters. it also achieves better translation quality than in-context learning and eliminates the need for post-processing the generated outputs and selecting in-context examples. ## experimental setup in our experiments, we use llama 7b and 13b @xcite as backbone language models and finetune them with the standard cross entropy loss. we train our models on general domain opus @xcite data from the europarl, globalvoices, paracrawl, tilde, ubuntu, and wikipedia domains. we consider the languages dutch (nl), french (fr), german (de), portuguese (pt) and russian (ru), both from and into english (en). 2 to ensure the quality of the training records, we first apply bicleaner @xcite using a threshold of 0.85 and then filter the remaining pairs, ensuring both language directions have a cometkiwi @xcite ) score above 0.8. finally, we sample 250k records for each language pair. during training, we uniformly sample from the data to ensure each language pair is seen a similar number of times. we perform validation on the flores-200 development set for the language pairs in the training data. for in-domain evaluation, we consider the flores-200 @xcite test dataset on all the translation directions included during training, as well as the wmt22 test sets foot_2 for the language pairs considered in our training data. regarding data for specialized domains, we consider the medical and law domains from @xcite , the tico dataset @xcite and @xcite . we evaluate our models on zero and five shot settings, uniformly sampling for each test sentence five independent few-shot samples from the respective development set. our main evaluation metric is comet @xcite foot_3 . we also report results with bleu @xcite , chrf @xcite and cometkiwi @xcite in appendix g. we refer the reader to appendix a for full details on hyperparameters and instruction formats used in the following experiments. 0 8 40 80 120 160 training examples (in thousands) 70 75 80 85 90 comet pretrained en-xx pretrained xx-en finetuned en-xx finetuned xx-en figure 2: comet scores for zero-shot evaluation on the flores-200 test set by llama 7b finetuned with differing amounts of training data. ## finetuning llms on mt instructions in this section, we investigate the performance of llms finetuned on machine translation instructions in relation to few-shot prompting with a pretrained language model. note that, throughout this section, we always analyse few-shot prompting for the pretrained model. we deem that this offers a fairer comparison to finetuning on translation instructions, since both methods have access to training examples. nevertheless, we also provide the results for zero-shot translation with the pretrained model in appendix g. similar to the findings in bawden and yvon (2023), zero-shot performance is far behind few-shot performance, in particular for outof-english language pairs, likely due to the prevalence of english data during the pretraining of the llama models. ## finetuning with few-shot examples in order to recover few-shot performance, we introduce instructions with few-shot examples in the training process: namely, we finetune on data which contains both zero-shot and few-shot instructions. following @xcite , we uniformly sample between 0 and 5 few-shot examples for each training example from an example pool previously separated from the training data. 8 from here, we build an instruction prompt with the training example and the selected examples and proceed with the training. in figure 3 , we observe that the models trained with in-context examples recover their few-shot capabilities, both for the general and specialized domains. the few-shot performance is on par or above the zero-shot performance, further suggesting that the models are extracting helpful information from the examples. in appendix d, we present a set of examples that highlight these gains. ## conclusion in this paper, we provide a study on finetuning and few-shot prompting for adapting llms for translation. we show that adapter-based finetuning matches the performance of traditional finetuning while training 50 times fewer parameters. additionally, finetuning with adapters outperforms few-shot prompting of large language models and eliminates the need for output post-processing and in-context examples. in addition, we show that finetuned models exhibit poor performance when prompted with in-context examples. to address this issue, we propose a simple approach that mixes few-shot prompts during finetuning. our results show that we recover the original few-shot capabilities and retain the benefits of finetuning.