Venue: NAACL 2019

# Stochastic Wasserstein Autoencoder for Probabilistic Sentence Generation

 Hareesh Bahuleyan, Lili Mou, Hao Zhou, Olga Vechtomova\({}^{\dagger}\)

University of Waterloo \(~{}^{\ddagger}\)ByteDance AI Lab

hballika@uwaterloo.ca doublepower.mou@gmail.com

zhouhao.nlp@bytedance.com ovechtomova@uwaterloo.ca

###### Abstract

The variational autoencoder (VAE) imposes a probabilistic distribution (typically Gaussian) on the latent space and penalizes the Kullback-Leibler (KL) divergence between the posterior and prior. In NLP, VAEs are extremely difficult to train due to the problem of KL collapsing to zero. One has to implement various heuristics such as KL weight annealing and word dropout in a carefully engineered manner to successfully train a VAE for text. In this paper, we propose to use the Wasserstein autoencoder (WAE) for probabilistic sentence generation, where the encoder could be either stochastic or deterministic. We show theoretically and empirically that, in the original WAE, the stochastically encoded Gaussian distribution tends to become a Dirac-delta function, and we propose a variant of WAE that encourages the stochasticity of the encoder. Experimental results show that the latent space learned by WAE exhibits properties of continuity and smoothness as in VAEs, while simultaneously achieving much higher BLEU scores for sentence reconstruction.1

Footnote 1: Our code is available at [https://github.com/HareeshBahuleyan/probabilistic_nlg](https://github.com/HareeshBahuleyan/probabilistic_nlg) A preliminary version of this paper was preprinted at [https://arxiv.org/abs/1806.08462](https://arxiv.org/abs/1806.08462)

+
Footnote †: Proceedings of NAACL-HLT 2019, pages 4068–4076 Minneapolis, Minnesota, June 2 - November 3, 2021

## 1 Introduction

Natural language sentence generation in the deep learning regime typically uses a recurrent neural network (RNN) to predict the most probable next word given previous words Mikolov et al. (2010). Such RNN architecture can be further conditioned on some source information, for example, an input sentence, resulting in a sequence-to-sequence (Seq2Seq) model.

Traditionally, sentence generation is accomplished in a _deterministic_ fashion, i.e., the model uses a deterministic neural network to encode an input sentence to some hidden representations, from which it then decodes an output sentence using another deterministic neural network.

bowman2016deep propose to use the variational autoencoder (VAE, Kingma and Welling, 2014) to map an input sentence to a probabilistic continuous latent space. VAE makes it possible to generate sentences from a distribution, which is desired in various applications. For example, in an open-domain dialog system, the information of an utterance and its response is not necessarily a one-to-one mapping, and multiple plausible responses could be suitable for a given input. Probabilistic sentence generation makes the dialog system more diversified and more meaningful Serban et al. (2017); Bahuleyan et al. (2018). Besides, probabilistic modeling of the hidden representations serves as a way of posterior regularization Zhang et al. (2016), facilitating interpolation Bowman et al. (2016) and manipulation of the latent representation Hu et al. (2017).

However, training VAEs in NLP is more difficult than the image domain Kingma and Welling (2014). The VAE training involves a reconstruction loss and a Kullback-Leibler (KL) divergence between the posterior and prior of the latent space. In NLP, the KL term tends to vanish to zero during training, leading to an ineffective latent space. Previous work has proposed various engineering tricks to alleviate this problem, including KL annealing and word dropout Bowman et al. (2016).

In this paper, we address the difficulty of training VAE sentence generators by using a Wasserstein autoencoder (WAE, Tolstikhin et al., 2018). WAE modifies VAE in that it requires the integration of the posterior to be close to its prior, where the closeness is measured with empirical samples drawn from the distributions. In this way, the encoder could be either stochastic or deterministic, but the model still retains probabilistic properties.



Moreover, we show both theoretically and empirically that the stochastic Gaussian encoder in the original form tends to be a Dirac-delta function. We thus propose a WAE variant that encourages the encoder's stochasticity by penalizing an auxiliary KL term.

Experiments show that the sentences generated by WAE exhibit properties of continuity and smoothness as in VAE, while achieving a much higher reconstruction performance. Our proposed variant further encourages the stochasticity of the encoder. More importantly, WAE is robust to hyperparameters and much easier to train, without the need for KL annealing or word dropout as in VAE. In a dialog system, we demonstrate that WAEs are capable of generating better quality and more diverse sentences than VAE.

## 2 Probabilistic Sentence Generation

Base Model: Deterministic Autoencoder (DAE).DAE encodes an input sentence with a recurrent neural network (RNN) and then decodes the same sentence through another RNN.

For the encoder, the hidden state of the last word is represented as the latent space of the input sentence \({\bf x}\). The latent representation is denoted as \(\mathbf{z}\). We feed \(\mathbf{z}\) to the decoder RNN, which predicts one word at a time using a softmax layer, given by \(p({\bf x}_{t}|\mathbf{z},{\bf x}_{<t})\).The training objective for DAE is the sequence-aggregated cross-entropy loss, given by

\[J=-\sum_{n=1}^{N}\sum_{t=1}^{|{\bf x}^{(n)}|}\log p({\bf x}_{t}^{( n)}|\mathbf{z}^{(n)},{\bf x}_{<t}^{(n)}) \tag{1}\]

where superscript \((n)\) indicates the \(n\)th data point among \(1,\cdots,N\).

In DAE, the latent space is encoded and then decoded in a deterministic way, i.e., there is no probabilistic modeling of the hidden space. The hidden representations of data may be located on an arbitrary manifold (Figure 0(a)), which is not suitable for probabilistic generation.

Variational Autoencoder (VAE).VAE extends DAE by imposing a prior distribution \(p(\mathbf{z})\) on the latent variable \(\mathbf{z}\), which is typically set to the standard normal \(\mathcal{N}(\mathbf{0},\mathbf{I})\)Kingma and Welling (2014). Given an input sentence \({\bf x}\), we would like to model the posterior of \(\mathbf{z}\) by another normal distribution, \(q(\mathbf{z}|{\bf x})=\mathcal{N}(\mathbf{\mu}_{\text{post}},\operatorname*{diag} \mathbf{\sigma}_{\text{post}}^{2})\), where \(\mathbf{\mu}_{\text{post}}\) and \(\mathbf{\sigma}_{\text{post}}^{2}\) are the outputs of the encoder.

In the training of VAE, \(\mathbf{z}\) is sampled from \(q(\mathbf{z}|{\bf x})\), and the training objective is to maximize a variational lower bound of the likelihood of data. This is equivalent to minimizing the (expected) reconstruction loss similar to (1), while being regularized by the KL divergence between \(q(\mathbf{z}|\mathbf{x})\) and \(p(\mathbf{z})\), given by

\[J= \sum_{n=1}^{N}\Big{[}-\mathop{\mathbb{E}}_{\mathbf{z}^{(n)}\sim q} \sum_{t=1}^{|{\bf x}^{(n)}|}\log p({\bf x}_{t}^{(n)}|\mathbf{z}^{(n)},{\bf x}_{<t}^ {(n)})\] \[+\lambda_{\text{VAE}}\cdot\mathrm{KL}(q(\mathbf{z}^{(n)}|{\bf x}^{(n) })\lVert p(\mathbf{z}))\Big{]} \tag{2}\]

where in the expectation \(\mathbf{z}^{(n)}\) is sampled from \(q(\mathbf{z}|{\bf x}^{(n)})\) and \(\lambda_{\text{VAE}}\) is a hyperparameter balancing the two terms.

Since VAE penalizes the divergence of \(\mathbf{z}\)'s posterior from its prior, it serves as a way of posterior regularization, making it possible to generate sentences from the continuous latent space.

However, the two objectives in (2) are contradictory to each other, as argued by Tolstikhin et al. (2018). VAE pushes the posterior of \(\mathbf{z}\), given any input \({\bf x}^{(n)}\), to be close to its prior, i.e., every blue ellipse in Figure 0(b) should be close to the red one. This makes perfect reconstruction impossible.

Further, VAE is difficult to train in NLP due to the problem of KL collapse, where the KL term tends to be zero, meaning that the encoder captures no information and the decoder learns an unconditioned language model. This phenomenon is observed in variational auto-regressive decoders using RNN. To alleviate this problem, existing tricks include KL annealing and word dropout Bowman et al. (2016), but both require extensive engineering.

Wasserstein Autoencoder (WAE).An alternative way of posterior regularization is to impose a constraint that the _aggregated posterior_ of \(\mathbf{z}\) should be the same as its prior Tolstsikhin et al. (2019).

Figure 1: The latent space of the deterministic autoencoder (DAE), variational autoencoder (VAE), Wasserstein autoencoder (WAE), as well as WAE with by our KL penalty. Blue circles: Posterior aggregated posterior distributions of data in the latent space. Red circles: Regularizations of the posterior.

 

2018), i.e., \(q({\mathbf{z}})\stackrel{{\text{def}}}{{=}}\sum_{\mathbf{x}}q({\mathbf{z}}| \mathbf{x})p_{\mathcal{D}}(\mathbf{x})\stackrel{{\text{set}}}{{=}} p({\mathbf{z}})\), where \(p_{\mathcal{D}}\) is the data distribution. This is also demonstrated in Figure 1c. By contrast, VAE requires that \(q({\mathbf{z}}|\mathbf{x})\) should be close to \(p({\mathbf{z}})\) for every input sentence \(\mathbf{x}\).

For computational purposes, Tolstikhin et al. (2018) relax the above constraint by penalizing the Wasserstein distance between \(q({\mathbf{z}})\) and \(p({\mathbf{z}})\). In particular, it is computed by the Maximum Mean Discrepancy (MMD), defined as

where \(P({\mathbf{z}})\) and \(Q({\mathbf{z}})\) are cumulative density functions. \(\mathcal{H}_{k}\) refers to the reproducing kernel Hilbert space defined by the kernel \(k\), which is often chosen as the inverse multiquadratic kernel \(k(x,y)=\frac{C}{C+\lVert x-y\rVert^{2}_{2}}\) for high-dimensional Gaussians.

One advantage of the Wasserstein distance is that it can be estimated by empirical samples as

\[\widehat{\mathrm{MMD}}=\frac{1}{N(N-1)}\sum_{n\neq m}k({\mathbf{z}}^ {(n)},{\mathbf{z}}^{(m)}) \tag{3}\] \[+\frac{1}{N(N-1)}\sum_{n\neq m}k({\widetilde{\mathbf{z}}}^{(n)},{ \widetilde{\mathbf{z}}}^{(m)})-\frac{1}{N^{2}}\sum_{n,m}k({\mathbf{z}}^{(n)},{ \widetilde{\mathbf{z}}}^{(m)})\]

where \({\widetilde{\mathbf{z}}}^{(n)}\) is a sample from the prior \(p({\mathbf{z}})\), and \({\mathbf{z}}^{(n)}\) is a sample from the aggregated posterior \(q({\mathbf{z}})\), which is obtained by sampling \(\mathbf{x}^{(n)}\) from the data distribution and then sampling \({\mathbf{z}}^{(n)}\) from \(q({\mathbf{z}}|\mathbf{x}^{(n)})\). In summary, the training objective of WAE is

\[J_{\textrm{WAE}}=-\sum_{n=1}^{N}\sum_{t=1}^{\lvert\texttt{x}^{(n)}\rvert}\log p (\texttt{x}_{t}^{(n)}|{\mathbf{z}}^{(n)},\textbf{x}_{<t}^{(n)})+\lambda_{\textrm{ WAE}}\cdot\widehat{\mathrm{MMD}} \tag{4}\]

where \(\lambda_{\textrm{WAE}}\) balances the MMD penalty and the reconstruction loss.

Alternatively, the dual form (adversarial loss) can also be used for WAE Zhao et al. (2018). In our preliminary experiments, we found MMD similar to but slightly better than the adversarial loss. The difference between our work and Zhao et al. (2018)--who extend the original WAE to sequence generation--is that we address the KL annealing problem of VAE and further analyze the stochasticity of WAE from a theoretical perspective, as follows.

Wae with Auxiliary Loss.In WAE, the aggregated posterior \(q({\mathbf{z}})\) involves an integration of data distribution, which allows using a deterministic function to encode \({\mathbf{z}}\) as \({\mathbf{z}}={\mathbf{f}}_{\textrm{encode}}(\mathbf{x})\) as suggested by Tolstikhin et al. (2018). This would largely alleviate the training difficulties as in VAE, because backpropagating gradient into the encoder no longer involves a stochastic layer.

The stochasticity of the encoder, however, is still a desired property in some applications, for example, generating diverse responses in a dialog system. We show both theoretically and empirically that a _dangling_ Gaussian stochastic encoder could possibly degrade to a deterministic one.

**Theorem 1**.: _Suppose we have a Gaussian family \(\mathcal{N}({\mathbf{\mu}},\operatorname{diag}{\mathbf{\sigma}}^{2})\), where \({\mathbf{\mu}}\) and \({\mathbf{\sigma}}\) are parameters. The covariance is diagonal, meaning that the variables are independent. If the gradient of \({\mathbf{\sigma}}\) completely comes from sample gradient and \({\mathbf{\sigma}}\) is small at the beginning of training, then the Gaussian converges to a Dirac delta function with stochastic gradient descent, i.e., \({\mathbf{\sigma}}\rightarrow{\bf 0}\). (See Appendix A for the proof.) \(\square\)_

To alleviate this problem, we propose a simple heuristic that encourages the stochasticity of the encoder. In particular, we penalize, for every data point, a KL term between the predicted posterior \(q({\mathbf{z}}|{\mathbf{x}})=\mathcal{N}({\mathbf{\mu}}_{\textrm{post}},\operatorname{ diag}{\mathbf{\sigma}}_{\textrm{post}}^{2})\) and a Gaussian with covariance \(\mathbf{I}\) centered at the predicted mean, i.e., \(\mathcal{N}({\mathbf{\mu}}_{\textrm{post}},\mathbf{I})\). This is shown in Figure 1d, where each posterior is encouraged to stretch with covariance \(\mathbf{I}\). Formally, the loss is

\[J=J_{\textrm{rec}}+\lambda_{\textrm{WAE}}\cdot\widehat{\mathrm{MMD}} \tag{5}\] \[+\lambda_{\textrm{KL}}\sum_{n}\operatorname{KL}\left(\mathcal{N}( \boldsymbol{\mu}_{\textrm{post}}^{(n)},\operatorname{diag}({\mathbf{\sigma}}_{ \textrm{post}}^{(n)})^{2})\right\lVert\mathcal{N}(\boldsymbol{\mu}_{\textrm{ post}}^{(n)},\mathbf{I})\right)\]

While our approach appears heuristic, the next theorem shows its theoretical justification.

**Theorem 2**.: _Objective (5) is a relaxed optimization of the WAE loss (4) with a constraint on \({\mathbf{\sigma}}_{\textrm{post}}\). (See Appendix B for the proof.) \(\square\)_

We will show empirically that such auxiliary loss enables us to generate smoother and more diverse sentences in WAE. It, however, does not suffer from KL collapse as in VAEs. The auxiliary KL loss that we define for stochastic WAE is computed against a target distribution \(\mathcal{N}(\boldsymbol{\mu}_{\textrm{post}}^{(n)},\mathbf{I})\) for each data sample \(\mathbf{x}^{(n)}\). Here, the predicted posterior mean itself is used in the target distribution 

As a result, this KL term does not force the model to learn the same posterior for all data samples (as in VAE), and thus, the decoder does not degrade to an unconditioned language model.

## 3 Experiments

We evaluate WAE in sentence generation on the Stanford Natural Language Inference (SNLI) dataset Bowman et al. (2015) as well as dialog response generation. All models use single-layer RNN with long short term memory (LSTM) units for both the encoder and decoder. Appendix C details our experimental settings.

VAE training.VAE is notoriously difficult to train in the RNN setting. While different researchers have their own practice of training VAE, we follow our previous experience Bahuleyan et al. (2018) and adopt the following tricks to stabilize the training: (1) \(\lambda_{\text{VAE}}\) was annealed in a \(\operatorname*{sigmoid}\) manner. We monitored the value of \(\lambda\cdot\mathrm{KL}\) and stop annealing once it reached its peak value, known as _peaking annealing_. (2) For word dropout, we started with no dropout, and gradually increased the dropout rate by \(0.05\) every epoch until it reached a value of \(0.5\). The effect of KL annealing is further analyzed in Appendix D.

### SNLI Generation

The SNLI sentences are written by crowdsourcing human workers in an image captioning task. It is a massive corpus but with comparatively simple sentences (examples shown in Table 4). This task could be thought of as domain-specific sentence generation, analogous to hand written digit generation in computer vision.

In Table 1, we compare all methods in two aspects. (1) We evaluate by **BLEU**Papineni et al. (2002) how an autoencoder preserves input information in a reconstruction task. (2) We also evaluate the quality of probabilistic sentence generation from the latent space. Although there is no probabilistic modeling of the latent space in DAE, we nevertheless draw samples from \(\mathcal{N}(\mathbf{0},\mathbf{I})\), which could serve as a non-informative prior. Perplexity (**PPL**) evaluates how fluent the generated sentences are. This is given by a third-party \(n\)-gram language model trained on the Wikipedia dataset. The unigram-KL (**UniKL**) evaluates if the word distribution of the generated sentences is close to that of the training corpus. Other surface metrics (entropy of the word distribution and average sentence length) also measure the similarity of the latent space generated sentence set to that of the corpus.

We see that DAE achieves the best BLEU score, which is not surprising because DAE directly optimizes the maximum likelihood of data as a surrogate of word prediction accuracy. Consequently, DAE performs poorly for probabilistic sentence generation as indicated by the other metrics.

VAE and WAE have additional penalties that depart from the goal of reconstruction. However, we see that WAEs, when trained with appropriate hyperparameters \((\lambda_{\text{WAE}},\lambda_{\text{KL}})\), achieve close performance to DAE, outperforming VAE by 40 BLEU points. This is because VAE encodes each input's posterior to be close to the prior, from which it is impossible to perfectly reconstruct the data.

Comparing the deterministic and stochastic encoders in WAE, we observe the same trade-off between reconstruction and sampling. However, our proposed stochastic encoder, with \(\lambda_{\rm KL}=0.1\) for WAE, consistently outperforms VAE in the contradictory metrics BLEU and PPL. The hyperparameters \(\lambda_{\text{WAE}}=10.0\) and \(\lambda_{\rm KL}=0.01\) appear to have the best balance between reconstruction, sentence fluency, as well as similarity to the original corpus.

Moreover, all our WAEs are trained without annealing or word dropout. It is significantly simpler than training a VAE, whose KL annealing typically involves a number of engineering tricks, such as the time step when KL is included, the slope of annealing, and the stopping criterion for annealing.

\begin{table}
\begin{tabular}{|l||c|c|c|c|} \hline  & **BLEU** & **PPL\({}^{\dagger}\)** & **UniKL\({}^{\ddagger}\)** & **Entropy** & **AvEqLen** \\ \hline

- & -5.63 & \(\rightarrow\)9.6 \\ \hline \hline
**DAE** & **86.35** & 146.2 & 0178 & 6.23 & 11.0 \\ \hline VAE (KL-annealed) & 43.18 & 79.4 & 0.081 & 5.04 & 8.8 \\ \hline WAE-D \(\lambda_{\text{WAE}}\!=\!3\) & 86.03 & 113.8 & 0.071 & 5.59 & 10.0 \\ WAE-D \(\lambda_{\text{WAE}}\!=\!10\) & 84.29 & 104.9 & 0.073 & 5.57 & 9.9 \\ \hline
**MAE-S**\(\lambda_{\text{KL}}\!=\!0.0\) & 75.66 & 115.0 & 0.69 & **5.61** & 9.9 \\
**MAE-S**\(\lambda_{\text{KL}}\!=\!0.01\) & 82.01 & 84.9 & **0.058** & 5.26 & **9.4** \\
**MAE-S**\(\lambda_{\text{KL}}\!=\!0.1\) & 47.63 & **62.5** & 0.150 & 4.65 & 8.7 \\ \hline \end{tabular}
\end{table}
Table 1: Results of SNLI-style sentence generation, where MAE is compared with DAE and VAE. **D** and **S** refer to the deterministic and stochastic encoders, respectively. \({}^{\uparrow/\downarrow}\)The larger/lower, the better. For **Entropy** and **AvgLen**, the closer to corpus statistics, the better (indicated by the \(\rightarrow\) arrow).

 



### Dialog Generation

We extend WAE to an encoder-decoder framework (denoted by WED) and evaluate it on the DailyDialog corpus Li et al. (2017).2 We follow Bahuleyan et al. (2018), using the encoder to capture an utterance and the decoder to generate a reply.

Footnote 2: In our pilot experiment, we obtained a BLEU-4 score of 6 by training a pure Seq2Seq model with LSTM units for 200 epochs, whereas Li et al. (2017) report 0.009 BLEU-4 and Luo et al. (2018) report 2.84 BLEU-4. Due to our unreasonably high performance, we investigated this in depth and found that the training and test sets of the DailyDialog corpus have overlaps. For the results reported in our paper, we have removed duplicate data in the test set, which is also available on our website (Footnote 1). To the best of our knowledge, we are the first to figure out the problem, which, unfortunately, makes comparison with previous work impossible.

Table 2 shows that WED with a deterministic encoder (WED-D) is better than the variational encoder-decoder (VED) in BLEU scores, but the generated sentences lack variety, which is measured by output entropy and the percentage of distinct unigrams and bigrams Dist-1/Dist-2, Li et al. (2016), evaluated on the generated test set responses.

We then applied our stochastic encoder for WED and see that, equipped with our KL-penalized stochastic encoder, WED-S outperforms DED, VED, and WED-D in all diversity measures. WED-S also outperforms VED in generation quality, consistent with the results in Table 1.

## 4 Conclusion

In this paper, we address the difficulty of training VAE by using a Wasserstein autoencoder (WAE) for probabilistic sentence generation. WAE implementation can be carried out with either a deterministic encoder or a stochastic one. The deterministic version achieves high reconstruction performance, but lacks diversity for generation. The stochastic encoder in the original form may collapse to a Dirac delta function, shown by both a theorem and empirical results. We thus propose to encourage stochasticity by penalizing a heuristic KL loss for WAE, which turns out to be a relaxed optimization of the Wasserstein distance with a constraint on the posterior family.

We evaluated our model on both SNLI sentence generation and dialog systems. We see that WAE achieves high reconstruction performance as DAE, while retaining the probabilistic property as VAE. Our KL-penalty further improves the stochasticity of WAE, as we achieve the highest performance in all diversity measures.

## Acknowledgments

We would like to acknowledge Yiping Song and Zhiliang Tian for their independent investigation on the DailyDialog corpus. We also thank Yanran Li, one of the authors who released DailyDialog, for discussion on this issue. This work was supported in part by the NSERC grant RGPIN-261439-2013 and an Amazon Research Award.

## References

* Bahuleyan et al. (2018) Hareesh Bahuleyan, Lili Mou, Olga Vechtomova, and Pascal Poupart. 2018. Variational attention for sequence-to-sequence models. In _Proceedings of the 27th International Conference on Computational Linguistics_, pages 1672-1682.
* Bowman et al. (2015) Samuel R. Bowman, Gabor Angeli, Christopher Potts, and Christopher D. Manning. 2015. A large annotated corpus for learning natural language inference. In _Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing_, pages 632-642.
* Bowman et al. (2016) Samuel R Bowman, Luke Vilnis, Oriol Vinyals, Andrew M Dai, Rafal Jozefowicz, and Samy Bengio. 2016. Generating sentences from a continuous space. In _Proceedings of the 20th SIGNLL Conference on Computational Natural Language Learning_, pages 10-21.
* Burgess et al. (2017) Christopher P Burgess, Irina Higgins, Arka Pal, Loic Matthey, Nick Watters, Guillaume Desjardins, and Alexander Lerchner. 2017. Understanding disentangling in beta-VAE. In _Proceedings of the Workshop on Learning Disentangled Representations: From Perception to Control_.
* Higgins et al. (2017) Irina Higgins, Loic Matthey, Arka Pal, Christopher Burgess, Xavier Glorot, Matthew Botvinick, Shakir Mohamed, and Alexander Lerchner. 2017. beta-vae: Learning basic visual concepts with a constrained variational framework. In _Proceedings of the International Conference on Learning Representations_.
* Hu et al. (2017) Zhiting Hu, Zichao Yang, Xiaodan Liang, Ruslan Salakhutdinov, and Eric P. Xing. 2017. Toward controlled generation of text. In _Proceedings of the

\begin{table}
\begin{tabular}{|l|c||c||c|c|c|} \hline  & **BLEU-2** & **BLEU-4** & **Entropy** & **Dist-1** & **Dist-2** \\ \hline \hline
**Test Set** & **-** & **-** & 6.15 & 0.077 & 0.414 \\ \hline
**PED** & 3.96 & 0.85 & 5.55 & 0.044 & 0.275 \\
**VED** & 3.26 & 0.59 & 5.45 & 0.053 & 0.204 \\
**WERD-D** & **4.05** & **0.98** & 5.53 & 0.042 & 0.272 \\
**WERD-S** & 3.72 & 0.69 & **5.59** & **0.066** & **0.309** \\ \hline \end{tabular}
\end{table}
Table 2: Results on dialog generation, where VED/WED hyperparameters for each model were chosen by Table 1.



34th International Conference on Machine Learning_, pages 1587-1596.
* Kingma and Ba (2015) Diederik P Kingma and Jimmy Ba. 2015. Adam: A method for stochastic optimization. In _Proceedings of the International Conference on Learning Representations_.
* Kingma and Welling (2014) Diederik P Kingma and Max Welling. 2014. Autoencoding variational Bayes. In _Proceedings of International Conference on Learning Representations_, pages 10-21.
* Li et al. (2016) Jiwei Li, Michel Galley, Chris Brockett, Jianfeng Gao, and Bill Dolan. 2016. A diversity-promoting objective function for neural conversation models. In _Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_, pages 110-119.
* Li et al. (2017) Yanran Li, Hui Su, Xiaoyu Shen, Wenjie Li, Ziqiang Cao, and Shuzi Niu. 2017. DailyDialog: a manually labelled multi-turn dialogue dataset. In _Proceedings of the 8th International Joint Conference on Natural Language Processing_, pages 986-995.
* Luo et al. (2018) Liangchen Luo, Jingjing Xu, Junyang Lin, Qi Zeng, and Xu Sun. 2018. An auto-encoder matching model for learning utterance-level semantic dependency in dialogue generation. In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_, pages 702-707.
* Mikolov et al. (2010) Tomas Mikolov, Martin Karafiat, Lukas Burget, Jan Cernocky, and Sanjeev Khudanpur. 2010. Recurrent neural network based language model. In _Eleventh Annual Conference of the International Speech Communication Association_, pages 1045-1048.
* Papineni et al. (2002) Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. 2002. BLEU: a method for automatic evaluation of machine translation. In _Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics_, pages 311-318.
* Serban et al. (2017) Iulian Vlad Serban, Alessandro Sordoni, Ryan Lowe, Laurent Charlin, Joelle Pineau, Aaron C Courville, and Yoshua Bengio. 2017. A hierarchical latent variable encoder-decoder model for generating dialogues. In _Proceedings of the Thirty-First AAAI Conference on Artificial Intelligence_, pages 3295-3301.
* Tolstikhin et al. (2018) Ilya Tolstikhin, Olivier Bousquet, Sylvain Gelly, and Bernhard Scholkopf. 2018. Wasserstein autoencoders. In _Proceedings of International Conference on Learning Representations_.
* Xu and Durrett (2018) Jiasheng Xu and Greg Durrett. 2018. Spherical latent spaces for stable variational autoencoders. In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_, pages 4503-4513.
* Yang et al. (2017) Zichao Yang, Zhiting Hu, Ruslan Salakhutdinov, and Taylor Berg-Kirkpatrick. 2017. Improved variational autoencoders for text modeling using dilated convolutions. In _Proceedings of the International Conference on Machine Learning_, pages 3881-3890.
* Zhang et al. (2016) Biao Zhang, Deyi Xiong, jinsong su, Hong Duan, and Min Zhang. 2016. Variational neural machine translation. In _Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing_, pages 521-530.
* Zhao et al. (2018) Junbo Zhao, Yoon Kim, Kelly Zhang, Alexander Rush, and Yann LeCun. 2018. Adversarially regularized autoencoders. In _Proceedings of the 35th International Conference on Machine Learning_, pages 5902-5911.

## Appendix A Proof of Theorem 1

**Theorem 1**.: _Suppose we have a Gaussian family \({\cal N}(\mathbf{\mu},\operatorname{diag}\mathbf{\sigma}^{2})\), where \(\mathbf{\mu}\) and \(\mathbf{\sigma}\) are parameters. The covariance is diagonal, meaning that the variables are independent. If the gradient of \(\mathbf{\sigma}\) completely comes from sample gradient and \(\mathbf{\sigma}\) is small at the beginning of training, then the Gaussian converges to a Dirac delta function with stochastic gradient descent, i.e., \(\mathbf{\sigma}\to\mathbf{0}\)._

Proof.: For the predicted posterior \({\cal N}(\mathbf{\mu},\operatorname{diag}\mathbf{\sigma}^{2})\) where all dimensions are independent, we consider a certain dimension, where the sample is \(z_{i}\sim{\cal N}(\mu_{i},\sigma_{i}^{2})\).

We denote the gradient of \(J\) wrt to \(z_{i}\) at \(z_{i}=\mu_{i}\) by \(g_{i}\mathrel{\ensurestack[t]{=$\Delta$}{=}}\frac{\partial J}{\partial z_{i}} \big{|}_{z_{i}=\mu_{i}}\). At a particular sample \(z_{i}^{(j)}\) around \(\mu_{i}\), the gradient \(g_{i}^{(j)}\) is

\[g_{i}^{(j)} \mathrel{\ensurestack[t]{=$\Delta$}{=}}\frac{\partial J}{ \partial z_{i}}\bigg{|}_{z_{i}=z_{i}^{(j)}} \tag{6}\] \[\approx g_{i}+\frac{\partial^{2}J}{\partial\mu_{i}^{2}}(z_{i}^{(j)}- \mu_{i})\] (7) \[\mathrel{\ensurestack[t]{=$\Delta$}{=}}g_{i}+k(z_{i}^{(j)}-\mu_{i})\] (8) \[=g_{i}+k(\mu_{i}+\epsilon^{(j)}\sigma_{i}-\mu_{i})\] (9) \[=g_{i}+k\sigma_{i}\epsilon^{(j)} \tag{10}\]

where (7) is due to Taylor series approximation, if we assume \(\sigma_{i}^{2}\) is small and thus \(z_{i}^{(j)}\) is near \(\mu_{i}\). \(k\) denotes \(\frac{\partial^{2}J}{\partial\mu_{i}^{2}}\).

We compute the expected gradient wrt to \(\sigma_{i}\) for \(\epsilon\sim{\cal N}(0,1)\). The assumption of this theorem is that the gradient of \(\mu_{i}\) and \(\sigma_{i}\) completely comes from the sample \(z_{i}\). By the chain rule, we hav 

\[\mathop{\mathbb{E}}_{\epsilon^{(j)}\sim\mathcal{N}(0,1)}\left[ \frac{\partial J}{\partial\sigma_{i}}\right] \tag{11}\] \[=\mathop{\mathbb{E}}_{\epsilon^{(j)}\sim\mathcal{N}(0,1)}\left[ \frac{\partial J}{\partial z_{i}^{(j)}}\cdot\frac{\partial z_{i}^{(j)}}{ \partial\sigma_{i}}\right]\] (12) \[=\mathop{\mathbb{E}}_{\epsilon^{(j)}\sim\mathcal{N}(0,1)}\left[ \big{(}g_{i}+k\sigma_{i}\epsilon^{(j)}\big{)}\cdot\epsilon^{(j)}\right]\] (13) \[=\mathop{\mathbb{E}}_{\epsilon^{(j)}\sim\mathcal{N}(0,1)}\Big{[} g_{i}\epsilon_{i}^{(j)}+k\sigma_{i}(\epsilon^{(j)})^{2}\Big{]}\] (14) \[= k\sigma_{i} \tag{15}\]

Notice that \(k>0\) if we are near a local optimum (locally convex).

In other words, the expected gradient of \(\sigma_{i}\) is proportional to \(\sigma_{i}\). According to stochastic gradient descent (SGD), \(\sigma_{i}\) will converge to zero. 

The theorem assumes \(\boldsymbol{\sigma}^{2}\) is small, compared with how \(J\) changes in the latent space. In practice, the encoded vectors of different samples may vary a lot, whereas if we sample different vectors from a certain predicted multi-variate Gaussian, we would generally obtain the same sentence. Therefore, \(J\) is kind of smooth in the latent space. The phenomenon can also be verified empirically by plotting the histogram of \(\sigma\) in WAE with a stochastic Gaussian encoder (Figure 2). We see that if the KL coefficient \(\lambda_{\mathrm{KL}}\) is 0, meaning that the gradient of \(\sigma\) comes only from the samples, then most \(\sigma\)'s collapse to 0.

Notice, however, that the theorem does not suggest a stochastic WAE and a deterministic WAE will yield exactly the same result, as their trajectories may be different.

## Appendix B Proof of Theorem 2

**Theorem 2**.: _Objective (5) is a relaxed optimization of the WAE loss (4) with a constraint on \(\boldsymbol{\sigma}_{\text{post}}\)._

Proof.: Objective (5) optimizes

\[J=J_{\text{rec}}+\lambda_{\text{WAE}}\cdot\widehat{\mathrm{ MMD}}\\ +\lambda_{\text{KL}}\sum_{n}\operatorname{KL}\left(\mathcal{N}( \boldsymbol{\mu}_{\text{post}}^{(n)},\operatorname*{diag}(\boldsymbol{\sigma }_{\text{post}}^{(n)})^{2})\|\mathcal{N}(\boldsymbol{\mu}_{\text{post}}^{(n)}, \mathbf{I})\right) \tag{16}\]

The first two terms are the WAE loss, whereas the last penalty relaxes the following optimization problem

\[\begin{array}{l}\text{minimize~{}~{}$J_{\text{rec}}+\lambda_{\text{WAE}} \cdot\widehat{\mathrm{MMD}}$}\\ \text{subject to}\\ \quad\sum_{n}\operatorname{KL}\left(\mathcal{N}(\boldsymbol{\mu}_{\text{ post}}^{(n)},\operatorname*{diag}(\boldsymbol{\sigma}_{\text{post}}^{( n)}))\middle||\mathcal{N}(\boldsymbol{\mu}_{\text{post}}^{(n)}, \mathbf{I})\right)<C\end{array} \tag{17}\]

for some constant \(C\).

As known, the KL divergence between two

Figure 2: The histograms of \(\sigma\) in the posterior of the WAE in the SNLI experiment. In the plot, there are 200 buckets in the range of \((0,1)\).

 

(uninvariant) Gaussian distributions is

\[{\rm KL}(\mathcal{N}(\mu_{1},\sigma_{1})\|(\mathcal{N}(\mu_{2}, \sigma_{2})))\] \[= \log\frac{\sigma_{2}}{\sigma_{1}}+\frac{\sigma_{1}^{2}+(\mu_{1}- \mu_{2})^{2}}{2\sigma_{2}^{2}}-\frac{1}{2} \tag{17}\]

The constraint in (16) is equivalent to

\[\sum_{n}\sum_{i}\left[-\log\sigma_{i}^{(n)}+\frac{1}{2}(\sigma_{ i}^{(n)})^{2}\right]<C \tag{18}\]

In other words, our seemingly heuristic KL penalty optimizes the Wasserstein loss, while restricting the posterior family. 

## Appendix C Implementation Details

All models were trained with the Adam optimizer Kingma and Ba (2015) with \(\beta_{1}=0.9\) and \(\beta_{2}=0.999\). In all our experiments, we feed the sampled latent vector \(\mathbf{z}\) to each time step of the decoder. Task-specific settings are listed in Table 3.

## Appendix D VAE Training Difficulties

It is a common practice that training VAEs involves KL annealing and word dropout, which further consists of hacks for tuning hyperparameters. We conducted an experiment of training VAE without KL annealing. In Figure 3, we present the KL loss (weighted by \(\lambda_{\text{VAE}}\)) during the training process for different values of \(\lambda_{\text{VAE}}\). The KL loss is believed to be an important diagnostic measure to indicate if the latent space is "variational" Yang et al. (2017); Higgins et al. (2017); Burgess et al. (2017). We see that if the penalty is too large, KL simply collapses to zero ignoring the entire input, in the case of which, the decoder becomes an unconditioned language model. On the other hand, if the KL penalty is too small, the model tends to become more _deterministic_ and the KL term does not play a role in the training. This is expected since in the limit of \(\lambda_{\text{VAE}}\) to \(0\), the model would probably ignore the KL term and becomes a deterministic autoencoder (shown also by Theorem 1).

The VAE with collapsed KL does not exhibit interesting properties such as random sampling for probabilistic sequence generation Bowman et al. (2016). As seen in Table 4, the generated sentences by VAE without annealing are very close to each other. This is because VAE's encoder does not capture useful information in the latent space, which is simply ignored during the decoding phase. By sampling the latent space, we do not obtain varying sentences. The empirical evidence verifies our intuition.

A recent study Xu and Durrett (2018) propose to get rid of KL annealing by using the von Mises-Fisher (vMF) family of posterior and prior. In particular, they set the prior to the uniform distribution on a unit hypersphere, whereas the posterior family is normal distribution on the surface of the same sphere. They fix the standard deviation (parametrized by \(\kappa\)) of the posterior, so that their KL is a constant and annealing is not required. This, unfortunately, loses the privilege of learning uncertainty in the probabilistic modeling. Examples in Table 4 show that, while we have reproduced the reconstruction negative log-likelihood with vMF-VAE (the metric used in their paper), the generated sentences are of poor quality. As also suggested by Xu and Durrett (2018), if the posterior uncertainty in vMF is made learnable, it re-introduces the KL collapse problem, in which 

case, the KL annealing is still needed.

By contrast, WAEs for sequence-to-sequence models are trained without any additional optimization strategies such as annealing. Even in our stochastic encoder, the KL penalty does not make WAE an unconditioned language model, because it does not force the encoded posterior to be the same for different input sentences.

## Appendix E Qualitative Samples

Table 4 shows sentences generated by randomly sampling points in the latent space for different models, along with sample sentences from the training set. They provide a qualitative understanding of each model's performance.

\begin{table}
\begin{tabular}{|p{213.8pt}|} \hline
**Training Samples** \\ _a mother and her child are outdoors._ \\ _the people are opening presents._ \\ _the girls are looking toward the water._ \\ _a small boy walks down a wooden path in the woods._ \\ _a person in a green jacket it surfing while holding on to a line._ \\ \hline
**DAE** \\ _two families walking in a towel down alaska sands Actor._ \\ _a blade is rolling its nose fatiously paper_ \\ _a woman in blue shirts is passing by a some beach transporting his child are wearing overalls ._ \\ _a guys are blowing on professional thinks the horse ._ \\ \hline
**VAE Without Annealing** \\ _a man is playing a guitar._ \\ _a man is playing with a dog ._ \\ _a man is playing with a dog ._ \\ _a man is playing a guitar._ \\ _a man is playing with a dog ._ \\ \hline
**VAE With Annealing** \\ _the band is sitting on the main street ._ \\ _couple dance on stage in a crowded room ._ \\ _two people run alone in an empty field ._ \\ _the group of people have gathered in a picture ._ \\ _a cruise ship is docking a boat ship ._ \\ \hline
**VAE MF** (\(\kappa\) fixed) \\ _a car is a and and a blue shirt top is ._ \\ _two children are playing on the group in are the the ._ \\ _a child and a adult and_ \\ _the young is playing for a picture ._ _a rule is playing a background ._ \\ \hline
**WAE-D** (\(\Delta_{\text{WEA}}=10\)) \\ _the lone man is working ._ \\ _the group of men is using ice at the sunset ._ \\ _a family is outside in the background ._ \\ _no women are standing on a busy street outside a fair_ \\ _a tourists is having fun on a sunny day_ \\ \hline
**WAE-S** (\(\lambda_{\text{MAE}}=10\), \(\lambda_{\text{KL}}=0.01\)) \\ _an asian man is dancing in a highland house ._ \\ _a person wearing a purple snowswirl jumps over the tree ._ \\ _the vocalist is at the music and dancing with a microphone ._ \\ _a young man is dressed in a white shirt cleaning clothes ._ \\ _three children lie together and a woman falls in a plane ._ \\ \hline \end{tabular}
\end{table}
Table 4: Sentences generated by randomly sampling from the prior for different models.