SlowGuess/NAACL_2021_OCR huggingface dataset:
Md Rizwan Parvez
rizwan@cs.ucla.edu
Transfer learning that adapts a model trained on data-rich sources to low-resource targets has been widely applied in natural language processing (NLP). However, when training a transfer model over multiple sources, not every source is equally useful for the target. To better transfer a model, it is essential to understand the values of the sources. In this paper, we develop SEAL-Shap, an efficient source valuation framework for quantifying the usefulness of the sources (e.g., domains/languages) in transfer learning based on the Shapley value method. Experiments and comprehensive analyses on both cross-domain and cross-lingual transfers demonstrate that our framework is not only effective in choosing useful transfer sources but also the source values match the intuitive source-target similarity.
Transfer learning has been widely used in learning models for low-resource scenarios by leveraging the supervision provided in data-rich source corpora. It has been applied to NLP tasks in various settings including domain adaptation (Blitzer et al., 2007; Ruder and Plank, 2017), cross-lingual transfer (Tackstrom et al., 2013; Wu and Dredze, 2019), and task transfer (Liu et al., 2019b; Vu et al., 2020).
A common transfer learning setting is to train a model on a set of sources and then evaluate it on the corresponding target (Yao and Doretto, 2010; Yang et al., 2020).<sup>1</sup> However, not every source corpus contributes equally to the transfer model. Some of them may even cause a performance drop (Ghorbani and Zou, 2019; Lin et al., 2019). Therefore, it is essential to understand the value of each source in the transfer learning not only to achieve
Figure 1: SEAL-Shap estimates the value of each source corpus by the average marginal contribution of that particular source corpus to every possible subset of the source corpora. Each block inside SEAL-Shap denotes a possible subset and the marginal contribution is derived by the difference of transfer results while trained with and without the corresponding source. Based on the source values, we select a subset of source corpora that achieves high transfer accuracy.
a good transfer performance but also for analyzing the source-target relationships.
Nonetheless, determining the value of a source corpus is challenging as it is affected by many factors, including the quality of the source data, the amount of the source data, and the difference between source and target at lexical, syntax and semantics levels (Ahmad et al., 2019; Lin et al., 2019). The current source valuation or ranking methods are often based on single source transfer performance (McDonald et al., 2011; Lin et al., 2019; Vu et al., 2020) or leave-one-out approaches (Tommasi and Caputo, 2009; Li et al., 2016; Feng et al., 2018; Rahimi et al., 2019). They do not consider the combinations of the sources. Consequently, they may identify the best single source corpus effectively but their top- $k$  ranked source corpora may achieve limited gain in transfer results.
In this paper, we introduce SEAL-Shap (Source
After, we focus on two transfer learning scenarios: (1) and (2) cross-domain. We train a model on a corpus and evaluate on a target corpus where it refers to the corresponding domain or language.
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 5084-5116 June 6-11, 2021. ©2021 Association for Computational Linguistics
sElection for trAnswer Learning via Shapley value), a source valuation framework $^2$  (see Fig 1) based on the Shapley value (Shapley, 1952; Roth, 1988) in cooperative game theory. SEAL-Shap adopts the notion of Shapely value to understand the contribution of each source by computing the approximate average marginal contribution of that particular source to every possible subset of the sources.
Shapley value is a unique contribution distribution scheme that satisfies the necessary conditions for data valuation like fairness and additivity (Dubey, 1975; Jia et al., 2019a,b). As many model explanation methods including Shapley value are computationally costly (Van den Broeck et al., 2021), in a different context of features and data valuation in machine learning, Ghorbani and Zou (2019) propose to use an approximate Shapley value to estimate the feature or data values.
However, the existing approximation methods for estimating Shapley values are not scalable for NLP applications. NLP models are often large (e.g., BERT (Devlin et al., 2019)) and NLP transfer learning usually assumes a large amount of source data. To deal with the scalability issue, we propose a new sampling scheme, a truncation method, and a caching mechanism to efficiently approximate the source Shapley values.
We evaluate the effectiveness of SEAL-Shap under various applications in quantifying the usefulness of the source corpora and in selecting potential transfer sources. We consider two settings of source valuation or selection: (1) where a small target corpus is available; and (2) where we only have access to the linguistic or statistical features of the target, such as language distance to the sources, typological properties, lexical overlap etc. For the first setting, we use the small target data as the validation set to measure the values of the sources w.r.t the target. For the second setting, we follow Lin et al. (2019) to train a source ranker based on SEAL-Shap and the available features.
We conduct extensive experiments in both (zero-shot) cross-lingual and cross-domain transfer settings on three NLP tasks, including POS tagging, sentiment analysis, and natural language inference (NLI) with different model architectures (BERT and BiLSTM). In a case study, on the cross-lingual transfer learning, we exhibit that the source language values are correlated with the language
family and language distance—indicating that our source values are meaningful and follow the intuitive source-target relationships. Lastly, we analyze the approximation correctness and the run-time improvement of our source valuation framework SEAL-Shap.
2 Source Valuation Framework
We propose SEAL-Shap, a source valuation framework. We start with the setting where we have only one target and multiple sources. We denote the target corpus by  $V$  and the corresponding set of source corpora by  $\mathcal{D} = \{D_1,\dots ,D_m\}$ . Our goal is to quantify the value  $\Phi_j$  of each source corpus  $D_{j}$  to the transfer performance on  $V$  and explain model behaviors. Once the source values are measured, we can then develop a method to select either all the sources or a subset of sources (i.e.,  $\subseteq \mathcal{D}$ ) that realizes a good transfer accuracy on  $V$ . Below, we first review the data Shapley value and its adaptation for transfer learning. Then, we describe how SEAL-Shap efficiently quantifies  $\Phi_j$  and how to use it to select a subset of sources for model transfer.
2.1 Background: Data Shapley Value
Shapley value is designed to measure individual contributions in collaborative game theory and has been adapted for data valuation in machine learning (Ghorbani and Zou, 2019; Jia et al., 2019a,b). In the transfer learning setting, on a target corpus  $V$ , let  $Score(C_{\Omega}, V)$  represent the transfer performance of a model  $C$  trained on a set of source corpora  $\Omega$ . The Shapley value  $\Phi_j$  is defined as the average marginal contribution of a source corpus  $D_j$  to every possible subsets of corpora  $\mathcal{D}$ :
$$
\frac{1}{m}\sum_{\Omega \subseteq \mathcal{D} - D_{j}}\frac{Score(C_{\Omega\cup D_{j}},V) - Score(C_{\Omega},V)}{\binom{m - 1}{|\Omega|}}.
$$
TMC-Shap for Transfer Learning: Computing the exact source-corpus Shapley value, described above, is computationally difficult as it involves evaluating the performances of the transfer models trained on all the possible combinations of the source corpora. Hence, Ghorbani and Zou (2019) propose to approximate the evaluation by
3In this paper, we consider a model trained on the union of the source data and the loss function for training the model is aggregated from the loss functions defined on each source. However, our approach is agnostic to how the model is trained and can be integrated with other training strategies.
2Our source codes are available at https://github. com/rizwan09/NLPDV/
a truncated Monte Carlo method. Given the target corpus  $V$  and a set of source corpora  $\mathcal{D}$ , for each epoch, a source training data set  $\Omega \subseteq \mathcal{D}$  is maintained and a random permutation  $\pi$  on  $\mathcal{D}$  is performed (corresponds to line 6 in Algorithm 1 which is discussed in Sec 2.2). Then it loops over every source corpus  $\pi_j$  in the ordered list  $\pi$  and compute its marginal contribution by evaluating how much the performance improves by adding  $\pi_j$  to  $\Omega$ :  $Score(C_{\Omega \cup \pi_j}, V) - Score(C_{\Omega}, V)$ . These processes are repeated multiple rounds and the average of all marginal contributions associated with a particular source corpus is taken as its approximate Shapley value (line 18 in Algorithm 1). When the size of  $\Omega$  increases, the marginal contribution of adding a new source corpus becomes smaller. Therefore, to reduce the computation, Ghorbani and Zou (2019) propose to truncate the computations at each epoch when the marginal contribution of adding a new source  $\pi_j$  is smaller than a user defined threshold Tolerance (line 10-11, 18 in Algorithm 1).
2.2 SEAL-Shap
Despite that TMC-Shap improves the running time, it is still unrealistic to use it in our setting where both source data and model are large. For example, in cross-lingual POS tagging on Universal Dependencies Treebanks, on average, it takes more than 200 hours to estimate the values of 30 source languages with multi-lingual BERT (See Sec 4.4). Therefore, in the following, we propose three techniques to further speed-up the evaluation process.
Stratified Sampling When computing the marginal contributions, training a model  $C$  on the entire training set  $\Omega$  is computationally expensive. Based on extensive experiments, when computing these marginal contributions, we find that we do not need the performance difference of models trained with the entire training sets. For a reasonably large source corpus, 20-30% samples in each source achieve lower but representative performance difference, in general. Therefore, we sample a subset of instances to evaluate the marginal contributions. To address computational limitation and scale to large data, sampling techniques have been widely discussed (L'heureux et al., 2017). In particular, we employ a stratified sampling (Neyman, 1992) to generate a subset  $\mathcal{T}$
from  $\Omega$  by sampling training instances from each source corpus  $\Omega_{x}$  with a user defined sample rate  $\eta$ . Then, we train the model on  $\mathcal{T}$  (line 14-15 in Algorithm 1). The quantitative effectiveness of this technique is discussed in Sec 4.4 and the impact of different sampling rates are presented in Fig 5.
Truncation As discussed in Sec 2.1, at each epoch, Ghorbani and Zou (2019) truncate the computations once a marginal contribution becomes small when looping over the ordered list  $\pi$  of that corresponding epoch, typically for the last few sources in  $\pi$ . On the other hand, at the beginning of each epoch, when computing the marginal contribution by adding the first source corpus  $\pi_1$  into an empty  $\Omega$ , the contribution is computed by the performance gap between a model trained on  $\pi_1$  and a random baseline model without any training. Usually, the performance of a random model  $(v_0)$  is low and hence, the marginal contribution is high in the first step, in general. As this scale of marginal contributions at the first step is drastically different from later steps, it leads TMC-Shap to converge slowly. Hence, to restrict the variance of the marginal contributions, we down weight the marginal contributions of the first step by setting  $v_0 = \rho$ , where  $\rho$  is a hyper-parameter<sup>6</sup> indicating the
4 Setting Tolerance to 0 turns off the truncation.
Higher sampling rate typically leads to better approximation but are expensive in run-time.
Typically a factor of the performance achieved when using only one source, or all the sources together
baseline performance of a model (line 7, 18 in Algorithm 1).
Caching When computing the source Shapley values, we have to repeatedly evaluate the performance of the model on different subsets of source corpora. Sometimes, we may encounter subsets that we have evaluated before. For example, consider a set of source corpora  $\mathcal{D} = \{D_1, D_2, D_3\}$  and we evaluate their Shapley values through two permutations:  $\pi_1 = [D_3, D_1, D_2]$ , and  $\pi_2 = [D_1, D_3, D_2]$ . When we compute the marginal contribution of the last source corpus  $D_2$ , in both cases the training set  $\Omega = \{D_1, D_3\}$ . That is, if we cache the result of  $Score(C_{D_1 \cup D_3})$ , then we can reuse the scores. We implement this cache mechanism in line 1, 13, 16, 17 in Algorithm 1. With these optimization techniques, we improve the computation time by about 2x (see Sec 4.4). This enables us to apply this techniques in NLP transfer learning.
Note that whenever an  $\Omega$  causes a cache miss, for each source  $\Omega_{x}$ , as discussed above in this Section, we sample a new set of instances (line 13-14 in Algorithm-1). Thus, given a reasonably large number of epochs, our approach performs sampling for a large number of times and in aggregation, it evaluates a wide number of samples in each source.
2.3 SEAL-Shap for Multiple Targets
Many applications require to evaluate the values of a set of sources with respect to a set of targets. For example, under the zero-shot transfer learning setting, we assume a model is purely trained on the source corpora without using any target data. Consequently, then the same trained model can be evaluated on multiple target corpora. With this intuition, whenever the model is trained on a new training set  $\Omega$ , SEAL-Shap evaluates it on all the target corpora and caches all of them accordingly.
2.4 Source Values without Evaluation Corpus
In the previous discussions above, we assume a small annotated target corpus is available and can be used to evaluate the transfer performances. However, in some scenarios, only some linguistic or statistical features of the sources and targets, such as language distance and word overlap, are available. Lin et al. (2019) show that by using these features, we can train a ranker to sort the sources to unknown targets by predicting their value. In the following, we extend their ranker by incorporating it with SEAL-Shap.
Given the set of training corpora  $\mathcal{D}$  and the actual target corpus  $V$ , we iteratively consider each training corpus  $D_{j}$  as target and the rest  $m - 1$  corpora as the sources. We compute the corresponding source values  $\mathcal{Y}_{\mathcal{D}}^{D_j} = \{\Phi_{D_1},\dots ,\Phi_{D_{j - 1}},\Phi_{D_{j + 1}},\dots ,\Phi_{D_m}\}$ . Now, w.r.t the target  $D_{j}$ , the linguistic or statistical features of the source corpora (e.g., language distance from the target, lexical overlap between the corresponding source and the target)  $\mathcal{X}_{\mathcal{D}}^{D_j} = \{F^j (D_1),\ldots ,F^j (D_{j - 1}),F^j (D_{j + 1}),\ldots ,F^j (D_m)\}$  where  $F^j$  denotes the source feature generator function for the corresponding target  $D_{j}$ . This feature vector of the source corpora  $(\mathcal{X}_{\mathcal{D}}^{D_j})$  is a training input and their value vector  $(\mathcal{Y}_{\mathcal{D}}^{D_j})$  is the corresponding training output for the ranker. We repeat this for each training corpus and generate the respective training inputs and outputs for the ranker. Once trained, for the actual target  $V$  and the source corpora  $\mathcal{D}$ , the ranker can predict the values of the source corpora  $\mathcal{Y}_{\mathcal{D}}^{V}$  only based on the linguistic source features  $\mathcal{X}_{\mathcal{D}}^{V}$ .
2.5 Source Corpora Selection by SEAL-Shap
The source values computed in Sec 2.2-2.4 estimate the usefulness of the corresponding transfer sources and can be used to identify the potential sources which lead to the good transfer performances. We select the potential source corpora in two ways. (i) Top- $k$ : We simply sort the sources based on their values and select the user defined top- $k$  sources. (ii) Threshold: When an annotated evaluation dataset in target corpus  $V$  is available, after computing the source values, we empirically set a threshold  $\theta$  and select each source that has source value higher than  $\theta$ . On that evaluation target corpus, we tune and set  $\theta$  for which the corresponding transfer model achieves the best performance.
We conduct experiments on zero-shot cross-lingual and cross-domain transfer settings. Models are trained only on the source languages/domains and directly applied in target languages/domains. Cross-lingual Datasets We conduct experiments on two popular cross-lingual transfer problems: (i) universal POS tagging on the Universal Dependencies Treebanks (Nivre et al., 2018). Following Ahmad et al. (2019), we select 31 languages of 13 different language families (details in Appendix A). (ii) natural language inference on the XNLI
(a) UD Treebank, target: en
(b) XNLI, target: vi
(c) mtl-dom-semi, target: E
Figure 2: Performance, and run time with up to top-3 sources ranked by different approaches. (a), (b) denotes cross-lingual and (c), (d) denotes cross-domain transfer. All models have same training configurations (e.g., sample size). All the run times are final except for Greedy DFS where it increases linearly with top-k. Adding top-2 and top-3 ranked sources, other methods drop their accuracy across the tasks while ours shows a consistent gain in all tasks and achieves the best results with top-3 sources.
(d) mGLUE, target:MNLI-mm
dataset (Conneau et al., 2018), that covers 15 different languages. XNLI task is a 3-way classification task (entailment, neutral, and contradiction). Data statistics are in Appendix R.
Cross-domain Datasets We consider three domain transfer tasks: (i) POS tagging: we use the SANCL 2012 shared task datasets (Petrov and McDonald, 2012) that has six different domains (details in Appendix B). (ii) Sentiment analysis: we use the multi-domain sentiment datasets (Liu et al., 2017) which has several additional domains than the popular Blitzer et al. (2007) dataset, See Appendix D. (iii) NLI: we consider a (modified) binary classification (e.g., entailed or not) dataset used in Ma et al. (2019). It is made upon modification on GLUE tasks (Wang et al., 2018) and has four domains (details in Appendix C). As GLUE test sets are unavailable, for each target domain, we use the original dev set as the pseudo test set and randomly select 2,000 instances from its training set as the pseudo dev set.
Classifier and Preprocessing For all domain transfer tasks, we use BERT and for all language transfer tasks, we use multi-lingual BERT (Devlin et al., 2019) models except for cross-domain POS tagging where we consider the state-of-the-art BiLSTM based Flair framework (Akbik et al., 2018). For BERT models, we use the Transformers implementations in the Huggingface library Wolf et al. (2019). For significance test, we use an open-sourced library.<sup>7</sup> By default, no preprocessing is performed except tokenization (see Appendix J).
Hyper-parameters Tuning For all BERT models, we tune the learning rate, batch size, and number of epochs. We also tune the number of epochs nepoch in Algorithm 1, the threshold SEAL-Shap value  $\theta$ , initial score  $\rho$ . Details are in Appendix K.
In the following, we first verify SEAL-Shap is an effective tool for source valuation. Then, we evaluate the source values when an evaluation target corpus is unavailable. In Sec 4.3, we interpret the relations between sources and targets based on the SEAL-Shap values. Finally, we analyze our method with comprehensive ablation studies.
4.1 Evaluating Source Valuation
We assess our source valuation approach in compare to the following baselines: (i) Baseline-s: source values are based on the single source transfer performance. (ii) Leave-one-out (LOO): source values are based on how much transfer performance we loose if we train the model on all the sources except the corresponding one. (iii) Baseline-r: a random baseline that assigns random values to sources. $^{8}$  (iv) Greedy DFS: the top-1 ranked source is same as that of Baseline-s. Next, it selects one of the remaining sources as top-2 that gives the best transfer result along with the top-1 and so on. (v) Lang-Dist: (if available) in reverse order of target-source language distance (Ahmad et al., 2019). $^{9}$
Balancing Source Corpora In the experiments, our focus is to understand the values of the sources. For some datasets, the sizes of source corpora are very different. For example, in UD Treebank, the number of instances in Czech, and Turkish is 69k, 3.5k, respectively. Since data-size is an obvious factor, we conduct experiments on balanced data to reduce the influence of data-size in the analysis. We sub-sample the source corpora to ensure their sizes are similar. Specifically, for the cross-domain NLI task, we sample 20k instances for each source.
Our experiments with different seeds result in different but similar results.
<sup>9</sup>Ahmad et al. (2019) compute the distances from an annotated dependency parse tree based on UD Treebank.
$^7$ github.com/neubig/util-scripts/blob/master/paired-bootstrap.py
Lang	en	All Source	Baseline-r	Baseline-s	SEAL-Shap
en	-	82.71	86.32	86.39	88.55*§†
fr	-	94.60	94.63	94.83	94.79
da	88.3	88.94	89.30	89.23	89.47*
es	85.2	93.15	93.00	93.04	93.21§
it	84.7	96.58	96.43	96.71	96.67
ca	-	91.54	91.64	90.78	92.08*§†
sl	84.2	93.28	93.50	92.89	93.52*†
nl	75.9	90.10	90.19	90.14	90.26
ru	-	92.98	92.91	92.71	93.13*§†
de	89.8	90.79	91.07	91.44	91.06
he	-	76.67	75.75	75.43	76.73§†
cs	-	93.89	93.04	93.94	94.81*§†
sk	83.6	95.68	95.62	95.53	95.81†
sr	-	97.55	97.47	97.43	97.58†
id	-	84.10	85.23	85.50	85.97*§
fi	-	87.13	86.89	86.86	87.05
ko	-	63.59	64.27	63.77	64.19
hi	-	81.49	80.27	79.94	82.41*§†
ja	-	66.86	65.99	67.71	67.81*§
fa	72.8	81.03	80.69	82.37	81.79
Average	-	82.98	83.05	83.15	83.66
Table 1: Performance on universal POS tagging when using each of language as the target language and the rest as source languages.  $*$ ,  $\$$ ,  $\dagger$  denote SEAL-Shap model is statistically significantly outperforms All Sources, Baseline-  $r$  and Baseline- $s$  respectively using paired bootstrap test with  $p \leq 0.05$ . "en" refers to the only source ("en") results in Wu and Dredze (2019).
For others, we sub-sample each source such that the size of the corpus is the same as the smallest one in the dataset. However, our approach can handle both balanced or unbalanced data and the source values are similar in conclusions (e.g., see Fig 5).
Result: We first compare these methods by selecting top-  $k$  sources ranked by each of the approach and reporting the corresponding transfer performance. With  $k = 3$ , we plot the corresponding transfer results and the running time for valuation in Fig 2. As mentioned in Sec 1, the relatively strong Baseline-s can select the best performing top-1 source but with top-2 and top-3 sources, the performances drop on cross-domain sentiment analysis and cross-lingual POS tagging (See Fig 2(c) and 2(a)) while our approach shows a consistent gain in all of the these tasks and with top-3 sources it achieves the best performances. Appendix I plots the results with higher  $k$ .
Next, as in Sec 2.5, we tune a threshold  $\theta$  and either select all the sources as useful or a smaller subset of  $m$  number of sources (i.e.,  $m < |\mathcal{D}|$ ) whose SEAL-Shap values are higher than  $\theta$ . In the followings, we compare the model performances of these  $m$  sources selected by SEAL-Shap with the same top- $m$  sources ranked by the aforementioned baseline methods. Being relatively weak or slow, we do not further report performances for  $LOO$ ,