Generating Sentences from a Continuous Space

Samuel R. Bowman, Luke Vilnis, Oriol Vinyals, Andrew M. Dai, Rafal Józefowicz, Samy BengioCoNLL 2015

Abstract

The standard recurrent network language model (RNNLM) generates sentences one word at a time and does not work from an explicit global sentence representation. In this work, we introduce and study an RNN-based variational autoencoder generative model that incorporates distributed latent representations of entire sentences. This factorization allows it to explicitly model holistic properties of sentences such as style, topic, and high-level syntactic features. Samples from the prior over these sentence representations remarkably produce diverse and well-formed sentences through simple deterministic decoding. By examining paths through this latent space, we are able to generate coherent novel sentences that interpolate between known sentences. We present techniques for solving the difficult learning problem presented by this model, demonstrate its effectiveness in imputing missing words, explore many interesting properties of the model's latent sentence space, and present negative results on the use of the model in language modeling.

Introduction

Standard Recurrent Neural Network Language Models (RNNLMs) are excellent at predicting the "next word," but they lack an explicit global representation of a sentence. They don't "know" the topic or style of the sentence they are halfway through writing. Furthermore, while standard autoencoders can compress a sentence into a vector, their latent space is often "fractured." If you take two encoded sentences and look at a point halfway between them, a standard decoder usually produces ungrammatical gibberish. This paper introduces the Sentence VAE to create a smooth, continuous latent space where every point represents a valid, human-like sentence.

Methods: The RNN-based VAE

The authors propose an RNN-based Variational Autoencoder (VAE) framework for text. Unlike standard models, this architecture maps entire sentences into a continuous, high-dimensional latent space.

  1. Encoder: An LSTM takes a sentence and outputs the parameters (mean and variance) of a Gaussian distribution.
  2. Latent Variable ($z$): A vector is sampled from this distribution, representing the "global features" of the sentence.
  3. Decoder: Another LSTM reconstructs the sentence, conditioned on this latent vector $z$.
The RNN-VAE architecture: an LSTM encoder maps inputs to latent parameters, from which a vector z is sampled to condition the LSTM decoder.

Overcoming Posterior Collapse

A major technical hurdle is that RNN decoders are "too powerful." Because an RNN can model text well just by looking at previous words, it often learns to ignore the latent vector $z$ entirely to minimize the KL divergence penalty. To fix this "posterior collapse," the authors introduced two key techniques:

  • KL Cost Annealing: Gradually increasing the KL penalty during training to allow the model to first learn to pack information into the latent space.
  • Word Dropout: Randomly replacing input words with an "unknown" token during decoding, forcing the model to rely on the global latent vector $z$ to reconstruct the sentence.

Key Insights and Results

The most striking feature of the Sentence VAE is its ability to perform "sentence morphing" or interpolation. By taking a linear path between the vectors of two sentences in the continuous latent space, the model generates a sequence of intermediate sentences. Unlike standard models, these transitions are smooth—changing a subject here or a verb tense there—while remaining grammatically plausible.

Sentence interpolation: taking a linear path between two points in the latent space produces a sequence of grammatically coherent intermediate sentences.

Beyond qualitative results, the VAE performs comparably to standard RNNLMs in language modeling and significantly outperforms them in tasks like sentence imputation (filling in missing words). Because it has a global "plan" ($z$), it can propagate information bidirectionally, whereas a standard RNN only looks backward.

Conclusion

The Sentence VAE demonstrates that it is possible to map discrete text into a continuous, generative space. While the model is notoriously difficult to train, its ability to capture global features like topic and style opens new doors for controlled text generation and semantic manipulation in natural language processing.

Summary updated

BibTeX
@inproceedings{bowman2015generating,
  author = {Samuel R. Bowman and Luke Vilnis and Oriol Vinyals and Andrew M. Dai and Rafal Józefowicz and Samy Bengio},
  title = {{Generating Sentences from a Continuous Space}},
  booktitle = {CoNLL},
  year = {2015},
  url = {https://openreview.net/forum?id=BrTrw7IEYk},
}
Figure