Sequence Length is a Domain: Length-based Overfitting in Transformer Models (2021)

Abstract: Transformer-based sequence-to-sequence architectures, while achieving state-of-the-art results on a large number of NLP tasks, can still suffer from overfitting during training. In practice, this is usually countered either by applying regularization methods (e.g. dropout, L2-regularization) or by providing huge amounts of training data. Additionally, Transformer and other architectures are known to struggle when generating very long sequences. For example, in machine translation, the neural-based systems perform worse on very long sequences when compared to the preceding phrase-based translation approaches (Koehn and Knowles, 2017). We present results which suggest that the issue might also be in the mismatch between the length distributions of the training and validation data combined with the aforementioned tendency of the neural networks to overfit to the training data. We demonstrate on a simple string editing tasks and a machine translation task that the Transformer model performance drops significantly when facing sequences of length diverging from the length distribution in the training data. Additionally, we show that the observed drop in performance is due to the hypothesis length corresponding to the lengths seen by the model during training rather than the length of the input sequence.

## introduction current state-of-the-art transformer-based sequence generation models, either fine-tuned for chosen downstream tasks @xcite , or trained from scratch for specific tasks such as machine translation @xcite or speech recognition @xcite , more and more often achieve performance comparable to that of humans @xcite @xcite . however, such models frequently require billions of trainable parameters together with huge amounts of data (billions of tokens) to reach such performance @xcite . the good performance on held-out test sets seems to confirm the good generalization power of these models, although the inherent strong biases, sometimes leading to the use of a foul and toxic language, preserving stereotypes, etc., are well acknowledged @xcite . @xcite claim that their transformer model is also capable of simple arithmetics, however, it is yet to be validated whether the model truly learns the arithmetic algorithms or simply encodes a lookup table for a subset of specific examples. in this paper, we argue that the assumed generalization power of the current state-of-the-art transformer-based language generators does not come from the architecture itself but rather from the sheer volume of training data and the model's ability to exploit the similarities between the training and validation data. we demonstrate how the transformer-based sequence-to-sequence models fail when the target sequence lengths of the training and validation data do not match. we show that this holds not only for very long test sequences but can be observed even with short sequences if they are omitted from the training data. furthermore, we show that we can artificially improve the test performance on longer sequences by only using shorter training sequences and concatenating them into longer training examples. we do not argue about transformer's (in)ability to handle long-distance dependencies, but our results suggest that a considerably simpler reason of mismatching sequence length can also contribute to the performance drop. we think that our findings can lead to better understanding of the transformer architecture and help to design better training schemes (e.g. curriculum learning). ## related work the problem of modeling very long sequences has been studied mainly in the context of recurrent neural networks (rnns). early studies showed that using lstms @xcite and introducing attention @xcite can improve the model performance on long sequences. however, these models still got outperformed on long sequences by phrasebased models @xcite . this problem was not resolved with the introduction of transformers @xcite . surprisingly, even though there were previous studies explaining the weaknesses of rnns with respect to long sequence modeling @xcite , similar analyses are yet to be done for transformers which are fundamentally different from rnns. there is an ongoing debate about the proper way of splitting the available data to training and evaluation subsets. @xcite show that using only standard dataset splits can lead to a biased evaluation resulting in overestimating the generalization ability of the model. furthermore, @xcite argue that even using randomly sampled dataset splits does not solve the overestimation problem. they instead suggest using multiple test sets possibly of an adversarial nature to properly evaluate the generalization ability of the model. in the following experiments, we evaluate vanilla transformer on such adversarial splits created with respect to the lengths of the modeled sequences. although similar analyses were performed in the past @xcite , it was at a smaller scale and mainly in the context source-side length bucketing. ## experiments we demonstrate the lack of ability to generalize to sequences of lengths not seen during training on two separate tasks: string editing and machine translation (mt). we use fairseq framework for sequence-tosequence learning @xcite in our experiments. 1 details about the model parameters and training are available in appendix a. ## conclusion we showed in our targeted experiment that vanilla transformer sequence-to-sequence models have a strong tendency to overfit with regard to the targetside length of the training sequences. on a simple algorithmic task, we documented that transformer can generalize very well to unseen examples within the same length bucket but falls short if the same task is required for input of a different length, shorter or longer. the algorithm of the task, even if very simple, is not learned. we further confirmed the overfitting problem on the machine translation task. this suggests that long-distance dependencies are not the only reason behind the decreased performance when translating very long sentences. we think that our findings can shed a new light on specific areas of deep learning research, namely domain adaptation and curriculum learning. we also showed that data augmentation can tackle the data sparsity in the domain of very long sentences.