Topic Modeling in Embedding Spaces

Topic modeling analyzes documents to learn meaningful patterns of words. However, existing topic models fail to learn interpretable topics when working with large and heavy-tailed vocabularies. To this end, we develop the Embedded Topic Model (ETM), a generative model of documents that marries traditional topic models with word embeddings. In particular, it models each word with a categorical distribution whose natural parameter is the inner product between a word embedding and an embedding of its assigned topic. To fit the ETM, we develop an efficient amortized variational inference algorithm. The ETM discovers interpretable topics even with large vocabularies that include rare words and stop words. It outperforms existing document models, such as latent Dirichlet allocation (LDA), in terms of both topic quality and predictive performance.


Introduction
Topic models are statistical tools for discovering the hidden semantic structure in a collection of documents (Blei et al., 2003;Blei, 2012). Topic models and their extensions have been applied to many fields, such as marketing, sociology, political science, and the digital humanities. Boyd-Graber et al. (2017) provide a review.
Most topic models build on latent Dirichlet allocation (LDA) (Blei et al., 2003). LDA is a hierarchical probabilistic model that represents each topic as a distribution over terms and represents each document as a mixture of the topics. When fit to a collection of documents, the topics summarize their contents, and the topic proportions provide a low-dimensional representation of each one. LDA 1 Code for this work can be found at https:// github.com/adjidieng/ETM.
can be fit to large datasets of text by using variational inference and stochastic optimization (Hoffman et al., 2010(Hoffman et al., , 2013.
LDA is a powerful model and it is widely used. However, it suffers from a pervasive technical problem-it fails in the face of large vocabularies. Practitioners must severely prune their vocabularies in order to fit good topic models, i.e., those that are both predictive and interpretable. This is typically done by removing the most and least frequent words. On large collections, this pruning may remove important terms and limit the scope of the models. The problem of topic modeling with large vocabularies has yet to be addressed in the research literature.
In parallel with topic modeling came the idea of word embeddings. Research in word embeddings begins with the neural language model of Bengio et al. (2003), published in the same year and journal as Blei et al. (2003). Word embeddings eschew the "one-hot" representation of wordsa vocabulary-length vector of zeros with a single one-to learn a distributed representation, one where words with similar meanings are close in a lower-dimensional vector space (Rumelhart and Abrahamson, 1973;Bengio et al., 2006). As for topic models, researchers scaled up embedding methods to large datasets (Mikolov et al., 2013a,b;Pennington et al., 2014;Levy and Goldberg, 2014;Mnih and Kavukcuoglu, 2013). Word embeddings have been extended and developed in many ways. They have become crucial in many applications of natural language processing (Li and Tao, 2018), and they have also been extended to datasets beyond text (Rudolph et al., 2016).
In this paper, we develop the embedded topic model (ETM), a topic model for word embeddings. The ETM enjoys the good properties of topic models and the good properties of word embeddings. Coherence-Normalized Perplexity LDA ETM Figure 1. Ratio of the normalized held-out perplexity for document completion and the topic coherence as as a function of the vocabulary size for the ETM and LDA. While the performance of LDA deteriorates for large vocabularies, the ETM maintains good performance.
As a topic model, it discovers an interpretable latent semantic structure of the texts; as a word embedding, it provides a low-dimensional representation of the meaning of words. It robustly accommodates large vocabularies and the long tail of language data. Figure 1 illustrates the advantages. This figure plots the ratio between the predictive perplexity of held-out documents and the topic coherence, as a function of the size of the vocabulary. (The perplexity has been normalized by the vocabulary size.) This is for a corpus of 11.2K articles from the 20NewsGroup and for 100 topics. The red line is LDA; its performance deteriorates as the vocabulary size increases-the predictive performance and the quality of the topics get worse. The blue line is the ETM; it maintains good performance, even as the vocabulary size gets large.
Like LDA, the ETM is a generative probabilistic model: each document is a mixture of topics and each observed word is assigned to a particular topic. In contrast to LDA, the per-topic conditional probability of a term has a log-linear form that involves a low-dimensional representation of the vocabulary. Each term is represented by an embedding; each topic is a point in that embedding space; and the topic's distribution over terms is proportional to the exponentiated inner product of the topic's embedding and each term's embedding. Figures 2 and 3 show topics from a 300-topic ETM of The New York Times. The figures show each topic's embedding and its closest words; these topics are about Christianity and sports.
Due to the topic representation in terms of a point in the embedding space, the ETM is also robust to the presence of stop words, unlike most common topic models. When stop words are included in the vocabulary, the ETM assigns topics to the corresponding area of the embedding space (we demonstrate this in Section 6).
As for most topic models, the posterior of the topic proportions is intractable to compute. We derive an efficient algorithm for approximating the posterior with variational inference (Jordan et al., 1999;Hoffman et al., 2013;Blei et al., 2017) and additionally use amortized inference to efficiently approximate the topic proportions (Kingma and Welling, 2014;Rezende et al., 2014). The resulting algorithm fits the ETM to large corpora with large vocabularies. The algorithm for the ETM can either use previously fitted word embeddings, or fit them jointly with the rest of parameters. (In particular, Figures 1 to 3 were obtained with the version of the ETM that obtains pre-fitted skip-gram word embeddings.) We compared the performance of the ETM to LDA and the neural variational document model (NVDM), a form of multinomial matrix factorization. The ETM provides good predictive performance, as measured by held-out log-likelihood on a document completion task (Wallach et al., 2009). It also provides meaningful topics, as measured by topic coherence (Mimno et al., 2011) and topic diversity, a metric that also indicates the quality of the topics. The ETM is especially robust to large vocabularies.

Related Work
This work develops a new topic model that extends LDA. LDA has been extended in many ways, and topic modeling has become a subfield of its own. For a review, see Blei (2012) and Boyd-Graber et al. (2017).
One of the goals in developing the ETM is to incorporate word similarity into the topic model, and there is previous research that shares this goal. These methods either modify the topic priors (Petterson et al., 2010;Zhao et al., 2017b;Shi et al., Petterson et al. (2010) use a word similarity graph (as given by a thesaurus) to bias LDA towards assigning similar words to similar topics. As another example, Xie et al. (2015) model the per-word topic assignments of LDA using a Markov random field to account for both the topic proportions and the topic assignments of similar words. These methods use word similarity as a type of "side information" about language; in contrast, the ETM directly models the similarity (via embeddings) in its generative process of words.
Other work has extended LDA to directly involve word embeddings. One common strategy is to convert the discrete text into continuous observations of embeddings, and then adapt LDA to generate real-valued data (Das et al., 2015;Xun et al., 2016;Batmanghelich et al., 2016;Xun et al., 2017). With this strategy, topics are Gaussian distributions with latent means and covariances, and the likelihood over the embeddings is modeled with a Gaussian (Das et al., 2015) or a Von-Mises Fisher distribution (Batmanghelich et al., 2016). The ETM differs from these approaches in that it is a model of categorical data, one that goes through the embeddings matrix. Thus it does not require pre-fitted embeddings and, indeed, can learn embeddings as part of its inference process.
There have been a few other ways of combining LDA and embeddings. Nguyen et al. (2015) mix the likelihood defined by LDA with a log-linear model that uses pre-fitted word embeddings; Bunk and Krestel (2018) randomly replace words drawn from a topic with their embeddings drawn from a Gaussian; and Xu et al. (2018) adopt a geometric perspective, using Wasserstein distances to learn topics and word embeddings jointly.
Another thread of recent research improves topic modeling inference through deep neural networks (Srivastava and Sutton, 2017; Card et al., 2017;Cong et al., 2017;Zhang et al., 2018). Specifically, these methods reduce the dimension of the text data through amortized inference and the variational auto-encoder (Kingma and Welling, 2014;Rezende et al., 2014). To perform inference in the ETM, we also avail ourselves of amortized inference methods (Gershman and Goodman, 2014).
Finally, as a document model, the ETM also relates to works that learn per-document representations as part of an embedding model (Le and Mikolov, 2014;Moody, 2016;Miao et al., 2016). In contrast to these works, the document variables in the ETM are part of a larger probabilistic topic model.

Background
The ETM builds on two main ideas, LDA and word embeddings. Consider a corpus of D documents, where the vocabulary contains V distinct terms. Let w dn ∈ {1, . . . , V } denote the n th word in the d th document.
Latent Dirichlet allocation. LDA is a probabilistic generative model of documents (Blei et al., 2003). It posits K topics β 1:K , each of which is a distribution over the vocabulary. LDA assumes each document comes from a mixture of topics, where the topics are shared across the corpus and the mixture proportions are unique for each document. The generative process for each document is the following: 1. Draw topic proportion θ d ∼ Dirichlet(α θ ). 2. For each word n in the document: (a) Draw topic assignment z dn ∼ Cat(θ d ).
Word embeddings. Word embeddings provide models of language that use vector representations of words (Rumelhart and Abrahamson, 1973;Bengio et al., 2003). The word representations are fitted to relate to meaning, in that words with similar meanings will have representations that are close. (In embeddings, the "meaning" of a word comes from the contexts in which it is used.) We focus on the continuous bag-of-words (CBOW) variant of word embeddings (Mikolov et al., 2013b). In CBOW, the likelihood of each word w dn is (1) The embedding matrix ρ is a L × V matrix whose columns contain the embedding representations of the vocabulary, ρ v ∈ R L . The vector α dn is the context embedding. The context embedding is the sum of the context embedding vectors (α v for each word v) of the words surrounding w dn .

The Embedded Topic Model
The ETM is a topic model that uses embedding representations of both words and topics. It contains two notions of latent dimension. First, it embeds the vocabulary in an L-dimensional space. These embeddings are similar in spirit to classical word embeddings. Second, it represents each document in terms of K latent topics.
In traditional topic modeling, each topic is a full distribution over the vocabulary. In the ETM, however, the k th topic is a vector α k ∈ R L in the embedding space. We call α k a topic embedding-it is a distributed representation of the k th topic in the semantic space of words.
In its generative process, the ETM uses the topic embedding to form a per-topic distribution over the vocabulary. Specifically, the ETM uses a loglinear model that takes the inner product of the word embedding matrix and the topic embedding. With this form, the ETM assigns high probability to a word v in topic k by measuring the agreement between the word's embedding and the topic's embedding.
Denote the L × V word embedding matrix by ρ; the column ρ v is the embedding of v. Under the ETM, the generative process of the d th document is the following: In Step 1, LN (·) denotes the logistic-normal distribution (Aitchison and Shen, 1980;Blei and Lafferty, 2007); it transforms a standard Gaussian random variable to the simplex. A draw θ d from this distribution is obtained as (We replaced the Dirichlet with the logistic normal to more easily use reparameterization in the inference algorithm; see Section 5.) Steps 1 and 2a are standard for topic modeling: they represent documents as distributions over topics and draw a topic assignment for each observed word. Step 2b is different; it uses the embeddings of the vocabulary ρ and the assigned topic embedding α z dn to draw the observed word from the assigned topic, as given by z dn .
The topic distribution in Step 2b mirrors the CBOW likelihood in Eq. 1. Recall CBOW uses the surrounding words to form the context vector α dn . In contrast, the ETM uses the topic embedding α z dn as the context vector, where the assigned topic z dn is drawn from the per-document variable θ d . The ETM draws its words from a document context, rather than from a window of surrounding words.
The ETM likelihood uses a matrix of word embeddings ρ, a representation of the vocabulary in a lower dimensional space. In practice, it can either rely on previously fitted embeddings or learn them as part of its overall fitting procedure. When the ETM learns the embeddings as part of the fitting procedure, it simultaneously finds topics and an embedding space.
When the ETM uses previously fitted embeddings, it learns the topics of a corpus in a particular embedding space. This strategy is particularly useful when there are words in the embedding that are not used in the corpus. The ETM can hypothesize how those words fit in to the topics because it can calculate ρ v α k , even for words v that do not appear in the corpus.

Inference and Estimation
We are given a corpus of documents {w 1 , . . . , w D }, where w d is a collection of N d words. How do we fit the ETM?
The marginal likelihood. The parameters of the ETM are the embeddings ρ 1:V and the topic embeddings α 1:K ; each α k is a point in the embedding space. We maximize the marginal likelihood of the documents, The problem is that the marginal likelihood of each document is intractable to compute. It involves a difficult integral over the topic proportions, which we write in terms of the untransformed proportions δ d in Eq. 2, The conditional distribution of each word marginalizes out the topic assignment z dn , Here, θ dk denotes the (transformed) topic proportions (Eq. 2) and β kv denotes a traditional "topic," i.e., a distribution over words, induced by the word embeddings ρ and the topic embedding α k , Eqs. 4 to 6 flesh out the likelihood in Eq. 3.

Variational inference.
We sidestep the intractable integral with variational inference (Jordan et al., 1999;Blei et al., 2017). Variational inference optimizes a sum of per-document bounds on the log of the marginal likelihood of Eq. 4. There are two sets of parameters to optimize: the model parameters, as described above, and the variational parameters, which tighten the bounds on the marginal likelihoods.
To begin, posit a family of distributions of the untransformed topic proportions q(δ d ; w d , ν). We use amortized inference, where the variational distribution of δ d depends on both the document w d and shared variational parameters ν. In particular q(δ d ; w d , ν) is a Gaussian whose mean and variance come from an "inference network," a neural network parameterized by ν (Kingma and Welling, 2014). The inference network ingests the document w d and outputs a mean and variance of δ d . (To accommodate documents of varying length, we form the input of the inference network by normalizing the bag-of-word representation of the document by the number of words N d .) We use this family of variational distributions to bound the log-marginal likelihood. The evidence lower bound (ELBO) is a function of the model parameters and the variational parameters, KL(q(δ d ; w d , ν) || p(δ d )). (7) As a function of the variational parameters, the first term encourages them to place mass on topic proportions δ d that explain the observed words; the second term encourages them to be close to the prior p(δ d ). As a function of the model parameters, this objective maximizes the expected complete log-likelihood, We optimize the ELBO with respect to both the model parameters and the variational parameters. We use stochastic optimization, forming noisy gradients by taking Monte Carlo approximations of the full gradient through the reparameterization trick (Kingma and Welling, 2014;Titsias and Lázaro-Gredilla, 2014;Rezende et al., 2014). We also use data subsampling to handle large collections of documents (Hoffman et al., 2013). We set the learning rate with Adam (Kingma and Ba, 2015). The procedure is shown in Algorithm 1, where the notation NN(x ; ν) represents a neural network with input x and parameters ν.
Algorithm 1 Topic modeling with the ETM Initialize model and variational parameters for iteration i = 1, 2, . . . do Compute β k = softmax(ρ α k ) for each topic k Choose a minibatch B of documents for each word in the document do Compute p(w dn | θ d ) = θ d β ·,w dn end for end for Estimate the ELBO and its gradient (backprop.) Update model parameters α 1:K Update variational parameters (ν µ , ν Σ ) end for

Empirical Study
We study the performance of the ETM and compare it to other unsupervised document models. A good document model should provide both coherent patterns of language and an accurate distribution of words, so we measure performance in terms of both predictive accuracy and topic interpretability. We measure accuracy with loglikelihood on a document completion task (Rosen-Zvi et al., 2004;Wallach et al., 2009); we measure topic interpretability as a blend of topic coherence and diversity. We find that, of the interpretable models, the ETM is the one that provides better predictions and topics.
In a separate analysis (Section 6.1), we study the robustness of each method in the presence of stop words. Standard topic models fail in this regime-since stop words appear in many documents, every learned topic includes some stop words, leading to poor topic interpretability. In contrast, the ETM is able to use the information from the word embeddings to provide interpretable topics. 2 Corpora. We study the 20Newsgroups corpus and the New York Times corpus.
The 20Newsgroup corpus is a collection of newsgroup posts. We preprocess the corpus by filtering stop words, words with document frequency above 70%, and tokenizing. To form the vocabu-lary, we keep all words that appear in more than a certain number of documents, and we vary the threshold from 100 (a smaller vocabulary, where V = 3,102) to 2 (a larger vocabulary, where V = 52,258). After preprocessing, we further remove one-word documents from the validation and test sets. We split the corpus into a training set of 11,260 documents, a test set of 7,532 documents, and a validation set of 100 documents.
The New York Times corpus is a larger collection of news articles. It contains more than 1.8 million articles, spanning the years 1987-2007. We follow the same preprocessing steps as for 20Newsgroups. We form versions of this corpus with vocabularies ranging from V = 5,921 to V = 212,237. After preprocessing, we use 85% of the documents for training, 10% for testing, and 5% for validation.

Models.
We compare the performance of the ETM with two other document models: latent Dirichlet allocation (LDA) and the neural variational document model (NVDM).
LDA (Blei et al., 2003) is a standard topic model that posits Dirichlet priors for the topics β k and topic proportions θ d . (We set the prior hyperparameters to 1.) It is a conditionally conjugate model, amenable to variational inference with coordinate ascent. We consider LDA because it is the most commonly used topic model, and it has a similar generative process as the ETM.
The NVDM (Miao et al., 2016) is a multinomial factor model of documents; it posits the likelihood w dn ∼ softmax(β θ d ), where the K-dimensional vector θ d ∼ N (0, I K ) is a per-document variable, and β is a real-valued matrix of size K × V . The NVDM uses a per-document real-valued latent vector θ d to average over the embedding matrix β in the logit space. Like the ETM, the NVDM uses amortized variational inference to jointly learn the approximate posterior over the document representation θ d and the model parameter β. NVDM is not interpretable as a topic model; its latent variables are unconstrained. We study a more interpretable variant of the NVDM which constrains θ d to lie in the simplex, replacing its Gaussian prior with a logistic normal (Aitchison and Shen, 1980). (This can be thought of as a semi-nonnegative matrix factorization.) We call this document model ∆-NVDM. We study two variants of the ETM, one where the word embeddings are pre-fitted and one where they are learned jointly with the rest of the parameters. The variant with pre-fitted embeddings is called the "labeled ETM." We use skip-gram embeddings (Mikolov et al., 2013b).
Algorithm settings. Given a corpus, each model comes with an approximate posterior inference problem. We use variational inference for all of the models and employ stochastic variational inference (SVI) (Hoffman et al., 2013) to speed up the optimization. The minibatch size is 1,000 documents. For LDA, we set the learning rate as suggested by Hoffman et al. (2013): the delay is 10 and the forgetting factor is 0.85.
Within SVI, LDA enjoys coordinate ascent variational updates, with 5 inner steps to optimize the local variables. For the other models, we use amortized inference over the local variables θ d . We use 3-layer inference networks and we set the local learning rate to 0.002. We use 2 regularization on the variational parameters (the weight decay parameter is 1.2 × 10 −6 ).
Qualitative results. We first examine the embeddings. The ETM, NVDM, and ∆-NVDM all involve a word embedding. We illustrate them by fixing a set of terms and calculating the words that occur in the neighborhood around them. For comparison, we also illustrate word embeddings learned by the skip-gram model. Table 1 illustrates the embeddings of the different models. All the methods provide interpretable embeddings-words with related meanings are close to each other. The ETM and the NVDM learn embeddings that are similar to those from the skipgram. The embeddings of ∆-NVDM are different; the simplex constraint on the local variable changes the nature of the embeddings.
We next look at the learned topics. Table 2 displays the 7 most used topics for all methods, as given by the average of the topic proportions θ d . LDA and the ETM both provide interpretable topics. Neither NVDM nor ∆-NVDM provide interpretable topics; their model parameters β are not interpretable as distributions over the vocabulary that mix to form documents.
Quantitative results. We next study the models quantitatively. We measure the quality of the topics and the predictive performance of the model. We found that among models with interpretable topics, the ETM provides the best predictions.
We measure topic quality by blending two metrics: topic coherence and topic diversity. Topic coherence is a quantitative measure of the interpretability of a topic (Mimno et al., 2011). It is the average pointwise mutual information of two words drawn randomly from the same document (Lau et al., 2014), 10 } denotes the top-10 most likely words in topic k. Here, f (·, ·) is the normalized pointwise mutual information, The quantity P (w i , w j ) is the probability of words w i and w j co-occurring in a document and P (w i ) is the marginal probability of word w i . We approximate these probabilities with empirical counts.
The idea behind topic coherence is that a coherent topic will display words that tend to occur in the same documents. In other words, the most likely words in a coherent topic should have high mutual information. Document models with higher topic coherence are more interpretable topic models.
We combine coherence with a second metric, topic diversity. We define topic diversity to be the percentage of unique words in the top 25 words of all topics. Diversity close to 0 indicates redundant topics; diversity close to 1 indicates more varied topics. We define the overall metric for the quality of a model's topics as the product of its topic diversity and topic coherence. A good topic model also provides a good distribution of language. To measure predictive quality, (a) Topic quality as measured by normalized product of topic coherence and topic diversity (the higher the better) vs. predictive performance as measured by normalized log-likelihood on document completion (the higher the better) on the 20NewsGroup dataset. (b) Topic quality as measured by normalized product of topic coherence and topic diversity (the higher the better) vs. predictive performance as measured by normalized log-likelihood on document completion (the higher the better) on the New York Times dataset. we calculate log likelihood on a document completion task (Rosen-Zvi et al., 2004;Wallach et al., 2009). We divide each test document into two sets of words. The first half is observed: it induces a distribution over topics which, in turn, induces a distribution over the next words in the document. We then evaluate the second half under this distribution. A good document model should provide higher log-likelihood on the second half. (For all methods, we approximate the likelihood by setting θ d to the variational mean.) We study both corpora and with different vocabularies. Figure 4 shows topic quality as a function of predictive power. (To ease visualization, we normalize both metrics by subtracting the mean and dividing by the standard deviation.) The best models are on the upper right corner. LDA predicts worst in almost all settings. On 20NewsGroups, the NVDM's predictions are in general better than LDA but worse than for the other methods; on the New York Times, the NVDM gives the best predictions. However, topic quality for the NVDM is far below the other methods. (It does not provide "topics", so we assess the interpretability of its β matrix.) In prediction, both versions of the ETM are at least as good as the simplex-constrained ∆-NVDM.
These figures show that, of the interpretable models, the ETM provides the best predictive performance while keeping interpretable topics. It is robust to large vocabularies.

Stop words
We now study a version of the New York Times corpus that includes all stop words. We remove infre- Our goal is to show that the labeled ETM provides interpretable topics even in the presence of stop words, another regime where topic models typically fail. In particular, given that stop words appear in many documents, traditional topic models learn topics that contain stop words, regardless of the actual semantics of the topic. This leads to poor topic interpretability.
We fit LDA, the ∆-NVDM, and the labeled ETM with K = 300 topics. (We do not report the NVDM because it does not provide interpretable topics.) Table 3 shows topic quality (the product of topic coherence and topic diversity). Overall, the labeled ETM gives the best performance in terms of topic quality.
While the ETM has a few "stop topics" that are specific for stop words (see, e.g., Figure 5), ∆-NVDM and LDA have stop words in almost every topic. (The topics are not displayed here for space constraints.) The reason is that stop words cooccur in the same documents as every other word; therefore traditional topic models have difficulties telling apart content words and stop words. The labeled ETM recognizes the location of stop words in the embedding space; its sets them off on their own topic.

Conclusion
We developed the ETM, a generative model of documents that marries LDA with word embeddings. The ETM assumes that topics and words live in the same embedding space, and that words are generated from a categorical distribu- tion whose natural parameter is the inner product of the word embeddings and the embedding of the assigned topic.
The ETM learns interpretable word embeddings and topics, even in corpora with large vocabularies. We studied the performance of the ETM against several document models. The ETM learns both coherent patterns of language and an accurate distribution of words.