SlowGuess/ACL_2020_OCR huggingface dataset:
Hendra Setiawan Matthias Sperber Udhay Nallasamy Matthias Paulik
{ hendra,sperber,udhay,mpaulik }@apple.com
Variational Neural Machine Translation (VNMT) is an attractive framework for modeling the generation of target translations, conditioned not only on the source sentence but also on some latent random variables. The latent variable modeling may introduce useful statistical dependencies that can improve translation accuracy. Unfortunately, learning informative latent variables is non-trivial, as the latent space can be prohibitively large, and the latent codes are prone to be ignored by many translation models at training time. Previous works impose strong assumptions on the distribution of the latent code and limit the choice of the NMT architecture. In this paper, we propose to apply the VNMT framework to the state-of-the-art Transformer and introduce a more flexible approximate posterior based on normalizing flows. We demonstrate the efficacy of our proposal under both in-domain and out-of-domain conditions, significantly outperforming strong baselines.
Translation is inherently ambiguous. For a given source sentence, there can be multiple plausible translations due to the author's stylistic preference, domain, and other factors. On the one hand, the introduction of neural machine translation (NMT) has significantly advanced the field (Bahdanau et al., 2015), continually producing state-of-the-art translation accuracy. On the other hand, the existing framework provides no explicit mechanisms to account for translation ambiguity.
Recently, there has been a growing interest in latent-variable NMT (LV-NMT) that seeks to incorporate latent random variables into NMT to account for the ambiguities mentioned above. For instance, Zhang et al. (2016) incorporated latent codes to capture underlying global semantics of source sentences into NMT, while Su et al. (2018)
proposed fine-grained latent codes at the word level. The learned codes, while not straightforward to analyze linguistically, are shown empirically to improve accuracy. Nevertheless, the introduction of latent random variables complicates the parameter estimation of these models, as it now involves intractable inference. In practice, prior work resorted to imposing strong assumptions on the latent code distribution, potentially compromising accuracy.
In this paper, we focus on improving Variational NMT (VNMT) (Zhang et al., 2016): a family of LV-NMT models that relies on the amortized variational method (Kingma and Welling, 2014) for inference. Our contributions are twofold. (1) We employ variational distributions based on normalizing flows (Rezende and Mohamed, 2015), instead of uni-modal Gaussian. Normalizing flows can yield complex distributions that may better match the latent code's true posterior. (2) We employ the Transformer architecture (Vaswani et al., 2017), including Transformer-Big, as our VNMT's generator network. We observed that the generator networks of most VNMT models belong to the RNN family that are relatively less powerful as a translation model than the Transformer.
We demonstrate the efficacy of our proposal on the German-English IWSLT'14 and English-German WMT'18 tasks, giving considerable improvements over strong non-latent Transformer baselines, and moderate improvements over Gaussian models. We further show that gains generalize to an out-of-domain condition and a simulated bimodal data condition.
2 VNMT with Normalizing Flows
Background Let  $\pmb{x}$  and  $\pmb{y}$  be a source sentence and its translation, drawn from a corpus  $\mathcal{D}$ . Our model seeks to find parameters  $\theta$  that maximize the marginal of a latent-variable model  $p_{\theta}(\pmb{y}, Z \mid \pmb{x})$
7771
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 7771-7777 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
where  $Z \in \mathbb{R}^D$  is a sentence-level latent code similar to (Zhang et al., 2016). VNMT models sidestep the marginalization by introducing variational distributions and seek to minimize this function (i.e., the Evidence Lower Bound or ELBO):
$$
\begin{array}{l} \sum_ {(\boldsymbol {x}, \boldsymbol {y}) \in \mathcal {D}} \mathbb {E} _ {q (Z | \boldsymbol {x}, \boldsymbol {y})} [ \log p _ {\theta} (\boldsymbol {y} \mid \boldsymbol {x}, Z) ] \\ - \operatorname {K L} \left(q (Z \mid \boldsymbol {x}, \boldsymbol {y}) | | p (Z \mid \boldsymbol {x})\right), \tag {1} \\ \end{array}
$$
where  $q(Z \mid x, y)$ ,  $p(Z \mid x)$  are the variational posterior and prior distribution of the latent codes, while  $p(y \mid x, Z)$  is a generator that models the generation of the translation conditioned on the latent code<sup>1</sup>. The ELBO is improved when the model learns a posterior distribution of latent codes that minimizes the reconstruction loss (the first term) while incurring a smaller amount of KL divergence penalty between the variational posterior and the prior (the second term).
The majority of VNMT models design their variational distributions to model unimodal distribution via isotropic Gaussians with diagonal covariance, which is the simplest form of prior and approximate posterior distribution. This assumption is computationally convenient because it permits a closed-form solution for computing the KL term and facilitates end-to-end gradient-based optimization via the re-parametrization trick (Rezende and Mohamed, 2015). However, such a simple distribution may not be expressive enough to approximate the true posterior distribution, which could be non-Gaussian, resulting in a loose gap between the ELBO and the true marginal likelihood. Therefore, we propose to employ more flexible posterior distributions in our VNMT model, while keeping the prior a Gaussian.
Normalizing Flows-based Posterior Rezende and Mohamed (2015) proposed Normalizing Flows (NF) as a way to introduce a more flexible posterior to Variational Autoencoder (VAE). The basic idea is to draw a sample,  $Z_{0}$ , from a simple (e.g., Gaussian) probability distribution and to apply  $K$  invertible parametric transformation functions  $(f_{k})$  called flows to transform the sample. The final latent code is given by  $Z_{K} = f_{K}(\dots f_{2}(f_{1}(Z_{0}))\dots)$  whose probability density function,  $q_{\lambda}(Z_K\mid \boldsymbol {x},\boldsymbol {y})$
is defined via the change of variable theorem as follows:
$$
q _ {0} (Z _ {0} \mid \boldsymbol {x}, \boldsymbol {y}) \prod_ {k = 1} ^ {K} \left| \det \frac {\partial f _ {k} (Z _ {k - 1} ; \boldsymbol {\lambda} _ {k} (\boldsymbol {x} , \boldsymbol {y}))}{\partial Z _ {k - 1}} \right| ^ {- 1},
$$
where  $\lambda_{k}$  refers to the parameters of the  $k$ -th flow with  $\lambda_0$  corresponds to the parameters of a base distribution. In practice, we can only consider transformations, whose determinants of Jacobians (the second term) are invertible and computationally tractable.
For our model, we consider several NFs, namely planar flows (Rezende and Mohamed, 2015), Sylvester flows (van den Berg et al., 2018) and affine coupling layer (Dinh et al., 2017), which have been successfully applied in computer vision tasks.
Planar flows (PF) applies this function:
$$
f _ {k} (Z; \lambda_ {k} (\boldsymbol {x}, \boldsymbol {y})) = Z + \mathbf {u} \cdot \tanh  (\mathbf {w} ^ {T} Z + \mathbf {b}),
$$
where  $\lambda_{k} = \{\mathbf{u},\mathbf{w}\in \mathbb{R}^{D},\mathbf{b}\in \mathbb{R}\}$ . Planar flows perform contraction or expansion to the direction perpendicular to the  $(\mathbf{w}^T Z + \mathbf{b})$  hyperplane.
Sylvester flows (SF) applies this function:
$$
f _ {k} (Z; \lambda_ {k} (\boldsymbol {x}, \boldsymbol {y})) = Z + \mathbf {A} \cdot \tanh  (\mathbf {B} Z + \mathbf {b}),
$$
where  $\lambda_{k} = \{\mathbf{A},\mathbf{B}\in \mathbb{R}^{M\times D},\mathbf{b}\in \mathbb{R}^{M}\}$  and  $M$  is the number of hidden units. Planar flows are a special case of Sylvester flows where  $M = 1$ . In our experiments, we consider the orthogonal Sylvester flows (van den Berg et al., 2018), whose parameters are matrices with  $M$  orthogonal columns.
Meanwhile, the affine coupling layer (CL) first splits  $Z$  into  $Z^{d_1}, Z^{d_2} \in \mathbb{R}^{D/2}$  and applies the following function:
$$
\begin{array}{l} f _ {k} \left(Z ^ {d _ {1}}; \lambda_ {k} (\boldsymbol {x}, \boldsymbol {y})\right) = Z ^ {d _ {1}}, \\ f _ {k} \left(Z ^ {d _ {2}}; \lambda_ {k} (\boldsymbol {x}, \boldsymbol {y}, Z ^ {d _ {1}})\right) = Z ^ {d _ {2}} \odot \exp \left(\boldsymbol {s} _ {k}\right) + \boldsymbol {t} _ {k}, \\ \end{array}
$$
where it applies identity transform to  $Z^{d_1}$  and applies a scale-shift transform to  $Z^{d_2}$  according to  $\lambda_k = \{s_k, t_k\}$ , which are conditioned on  $Z^{d_1}$ ,  $x$  and  $y$ . CL is less expressive than PF and SF, but both sampling and computing the probability of arbitrary samples are easier. In practice, we follow (Dinh et al., 2017) to switch  $Z^{d_1}$  and  $Z^{d_2}$  alternately for subsequent flows.
As we adopt the amortized inference strategy, the parameters of these NFs are data-dependent. In our model, they are the output of 1-layer linear map
<sup>1</sup>In VAE terms, the posterior and prior distributions are referred to as the encoders, while the generator is referred to as the decoder. As these terms have other specific meaning in NMT, we avoid to use them in this paper.
7772
with inputs that depend on  $\mathbf{x}$  and  $\mathbf{y}$ . Also, as the introduction of normalizing flows no longer offers a simple closed-form solution, we modify the KL term in Eq. 1 into:
$$
\mathbb {E} _ {q _ {\lambda} (Z | \boldsymbol {x}, \boldsymbol {y})} \left[ \log q _ {\lambda} (Z | \boldsymbol {x}, \boldsymbol {y}) - \log p _ {\psi} (Z | \boldsymbol {x}) \right]
$$
where we estimate the expectation w.r.t.  $q(Z_{K}|\pmb {x};\pmb {\lambda})$  via  $L$  Monte-Carlo samples. We found that  $L = 1$  is sufficient, similar to (Zhang et al., 2016). To address variable-length inputs, we use the average of the embeddings of the source and target tokens via a mean-pooling layer, i.e., meanpool  $(\pmb {x})$  and meanpool  $(y)$  respectively.
Transformer-based Generator We incorporate the latent code to the Transformer model by mixing the code into the output of the Transformer decoder's last layer  $(h_j)$  as follows:
$$
g _ {j} = \delta ([ h _ {j}; Z ]), \quad h _ {j} = (1 - g _ {j}) * h _ {j} + g _ {j} * Z
$$
where  $g_{j}$  controls the latent code's contribution, and  $\delta(\cdot)$  is the sigmoid function. In the case of the dimension of the latent code  $(D)$  doesn't match the dimension of  $h_{j}$ , we apply a linear projection layer. Our preliminary experiments suggest that Transformer is less likely to ignore the latent code in this approach compared to other approaches we explored, e.g., incorporating the latent code as the first generated token as used in (Zhang et al., 2016).
Prediction Ultimately, we search for the most probable translation  $(\hat{\pmb{y}})$  given a source sentence  $(\pmb{x})$  through the evidence lower bound. However, sampling latent codes from the posterior distribution is not straightforward, since the posterior is conditioned on the sentence being predicted. Zhang et al. (2016) suggests taking the prior's mean as the latent code. Unfortunately, as our prior is a Gaussian distribution, this strategy can diminish the benefit of employing normalizing flows posterior.
Eikema and Aziz (2018) explore two strategies, namely restricting the conditioning of the posterior to  $\pmb{x}$  alone (dropping  $\pmb{y}$ ) and introducing an auxiliary distribution,  $r(Z|x)$ , from which the latent codes are drawn. They found that the former is more accurate with the benefit of being simpler. This is confirmed by our preliminary experiments. We opt to adopt this strategy and use the mean of the posterior as the latent code at prediction time.
Mitigating Posterior Collapse As reported by previous work, VNMT models are prone to posterior collapse, where the training fails to learn informative latent code as indicated by the value of KL term that vanishes to 0. This phenomenon is often attributed to the strong generator (Alemi et al., 2018) employed by the models, in which case, the generator's internal cells carry sufficient information to generate the translation. Significant research effort has been spent to weaken the generator network. Mitigating posterior collapse is crucial for our VNMT model as we employ the Transformer, an even stronger generator that comes with more direct connections between source and target sentences (Bahuleyan et al., 2018).
To remedy these issues, we adopt the  $\beta_{C}$ -VAE (Prokhorov et al., 2019) and compute the following modified KL term:  $\beta |KL - C|$  where  $\beta$  is the scaling factor while  $C$  is a rate to control the KL magnitude. When  $C > 0$ , the models are discouraged from ignoring the latent code. In our experiments, we set  $C = 0.1$  and  $\beta = 1$ . Additionally, we apply the standard practice of word dropping in our experiments.
Related Work VNMT comes in two flavors. The first variant models the conditional probability akin to a translation model, while the second one models the joint probability of the source and target sentences. Our model adopts the first variant similar to (Zhang et al., 2016; Su et al., 2018; Pagnoni et al., 2018), while (Eikema and Aziz, 2018; Shah and Barber, 2018) adopt the second variant. The majority of VNMT models employ RNN-based generators and assume isotropic Gaussian distribution, except for (McCarthy et al., 2019) and (Przystupa et al., 2019). The former employs the Transformer architecture but assumes a Gaussian posterior, while the latter employs the normalizing flows posterior (particularly planar flows) but uses an RNN-based generator. We combine more sophisticated normalizing flows and the more powerful Transformer architecture to produce state-of-the-art results.
Experimental Setup We integrate our proposal into the Fairseq toolkit (Ott et al., 2019; Gehring et al., 2017a,b). We report results on the IWSLT'14 German-English (De-En) and the
7773
WMT'18 English-German (En-De) tasks. For IWSLT'14, we replicate Wu et al. (2019); Edunov et al. (2018)'s setup with 160K training sentences and a 10K joint BPE vocabulary, while for WMT'18, we replicate Edunov et al. (2018)'s setup with 5.2M training sentences and a 32K joint BPE vocabulary. For WMT experiments, we report the accuracy using detokenized SacreBLEU (Post, 2018) to facilitate fair comparison with other published results. Note that tokenized BLEU score is often higher depending on the tokenizer, thus not comparable. We apply KL annealing schedule and token dropout similar to (Bowman et al., 2016), where we set the KL annealing to 80K updates and drop out  $20\%$  target tokens in the IWSLT and  $10\%$  in the WMT experiments.
The encoder and decoder of our Transformer generator have 6 blocks each. The number of attention heads, embedding dimension, and inner-layer dimensions are 4, 512, 1024 for IWSLT; and 16, 1024, 4096 for WMT. The WMT setup is often referred to as the Transformer Big. To our knowledge, these architectures represent the best configurations for our tasks. We set the latent dimension to  $D = 128$ , which is projected using a 1-layer linear map to the embedding space. We report decoding results with beam=5. For WMT experiments, we set the length penalty to 0.6. For all experiments with NF-based posterior, we employ flows of length 4, following the results of our pilot study.
In-Domain Results We present our IWSLT results in rows 1 to 6 of Table 1. The accuracy of the baseline Transformer model is reported in row (1), which matches the number reported by Wu et al. (2019). In row (2), we report a static  $Z$  experiment, where  $Z = \mathrm{meanpool}(\boldsymbol{x})$ . We design this experiment to isolate the benefits of token dropping and utilizing average source embedding as context. As shown, the static  $Z$  provides +0.8 BLEU point gain. In row (3), we report the accuracy of our VNMT baseline when the approximate posterior is a Gaussian, which is +1.3 BLEU point from baseline or +0.5 point from the static  $Z$ , suggesting the efficacy of latent-variable modeling. We then report the accuracy of different variants of our model in rows (4) to (6), where we replace the Gaussian posterior with a cascade of 4 PF, SF and CL, respectively. For SF, we report the result with  $M = 8$  orthogonal columns in row (5).
As shown, these flows modestly add  $+0.2$  to  $+0.3$  points. It is worth noticing that the improvement introduces only around  $5\%$  additional parameters.
System	#params	BLEU
1	Transformer IWSLT	42.9M	34.5
2	+ static Z	42.9M	35.3
3	+ Z ~ Gaussian	43.6M	35.8
4	+ Z ~ 4 x PF	44.2M	36.1
5	+ Z ~ 4 x SF (M=8)	45.9M	36.0
6	+ Z ~ 4 x CL	44.3M	36.1
7	(1) + distilled	42.9M	34.9
8	(6) + distilled	44.3M	36.6
9	(Edunov et al., 2018)	29.0
10	Transformer Big	209.1M	28.9
11	+ static Z	209.1M	29.0
12	+ Z ~ Gaussian	210.5M	29.1
13	+ Z ~ 4 x PF	211.6M	29.3
14	+ Z ~ 4 x SF (M=8)	215.3M	29.5
15	+ Z ~ 4 x CL	210.6M	29.2
16	(10) + distilled	209.1M	29.2
17	(14) + distilled	215.3M	29.9
Table 1: The translation accuracy on the De-En IWSLT'14 task (rows 1-8), the En-De WMT'18 task (rows 10-17). Each task's best results in the in-domain setting are italicized, while the results with added distilled data are in bold.
We report our WMT results that use the Transformer Big architecture in rows (10) to (15). For comparison, we quote the state-of-the-art result for this dataset from Edunov et al. (2018) in row (9), where the SacreBLEU score is obtained from Edunov (2019). As shown, our baseline result (row 10) is on par with the state-of-the-art result. The WMT results are consistent with the IWSLT experiments, where our models (rows 13-15) significantly outperform the baseline, even though they differ in terms of which normalizing flows perform the best. The gain over the VNMT baseline is slightly higher, perhaps because NF is more effective in larger datasets. In particular, we found that SF and PF perform better than CL, perhaps due to their simpler architecture, i.e., their posteriors are conditioned only on the source sentence, and their priors are uninformed Gaussian. Row (11) shows that the static  $Z$ 's gain is minimal. In row (14), our best VNMT outperforms the state-of-the-art Transformer Big model by +0.6 BLEU while adding only 3% additional parameters.
7774
Simulated Bimodal Data We conjecture that the gain partly comes from NF's ability to capture non-Gaussian distribution. To investigate this, we artificially increase the modality of our training data, i.e., forcing all source sentences to have multiple translations. We perform the sequence-level knowledge distillation (Kim and Rush, 2016) with baseline systems as the teachers, creating additional data referred to as distilled data. We then train systems on this augmented training data, i.e., original + distilled data. Rows (7) and (16) show that the baseline systems benefit from the distilled data. Rows (8) and (17) show that our VNMT models gain more benefit, resulting in +2.1 and +0.9 BLEU points over non-latent baselines on IWSLT and WMT tasks respectively.
Simulated Out-of-Domain Condition We investigate whether the in-domain improvement carries to out-of-domain test sets. To simulate an out-of-domain condition, we utilize our existing setup where the domain of the De-En IWSLT task is TED talks while the domain of the En-De WMT task is news articles. In particular, we invert the IWSLT De-En test set, and decode the English sentences using our baseline and best WMT En-De systems of rows (10) and (14). For this inverted set, the accuracy of our baseline system is 27.9, while the accuracy of our best system is 28.8, which is +0.9 points better. For reference, the accuracy of the Gaussian system in row (11) is 28.2 BLEU. While more rigorous out-of-domain experiments are needed, this result gives a strong indication that our model is relatively robust for this out-of-domain test set.
Translation Analysis To better understand the effect of normalizing flows, we manually inspect our WMT outputs and showcase a few examples in Table 2. We compare the outputs of our best model that employs normalizing flows (VNMT-NF, row 14) with the baseline non-latent Transformer (row 10) and the baseline VNMT that employs Gaussian posterior (VNMT-G, row 12).
As shown, our VNMT model consistently improves upon gender consistency. In example 1, the translation of the interior decorator depends on the gender of its cataphora (her), which is feminine. While all systems translate the cataphora correctly to ihrem, the baseline and VNMT-G translate the
Example 1
Source	In her book, the interior decorator presents 17 housing models for independent living in old age.
Reference	In ihrem Buch stellt die Innenarchitektin 17 Wohnmodelle für ein selbstbestimmtes Wohnen im Alter vor.
Non-latent Baseline	In ihrem Buch präsentiert der Innenarchitekt 17 Wohnmodelle für ein unabhängiges Leben im Alter.
VNMT-G	In ihrem Buch stellt die der Innenarchitekt 17 Wohnmodelle für ein selbstbestimmtes Wohnen im Alter vor.
VNMT-NF	In ihrem Buch präsentiert die Innenkdekoratorin 17 Wohnmodelle für ein unabhängiges Leben im Alter.
Example 2
Source	Even though she earns S 3,000 (2,400) a month as an administrator and her husband works as well, the monthly family income is insufficient, she says.
Reference	Obwohl sie jeder Monat 3.000 Singapur-Dollar (ca 1.730 Euro) als Verwaltungsmitarbeiterin verdiene –truncated–
Non-latent Baseline	Obwohl sie pro Monat 3.000 S $ (2.400 $) als Verwalter verdient und auch ihr Mann arbeitet, ist das –truncated–
VNMT-G	Obwohl sie jeder Monat 3.000 Singapur-Dollar (ca 1.730 Euro) als Verwaltungsmitarbeiterin –truncated–
VNMT-NF	Obwohl sie S $ 3.000 ($ 2.400) pro Monat als Administratorin verdient und ihr Mann auch –truncated–
Table 2: Translation examples with different gender consistency. Inconsistent, consistent translations and source words are in red, orange, blue respectively.
phrase to its masculine form. In contrast, the translation of our VNMT-NF produces the feminine translation, respecting the gender agreement. In example 2, only VNMT-NF and VNMT-G produce gender consistent translations.
4 Discussions and Conclusions
We present a Variational NMT model that outperforms a strong state-of-the-art non-latent NMT model. We show that the gain modestly comes from the introduction of a family of flexible distribution based on normalizing flows. We also demonstrate the robustness of our proposed model in an increased multimodality condition and on a simulated out-of-domain test set.
We plan to conduct a more in-depth investigation into actual multimodality condition with high-coverage sets of plausible translations. We conjecture that conditioning the posterior on the target sentences would be more beneficial. Also, we plan to consider more structured latent variables beyond modeling the sentence-level variation as well as to apply our VNMT model to more language pairs.