Shapley Head Pruning: Identifying and Removing Interference in Multilingual Transformers (2023)

Abstract: Multilingual transformer-based models demonstrate remarkable zero and few-shot transfer across languages by learning and reusing language-agnostic features. However, as a fixed-size model acquires more languages, its performance across all languages degrades. Those who attribute this interference phenomenon to limited model capacity address the problem by adding additional parameters, despite evidence that transformer-based models are overparameterized. In this work, we show that it is possible to reduce interference by instead identifying and pruning language-specific attention heads. First, we use Shapley Values, a credit allocation metric from coalitional game theory, to identify attention heads that introduce interference. Then, we show that pruning such heads from a fixed model improves performance for a target language on both sentence classification and structural prediction. Finally, we provide insights on language-agnostic and language-specific attention heads using attention visualization.

## introduction cross-lingual transfer learning aims to utilize a natural language processing system trained on a source language to improve results for the same task in a different target language. the core goal is to maintain relevant learned patterns from the source while disregarding those which are inapplicable to the target. multilingual pretraining of transformer language models has recently become a widespread method for cross-lingual transfer; demonstrating remarkable zero and few shot performance across languages when finetuned on monolingual data @xcite @xcite . however, adding languages beyond a threshold begins to harm cross-lingual transfer in a fixedsize model as shown in prior work @xcite . this phenomenon, termed 1 we release code to compute shapley values on github interference, has been addressed with additional parameters, both language-specific @xcite and broadly @xcite . @xcite justifies this by showing that competition over limited capacity drives interference. this seems to contradict the lottery ticket hypothesis, which has shown that pretrained language models are highly overparameterized @xcite . we offer an alternate hypothesis that interference is caused by components that are specialized to language-specific patterns and introduce noise when applied to other languages. to test this hypothesis, we introduce a methodology that selectively removes noisy components to improve language-specific performance without updating or adding additional language-specific parameters. our work builds on prior research studying monolingual models that shows they can be pruned aggressively @xcite . we leverage shapley values, the mean marginal contribution of a player to a collaborative reward, to identify attention heads that cause interference. unlike prior methods, shapley values map each head to positive and negative values in a way that abides by all axioms of fair attribution @xcite . therefore, negative values soundly mark interfering heads where removal will improve performance. we approximate shapley values in a computationally tractable but functionally accurate manner using truncation and multi-armed bandit sampling following prior work in computer vision @xcite . we contribute the following: ## methods to identify and remove interference, we need a metric that can separate harmful, unimportant, and beneficial attention heads. prior work @xcite utilized the magnitude of gradients as an importance metric. however, this metric measures the sensitivity of the loss function to the masking of a particular head. defined in this way, importance will spike indiscriminately for both harmful and beneficial heads. therefore, we develop a simple yet effective method to separate these classes. shapley values @xcite have often been applied in model interpretability since they are the only attribution method to abide by the theoretical properties of local accuracy, missingness, and consistency laid out by lundberg and @xcite . in our setting, shapley values have two advantages over gradient-based importance metrics. firstly, gradient-based approaches require differentiable re-laxations of evaluation functions and masking, but shapley values do not. therefore, we can instead use the evaluation functions and binary masks directly. secondly, shapley values are meaningfully signed which allows them to distinguish beneficial, unimportant, and harmful heads rather than just important and unimportant heads. this latter property is essential for our goal of identifying interference. we apply shapley values to the task of structural pruning. in order to compute shapley values for each head, we first formalize the forward pass of a transformer as a coalitional game between attention heads. then, we describe a methodology to efficiently approximate shapley values using monte carlo simulation combined with truncation and multi-armed bandit search. finally, we propose a pruning algorithm using the resulting values to evaluate the practical utility of this theoretically grounded importance metric. ## qualitative attention analysis in order to provide intuition into the function of attention heads, prior work has turned to attention visualization as the basis for qualitative analysis of the inner workings of transformer models. @xcite and @xcite both explore patterns within attention heads. we visualize the attention patterns of outlier attention heads using bertviz @xcite from our model to give a qualitative understanding of the attention head patterns associated with languageagnostic and language-specific heads. ## conclusions & future work in this work, we developed a simple yet effective approach to measure the impact of individual attention heads on task performance by leveraging shapley values. we used this to identify languagespecific and language-agnostic structural components of multilingual transformer language models. we demonstrated that the resulting values exhibit language affinity, varying across languages. we then applied these attention head shapley values to improve cross-lingual performance through pruning for both sequence classification and structured prediction. finally, we performed provided insights on language-agnostic and language-specific attention heads using attention visualization. we believe that attention head shapley values have strong potential to systematically inform future studies of multilingual models and transformers broadly. future work should explore the relationship between linguistic features, training data volume, and the language-specificity of attention heads. additionally, the benefits of removing heads motivates work that reduces cross-lingual interference introduced by language-specific components during pre-training, such as pruning during pretraining or utilizing sparsely activated networks.