SlowGuess/ACL_2020_OCR huggingface dataset:
Xinyi Wang
Yulia Tsvetkov
Language Technology Institute, Carnegie Mellon University, Pittsburgh, PA 15213
{xinyiw1,ytsvetko,gneubig}@cs.cmu.edu
When training multilingual machine translation (MT) models that can translate to/from multiple languages, we are faced with imbalanced training sets: some languages have much more training data than others. Standard practice is to up-sample less resourced languages to increase representation, and the degree of up-sampling has a large effect on the overall performance. In this paper, we propose a method that instead automatically learns how to weight training data through a data scorer that is optimized to maximize performance on all test languages. Experiments on two sets of languages under both one-to-many and many-to-one MT settings show our method not only consistently outperforms heuristic baselines in terms of average performance, but also offers flexible control over the performance of which languages are optimized.
Multilingual models are trained to process different languages in a single model, and have been applied to a wide variety of NLP tasks such as text classification (Klementiev et al., 2012; Chen et al., 2018a), syntactic analysis (Plank et al., 2016; Ammar et al., 2016), named-entity recognition (Xie et al., 2018; Wu and Dredze, 2019), and machine translation (MT) (Dong et al., 2015; Johnson et al., 2016). These models have two particularly concrete advantages over their monolingual counterparts. First, deploying a single multilingual model is much more resource efficient than deploying one model for each language under consideration (Arivazhagan et al., 2019; Aharoni et al., 2019). Second, multilingual training makes it possible to transfer knowledge from high-resource languages (HRLs) to improve performance on low-resource languages (LRLs) (Zoph et al., 2016;
Nguyen and Chiang, 2018; Neubig and Hu, 2018; Wang and Neubig, 2019; Aharoni et al., 2019).
A common problem with multilingual training is that the data from different languages are both heterogeneous (different languages may exhibit very different properties) and imbalanced (there may be wildly varying amounts of training data for each language). Thus, while LRLs will often benefit from transfer from other languages, for languages where sufficient monolingual data exists, performance will often decrease due to interference from the heterogeneous nature of the data. This is especially the case for modestly-sized models that are conducive to efficient deployment (Arivazhagan et al., 2019; Conneau et al., 2019).
To balance the performance on different languages, the standard practice is to heuristically adjust the distribution of data used in training, specifically by over-sampling the training data from LRLs (Johnson et al., 2016; Neubig and Hu, 2018; Arivazhagan et al., 2019; Conneau et al., 2019). For example, Arivazhagan et al. (2019) sample training data from different languages based on the dataset size scaled by a heuristically tuned temperature term. However, such heuristics are far from perfect. First, Arivazhagan et al. (2019) find that the exact value of this temperature term significantly affects results, and we further show in experiments that the ideal temperature varies significantly from one experimental setting to another. Second, this heuristic ignores factors other than data size that affect the interaction between different languages, despite the fact that language similarity has been empirically proven important in examinations of cross-lingual transfer learning (Wang and Neubig, 2019; Lin et al., 2019).
In this paper, we ask the question: "is it possible to learn an optimal strategy to automatically balance the usage of data in multilingual model training?" To this effect, we propose a method that
The code is available at https://github.com/cindyxinyiwang/fairseq/tree/multiDDS.
8526
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 8526-8537 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
learns a language scorer that can be used throughout training to improve the model performance on all languages. Our method is based on the recently proposed approach of Differentiable Data Selection (Wang et al., 2019b, DDS), a general machine learning method for optimizing the weighting of different training examples to improve a pre-determined objective. In this work, we take this objective to be the average loss from different languages, and directly optimize the weights of training data from each language to maximize this objective on a multilingual development set. This formulation has no heuristic temperatures, and enables the language scorer to consider the interaction between languages.
Based on this formulation, we propose an algorithm that improves the ability of DDS to optimize multiple model objectives, which we name MultiDDS. This is particularly useful in the case where we want to optimize performance on multiple languages simultaneously. Specifically, MultiDDS (1) has a more flexible scorer parameterization, (2) is memory efficient when training on multiple languages, and (3) stabilizes the reward signal so that it improves all objectives simultaneously instead of being overwhelmed by a single objective.
While the proposed methods are model-agnostic and thus potentially applicable to a wide variety of tasks, we specifically test them on the problem of training multilingual NMT systems that can translate many languages in a single model. We perform experiments on two sets of languages (one with more similarity between the languages, one with less) and two translation directions (one-to-many and many-to-one where the "one" is English). Results show that MultiDDS consistently outperforms various baselines in all settings. Moreover, we demonstrate MultiDDS provides a flexible framework that allows the user to define a variety of optimization objectives for multilingual models.
2 Multilingual Training Preliminaries
Monolingual Training Objective A standard NMT model is trained to translate from a single source language  $S$  to a target language  $T$ . The parameters of the model are generally trained by preparing a training dataset  $D_{\mathrm{train}}$ , and defining the empirical distribution of sentence pairs  $\langle x, y \rangle$  sampled from  $D_{\mathrm{train}}$  as  $P$ . We then minimize the empirical risk  $J(\theta, P)$ , which is the expected value
of the loss function  $\ell (x,y;\theta)$  over this distribution:
$$
\theta^ {*} = \underset {\theta} {\operatorname {a r g m i n}} J (\theta , D _ {\text {t r a i n}})
$$
where  $J(\theta ,D_{\mathrm{train}}) = \mathbb{E}_{x,y\sim P(X,Y)}[\ell (x,y;\theta)]$  (1)
Multilingual Training Formulation A multilingual NMT model can translate  $n$  pairs of languages  $\{S^1 - T^1, S^2 - T^2, \dots, S^n - T^n\}$ , from any source language  $S^i$ . to its corresponding target  $T^i$ . To train such a multilingual model, we have access to  $n$  sets of training data  $D_{\mathrm{train}} = D_{\mathrm{train}}^1, D_{\mathrm{train}}^2, \dots, D_{\mathrm{train}}^n$ , where  $D_{\mathrm{train}}^i$  is training data for language pair  $S^i - T^i$ . From these datasets, we can define  $P^i$ , the distribution of sentences from  $S^i - T^i$ , and consequently also define a risk  $J(\theta, P^i)$  for each language following the monolingual objective in Eq. 1.
However, the question now becomes: "how do we define an overall training objective given these multiple separate datasets?" Several different methods to do so have been proposed in the past. To discuss all of these different methods in a unified framework, we further define a distribution  $P_{D}$  over the  $n$  sets of training data, and define our overall multilingual training objective as
$$
J _ {\text {m u l t}} (\theta , P _ {D}, D _ {\text {t r a i n}}) = \mathbb {E} _ {i \sim P _ {D} (i; \psi)} [ J (\theta , D _ {\text {t r a i n}} ^ {i}) ]. \tag {2}
$$
In practice, this overall objective can be approximated by selecting a language according to  $\tilde{i} \sim P_D(i)$ , then calculating gradients with respect to  $\theta$  on a batch of data from  $D_{\mathrm{train}}^{\tilde{i}}$ .
Evaluation Methods Another important question is how to evaluate the performance of such multilingual models. During training, it is common to use a separate development set for each language  $D_{\mathrm{dev}} = D_{\mathrm{dev}}^{1}, D_{\mathrm{dev}}^{2}, \ldots, D_{\mathrm{dev}}^{n}$  to select the best model. Given that the objective of multilingual training is generally to optimize the performance on all languages simultaneously (Arivazhagan et al., 2019; Conneau et al., 2019), we can formalize this objective as minimizing the average of dev risks<sup>2</sup>:
$$
J _ {\mathrm {d e v}} (\theta , D _ {\mathrm {d e v}}) = \frac {1}{n} \sum_ {i = 1} ^ {n} J (\theta , D _ {\mathrm {d e v}} ^ {i}). \tag {3}
$$
In reality, it is common to have the loss  $\ell$  be a likelihood-based objective, but finally measure another metric such as BLEU score at test time, but for simplicity we will assume that these two metrics are correlated.
8527
Relation to Heuristic Strategies This formulation generalizes a variety of existing techniques that define  $P_{D}(i)$  using a heuristic strategy, and keep it fixed throughout training.
Uniform: The simplest strategy sets  $P_{D}(i)$  to a uniform distribution, sampling minibatches from each language with equal frequency (Johnson et al., 2016).
Proportional: It is also common to sample data in portions equivalent to the size of the corresponding corpora in each language (Johnson et al., 2016; Neubig and Hu, 2018).
Temperature-based: Finally, because both of the strategies above are extreme (proportional underweighting LRLs, and uniform causing overfitting by re-sampling sentences from limited-size LRL datasets), it is common to sample according to data size exponentiated by a temperature term  $\tau$  (Arivazhagan et al., 2019; Conneau et al., 2019):
$$
P _ {D} (i) = \frac {q _ {i} ^ {1 / \tau}}{\sum_ {k = 1} ^ {n} q _ {k} ^ {1 / \tau}} \text {w h e r e} q _ {i} = \frac {\left| D _ {\text {t r a i n}} ^ {i} \right|}{\sum_ {k = 1} ^ {n} \left| D _ {\text {t r a i n}} ^ {k} \right|}. \tag {4}
$$
When  $\tau = 1$  or  $\tau = \infty$  this is equivalent to proportional or uniform sampling respectively, and when a number in the middle is chosen it becomes possible to balance between the two strategies.
As noted in the introduction, these heuristic strategies have several drawbacks regarding sensitivity to the  $\tau$  hyperparameter, and lack of consideration of similarity between the languages. In the following sections we will propose methods to resolve these issues.
3 Differentiable Data Selection
Now we turn to the question: is there a better way to optimize  $P_{D}(i)$  so that we can achieve our final objective of performing well on a representative development set over all languages, i.e. minimizing  $J_{\mathrm{dev}}(\theta, D_{\mathrm{dev}})$ . In order to do so, we turn to a recently proposed method of Differentiable Data Selection (Wang et al., 2019b, DDS), a general purpose machine learning method that allows for weighting of training data to improve performance on a separate set of held-out data.
Specifically, DDS uses a technique called bi-level optimization (Colson et al., 2007), that learns
a second set of parameters  $\psi$  that modify the training objective that we use to learn  $\theta$ , so as to maximize the final objective  $J_{\mathrm{dev}}(\theta, D_{\mathrm{dev}})$ . Specifically, it proposes to learn a data scorer  $P(x, y; \psi)$ , parameterized by  $\psi$ , such that training using data sampled from the scorer optimizes the model performance on the dev set. To take the example of learning an NMT system to translate a single language pair  $i$  using DDS, the general objective in Eq. 1 could be rewritten as
$$
\psi^ {*} = \underset {\psi} {\operatorname {a r g m i n}} J \left(\theta^ {*} (\psi), D _ {\mathrm {d e v}} ^ {i}\right) \text {w h e r e} \tag {5}
$$
$$
\theta^ {*} (\psi) = \underset {\theta} {\operatorname {a r g m i n}} \mathbb {E} _ {x, y \sim P (x, y; \psi)} \left[ \ell (x, y; \theta) \right].
$$
DDS optimizes  $\theta$  and  $\psi$  iteratively throughout the training process. Given a fixed  $\psi$ , the update rule for  $\theta$  is simply
$$
\theta_ {t} \gets \theta_ {t - 1} - \nabla_ {\theta} \mathbb {E} _ {x, y \sim P (x, y; \psi)} [ \ell (x, y; \theta) ]
$$
To update the data scorer, DDS uses reinforcement learning with a reward function that approximates the effect of the training data on the model's dev performance
$$
\begin{array}{l} R (x, y; \theta_ {t}) \approx \nabla J (\theta_ {t}, D _ {\mathrm {d e v}} ^ {i}) ^ {\top} \cdot \nabla_ {\theta} \ell (x, y; \theta_ {t - 1}) \\ \approx \cos (\nabla J (\theta_ {t}, D _ {\mathrm {d e v}} ^ {i}), \nabla_ {\theta} \ell (x, y; \theta_ {t - 1})) \tag {6} \\ \end{array}
$$
where  $\cos (\cdot)$  is the cosine similarity of two vectors. This reward can be derived by directly differentiating  $J(\theta (\psi),D_{\mathrm{dev}}^{i})$  with respect to  $\psi$ , but intuitively, it indicates that the data scorer should be updated to up-weigh the data points that have similar gradient with the dev data. According to the REINFORCE algorithm (Williams, 1992), the update rule for the data scorer then becomes
$$
\psi_ {t + 1} \leftarrow \psi_ {t} + R (x, y; \theta_ {t}) \cdot \nabla_ {\psi} \log P (x, y; \psi) \tag {7}
$$
4 DDS for Multilingual Training
In this section, we use the previously described DDS method to derive a new framework that, instead of relying on fixed heuristics, adaptively optimizes usage of multilingual data for the best model performance on multiple languages. We illustrate the overall workflow in Fig. 1.
First, we note two desiderata for our multilingual training method: 1) generality: the method should be flexible enough so that it can be utilized universally for different multilingual tasks and settings (such as different translation directions for
8528
NMT). 2) scalability: the method should be stable and efficient if one wishes to scale up the number of languages that a multilingual model supports. Based on these two properties, we introduce MultiDDS, an extension of the DDS method tailored for multilingual training.
Method MultiDDS directly parameterizes the standard dataset sampling distribution for multilingual training with  $\psi$ :
$$
P _ {D} (i; \psi) = e ^ {\psi_ {i}} / \sum_ {k = 1} ^ {n} e ^ {\psi_ {k}} \tag {8}
$$
and optimizes  $\psi$  to minimize the dev loss. Notably, unlike standard DDS we make the design decision to weight training datasets rather than score each training example  $\langle x,y\rangle$  directly, as it is more efficient and also likely easier to learn.
We can thus rewrite the objective in Eq. 2 to incorporate both  $\psi$  and  $\theta$  as:
$$
\begin{array}{l} \psi^ {*} = \underset {\psi} {\operatorname {a r g m i n}} J _ {\mathrm {d e v}} (\theta^ {*} (\psi), D _ {\mathrm {d e v}}) \text {w h e r e} \\ \theta^ {*} = \underset {\theta} {\operatorname {a r g m i n}} \mathbb {E} _ {i \sim P _ {D} (i; \psi)} \left[ J (\theta , D _ {\text {t r a i n}} ^ {i}) \right] \\ \end{array}
$$
In other words, while the general DDS framework evaluates the model performance on a single dev set and optimizes the weighting of each training example, our multilingual training objective evaluates the performance over an aggregation of  $n$  dev sets and optimizes the weighting of  $n$  training sets.
The reward signal for updating  $\psi_t$  is
$$
\begin{array}{l} R (i; \theta_ {t}) \approx \cos \left(\nabla \left(J _ {\mathrm {d e v}} \left(\theta_ {t}, D _ {\mathrm {d e v}}\right)\right), \nabla_ {\theta} J \left(\theta_ {t - 1}, D _ {\mathrm {t r a i n}} ^ {i}\right)\right) \\ = \cos \left(\nabla \left(\frac {1}{n} \sum_ {k = 1} ^ {n} J \left(\theta_ {t}, D _ {\mathrm {d e v}} ^ {k}\right)\right), \nabla_ {\theta} J \left(\theta_ {t - 1}, D _ {\text {t r a i n}} ^ {i}\right)\right), \tag {10} \\ \end{array}
$$
where  $J_{\mathrm{dev}}(\cdot)$  defines the combination of  $n$  dev sets, and we simply plug in its definition from Eq. 3. Intuitively, Eq. 10 implies that we should favor the training language  $i$  if its gradient aligns with the gradient of the aggregated dev risk of all languages.
Implementing the Scorer Update The pseudocode for the training algorithm using MultiDDS can be found in line 25. Notably, we do not update the data scorer  $\psi$  on every training step, because it is too computationally expensive for NMT training (Wang et al., 2019b). Instead, after training the multilingual model  $\theta$  for a certain number of steps, we update the scorer for all languages. This implementation is not only efficient, but also allows us to
Figure 1: An illustration of the MultiDDS algorithm. Solid lines represent updates for  $\theta$ , and dashed lines represent updates for  $\psi$ . The scorer defines the distribution over  $n$  training languages, from which training data is sampled to train the model. The scorer is updated to favor the datasets with similar gradients as the gradient of the aggregated dev sets.
re-estimate more frequently the effect of languages that have low probability of being sampled.
In order to do so, it is necessary to calculate the effect of each training language on the current model, namely  $R(i; \theta_t)$ . We estimate this value by sampling a batch of data from each  $D_{\text{train}}^i$  to get the training gradient for  $\theta_t$ , and use this to calculate the reward for this language. This process is detailed in line 11 of the line 25.
Unlike the algorithm in DDS which requires storing  $n$  model gradients, this approximation does not require extra memory even if  $n$  is large, which is important given recent efforts to scale multilingual training to  $100+$  (Arivazhagan et al., 2019; Aharoni et al., 2019) or even  $1000+$  languages (Östling and Tiedemann, 2017; Malaviya et al., 2017).
5 Stabilized Multi-objective Training
In our initial attempts to scale DDS to highly multilingual training, we found that one challenge was that the reward for updating the scorer became unstable. This is because the gradient of a multilingual dev set is less consistent and of higher variance than that of a monolingual dev set, which influences the fidelity of the data scorer reward.
3The NMT algorithm in (Wang et al., 2019b) estimates the reward by storing the moving average of  $n$  training gradients, which is not memory efficient (See Line. 7 of Alg. 2 in (Wang et al., 2019b)). In the preliminary experiments, our approximation performs as well as the moving average approximation (see App. A.1). Thus, we use our approximation method as the component for MultiDDS for the rest of the experiments.
Suppose the dev set gradient of language  $k$  has variance of  $\operatorname{var}(g_{\mathrm{dev}}^k) = \sigma$ , and that the dev gradients of each language
8529
Thus, instead of using the gradient alignment between the training data and the aggregated loss of  $n$  dev sets as the reward, we propose a second approach to first calculate the gradient alignment reward between the data and each of the  $n$  dev sets, then take the average of these as the final reward.
$\{g_{\mathrm{dev}}^1,\dots,g_{\mathrm{dev}}^n\}$  are independent. Then the sum of the gradients from the  $n$  languages has a variance of  $\operatorname {var}(\sum_{k = 1}^{n}g_{\mathrm{dev}}^{k}) = n\sigma$
This can be expressed mathematically as follows:
$$
\begin{array}{l} R ^ {\prime} (i; \theta_ {t}) \approx \\ \cos \left(\nabla_ {\theta} \left(\frac {1}{n} \sum_ {k = 1} ^ {n} J \left(\theta_ {t}, D _ {\text {d e v}} ^ {k}\right)\right), \nabla_ {\theta} J \left(\theta_ {t - 1}, D _ {\text {t r a i n}} ^ {i}\right)\right) \\ \approx \frac {1}{n} \sum_ {k = 1} ^ {n} \cos \left(\nabla_ {\theta} J \left(\theta_ {t}, D _ {\mathrm {d e v}} ^ {k}\right), \nabla_ {\theta} J \left(\theta_ {t - 1}, D _ {\text {t r a i n}} ^ {i}\right)\right) \tag {11} \\ \end{array}
$$
To implement this, we can simply replace the standard reward calculation at Line 11 of line 25 to use the stable reward. We name this setting MultiDDS-S. In § 6.6 we show that this method has less variance than the reward in Eq. 10.
6.1 Data and Settings
We use the 58-languages-to-English parallel data from Qi et al. (2018). A multilingual NMT model is trained for each of the two sets of language pairs with different level of language diversity:
Related: 4 LRLs (Azerbaijani: aze, Belarusian: bel, Glacian: glg, Slovak: slk) and a related HRL for each LRL (Turkish: tur, Russian: rus, Portuguese: por, Czech: ces)
Diverse: 8 languages with varying amounts of data, picked without consideration for relatedness (Bosnian: bos, Marathi: mar, Hindi: hin, Macedonian: mkd, Greek: ell, Bulgarian: bul, French: fra, Korean: kor)
Statistics of the datasets are in  $\S$  A.3.
For each set of languages, we test two varieties of translation: 1) many-to-one (M2O): translating 8 languages to English; 2) one-to-many (O2M): translating English into 8 different languages. A target language tag is added to the source sentences for the O2M setting (Johnson et al., 2016).
6.2 Experiment Setup
All translation models use standard transformer models (Vaswani et al., 2017) as implemented in fairseq (Ott et al., 2019) with 6 layers and 4 attention heads. All models are trained for 40 epochs. We preprocess the data using sentencpiece (Kudo and Richardson, 2018) with a vocabulary size of  $8K$  for each language. The complete set of hyperparameters can be found in § A.2. The model performance is evaluated with BLEU score (Papineni et al., 2002), using sacreBLEU (Post, 2018).
8530
Baselines We compare with the three standard heuristic methods explained in § 2: 1) Uniform  $(\tau = \infty)$ : datasets are sampled uniformly, so that LRLs are over-sampled to match the size of the HRLs; 2) Temperature: scales the proportional distribution by  $\tau = 5$  (following Arivazhagan et al. (2019)) to slightly over-sample the LRLs; 3) Proportional  $(\tau = 1)$ : datasets are sampled proportional to their size, so that there is no over-sampling of the LRLs.
Ours we run MultiDDS with either the standard reward (MultiDDS), or the stabilized reward proposed in Eq. 11 (MultiDDS-S). The scorer for MultiDDS simply maps the ID of each dataset to its corresponding probability (See Eq. 8. The scorer has N parameters for a dataset with N languages.)
6.3 Main Results
We first show the average BLEU score over all languages for each translation setting in Tab. 2. First, comparing the baselines, we can see that there is no consistently strong strategy for setting the sampling ratio, with proportional sampling being best in the M2O setting, but worst in the O2M setting. Next, we can see that MultiDDS outperforms the best baseline in three of the four settings and is comparable to proportional sampling in the last M2O-Diverse setting. With the stabilized reward, MultiDDS-S consistently delivers better overall performance than the best baseline, and outperforms MultiDDS in three settings. From these results, we can conclude that MultiDDS-S provides a stable strategy to train multilingual systems over a variety of settings.
Next, we look closer at the BLEU score of each language pair for MultiDDS-S and the best baseline. The results for all translation settings are in Tab. 1. In general, MultiDDS-S outperforms the baseline on more languages. In the best case, for the O2M-Related setting, MultiDDS-S brings significant gains for five of the eight languages, without hurting the remaining three. The gains for the Related group are larger than for the Diverse group, likely because MultiDDS can take better advantage of language similarities than the baseline methods.
It is worth noting that MultiDDS does not impose large training overhead. For example, for our M2O system, the standard method needs around 19 hours and MultiDDS needs around 20 hours for convergence. The change in training time is not significant because MultiDDS only optimizes a
simple distribution over the training datasets.
6.4 Prioritizing what to Optimize