Analyzing Redundancy in Pretrained Transformer Models (2020)

Abstract: Transformer-based deep NLP models are trained using hundreds of millions of parameters, limiting their applicability in computationally constrained environments. In this paper, we study the cause of these limitations by defining a notion of Redundancy, which we categorize into two classes: General Redundancy and Task-specific Redundancy. We dissect two popular pretrained models, BERT and XLNet, studying how much redundancy they exhibit at a representation-level and at a more fine-grained neuron-level. Our analysis reveals interesting insights, such as i) 85% of the neurons across the network are redundant and ii) at least 92% of them can be removed when optimizing towards a downstream task. Based on our analysis, we present an efficient feature-based transfer learning procedure, which maintains 97% performance while using at-most 10% of the original neurons.

## introduction large pretrained models have improved the stateof-the-art in a variety of nlp tasks, with each new model introducing deeper and wider architectures causing a significant increase in the number of parameters. for example, bert large @xcite , nvidia's megatron model, and google's t5 model @xcite were trained using 340 million, 8.3 billion and 11 billion parameters respectively. an emerging body of work shows that these models are over-parameterized and do not require all the representational power lent by the rich architectural choices during inference. for example, these models can be distilled @xcite or pruned @xcite , with a minor drop in performance. recent research @xcite analyzed contextualized embeddings in pretrained models and showed that the representations learned within these models are highly anisotropic. while these approaches successfully exploited over-parameterization and redundancy in pretrained models, the choice of what to prune is empirically motivated and the work does not directly explore the redundancy in the network. identifying and analyzing redundant parts of the network is useful in: i) developing a better understanding of these models, ii) guiding research on compact and efficient models, and iii) leading towards better architectural choices. in this paper, we analyze redundancy in pretrained models. we classify it into general redundancy and task-specific redundancy. the former is defined as the redundant information present in a pretrained model irrespective of any downstream task. this redundancy is an artifact of overparameterization and other training choices that force various parts of the models to learn similar information. the latter is motivated by pretrained models being universal feature extractors. we hypothesize that several parts of the network are specifically redundant for a given downstream task. we study both general and task-specific redundancies at the representation-level and at a more fine-grained neuron-level. such an analysis allows us to answer the following questions: i) how redundant are the layers within a model? ii) do all the layers add significantly diverse information? iii) do the dimensions within a hidden layer represent different facets of knowledge, or are some neurons largely redundant? iv) how much information in a pretrained model is necessary for specific downstream tasks? and v) can we exploit redundancy to enable efficiency? we introduce several methods to analyze redundancy in the network. specifically, for general redundancy, we use center kernel alignment @xcite for layer-level analysis, and correlation clustering for neuron-level analysis. for task-specific redundancy, we use linear probing @xcite to identify redundant layers, and linguistic correlation analysis @xcite to examine neuronlevel redundancy. we conduct our study on two pretrained language models, bert @xcite and xlnet @xcite . while these networks are similar in the number of parameters, they are trained using different training objectives, which accounts for interesting comparative analysis between these models. for task-specific analysis, we present our results across a wide suite of downstream tasks: four core nlp sequence labeling tasks and seven sequence classification tasks from the glue benchmark @xcite . our analysis yields the following insights: ## related work a number of studies have analyzed representations at layer-level @xcite @xcite @xcite and at neuron-level @xcite @xcite . these studies aim at analyzing either the linguistic knowledge learned in representations and in neurons or the general importance of neurons in the model. the former is commonly done using a probing classifier @xcite @xcite . recently, voita and titov (2020); @xcite proposed probing methods based on information theoretic measures. the general importance of neurons is mainly captured using similarity and correlationbased methods @xcite @xcite . similar to the work on analyzing deep nlp models, we analyze pretrained models at representation-level and at neuron-level. different from them, we analyze various forms of redundancy in these models. we draw upon various techniques from the literature and adapt them to perform a redundancy analysis. while the work on pretrained model compression @xcite @xcite @xcite indirectly shows that models exhibit redundancy, little has been done to explore the redundancy in the network. recent studies @xcite @xcite dropped attention heads and layers in the network with marginal degradation in performance. their work is limited in the context of redundancy as none of the pruning choices are built upon the amount of redundancy present in different parts of the network. our work identifies redundancy at various levels of the network and can guide the research in model compression. ## problem definition consider a pretrained model m with l layers: {l 0 , l 1 , . . . , l l }, where l 0 is an embedding layer and each layer l i is of size h. given a dataset @xmath0, w 2 , ..., w t } consisting of t words, the contextualized embedding of word w j at layer l i is z i @xmath1. a neuron consists of each individual unit of z i j . for example, bert-base has @xmath2, each of size 768 i.e. there are 768 individual neurons in each layer. the total number of neurons in the model are 13 × 768 = 9984. we analyze redundancy in m at layer-level l i : how redundant is a layer? and at neuron-level: how redundant are the neurons? we target these two questions in the context of general redundancy and task-specific redundancy. ## general redundancy neural networks are designed to be distributed in nature and are therefore innately redundant. additionally, over-parameterization in pretrained models with a combination of various training and design choices causes further redundancy of information. in the following, we analyze general redundancy at layer-level and at neuron-level. ## task-specific redundancy while pretrained models have a high amount of general redundancy as shown in the previous section, they may additionally exhibit redundancies specific to a downstream task. studying redundancy in relation to a specific task helps us understand pretrained models better. it further reflects on how much of the network, and which parts of the network, suffice to perform a task efficiently. ## efficient transfer learning in this section, we build upon the redundancy analysis presented in the previous sections and propose a novel method for efficient feature-based transfer learning. in a typical feature-based transfer learning setup, contextualized embeddings are first extracted from a pretrained model, and then a classifier is trained on the embeddings towards the downstream nlp task. the bulk of the computational expense is incurred from the following sources: we propose a three step process to target these two sources of computation bottlenecks: the three steps explicitly target task-specific layer redundancy, general neuron redundancy and task-specific neuron redundancy respectively. we refer to step 1 as layerselector (ls) and step 2 and 3 as ccfs (correlation clustering + feature selection) later on. for all experiments, we use a performance threshold of 1% for ls and ccfs each. it is worth mentioning that the tradeoff between loss in accuracy and efficiency can be controlled through these thresholds, which can be adjusted to serve faster turn-around or better performance. ## conclusion and future directions we defined a notion of redundancy and analyzed pre-trained models for general redundancy and task-specific redundancy exhibited at layer-level and at individual neuron-level. our analysis on general redundancy showed that i) adjacent layers are most redundant in the network with an exception of final layers which are close to the objective function, and ii) up to 85% and 92% neurons are redundant in bert and xlnet respectively. we further showed that networks exhibit varying amount of task-specific redundancy; higher layerlevel redundancy for core language tasks compared to sequence-level tasks. we found that at least 92% of the neurons are redundant with respect to a downstream task. based on our analysis, we proposed an efficient transfer learning procedure that directly targets layer-level and neuron-level redundancy to achieve efficiency in feature-based transfer learning. while our analysis is helpful in understanding pretrained models, it suggests interesting research directions towards building compact models and models with better architectural choices. for example, a high amount of neuron-level redundancy in the same layer suggests that layer-size compression might be more effective in reducing the pretrained model size while preserving oracle performance. similarly, our finding that core-linguistic tasks are learned at lower-layers and require a higher number of neurons, while sequence-level tasks are learned at higher-layers and require fewer neurons, suggests pyramid-style architectures that have wide lower layers and compact higher layers and may result in smaller models with performance competitive with large models.