Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents...

12
Topic Modeling in Embedding Spaces Adji B. Dieng Columbia University [email protected] Francisco J. R. Ruiz Columbia University Cambridge University [email protected] David M. Blei Columbia University [email protected] Abstract Topic modeling analyzes documents to learn meaningful patterns of words. How- ever, existing topic models fail to learn inter- pretable 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 mar- ries traditional topic models with word em- beddings. In particular, it models each word with a categorical distribution whose natu- ral 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 in- clude rare words and stop words. It out- performs existing document models, such as latent Dirichlet allocation, in terms of both topic quality and predictive performance. 1 1 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, polit- ical science, and the digital humanities. Boyd- Graber et al. (2017) provide a review. Most topic models build on latent Dirichlet al- location (LDA)(Blei et al., 2003). LDA is a hi- erarchical 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 varia- tional inference and stochastic optimization (Hoff- man et al., 2010, 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 vocabular- ies. Practitioners must severely prune their vocab- ularies 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 fre- quent 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 Ben- gio et al. (2003), published in the same year and journal as Blei et al. (2003). Word embeddings eschew the “one-hot” representation of words— a vocabulary-length vector of zeros with a sin- gle 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 be- yond 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 mod- els and the good properties of word embeddings. arXiv:1907.04907v1 [cs.IR] 8 Jul 2019

Transcript of Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents...

Page 1: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

Topic Modeling in Embedding Spaces

Adji B. DiengColumbia University

[email protected]

Francisco J. R. RuizColumbia UniversityCambridge [email protected]

David M. BleiColumbia University

[email protected]

Abstract

Topic modeling analyzes documents tolearn meaningful patterns of words. How-ever, existing topic models fail to learn inter-pretable topics when working with large andheavy-tailed vocabularies. To this end, wedevelop the embedded topic model (ETM),a generative model of documents that mar-ries traditional topic models with word em-beddings. In particular, it models each wordwith a categorical distribution whose natu-ral parameter is the inner product betweena word embedding and an embedding of itsassigned topic. To fit the ETM, we developan efficient amortized variational inferencealgorithm. The ETM discovers interpretabletopics even with large vocabularies that in-clude rare words and stop words. It out-performs existing document models, such aslatent Dirichlet allocation, in terms of bothtopic quality and predictive performance.1

1 Introduction

Topic models are statistical tools for discoveringthe hidden semantic structure in a collection ofdocuments (Blei et al., 2003; Blei, 2012). Topicmodels and their extensions have been applied tomany fields, such as marketing, sociology, polit-ical science, and the digital humanities. Boyd-Graber et al. (2017) provide a review.

Most topic models build on latent Dirichlet al-location (LDA) (Blei et al., 2003). LDA is a hi-erarchical probabilistic model that represents eachtopic as a distribution over terms and representseach document as a mixture of the topics. When fitto a collection of documents, the topics summarizetheir contents, and the topic proportions provide alow-dimensional representation of each one. LDA

1Code for this work can be found at https://github.com/adjidieng/ETM.

can be fit to large datasets of text by using varia-tional inference and stochastic optimization (Hoff-man et al., 2010, 2013).

LDA is a powerful model and it is widely used.However, it suffers from a pervasive technicalproblem—it fails in the face of large vocabular-ies. Practitioners must severely prune their vocab-ularies in order to fit good topic models, i.e., thosethat are both predictive and interpretable. This istypically done by removing the most and least fre-quent words. On large collections, this pruningmay remove important terms and limit the scope ofthe models. The problem of topic modeling withlarge vocabularies has yet to be addressed in theresearch literature.

In parallel with topic modeling came the idea ofword embeddings. Research in word embeddingsbegins with the neural language model of Ben-gio et al. (2003), published in the same year andjournal as Blei et al. (2003). Word embeddingseschew the “one-hot” representation of words—a vocabulary-length vector of zeros with a sin-gle one—to learn a distributed representation, onewhere words with similar meanings are close ina lower-dimensional vector space (Rumelhart andAbrahamson, 1973; Bengio et al., 2006). As fortopic models, researchers scaled up embeddingmethods to large datasets (Mikolov et al., 2013a,b;Pennington et al., 2014; Levy and Goldberg, 2014;Mnih and Kavukcuoglu, 2013). Word embeddingshave been extended and developed in many ways.They have become crucial in many applications ofnatural language processing (Li and Tao, 2018),and they have also been extended to datasets be-yond text (Rudolph et al., 2016).

In this paper, we develop the embedded topicmodel (ETM), a topic model for word embeddings.The ETM enjoys the good properties of topic mod-els and the good properties of word embeddings.

arX

iv:1

907.

0490

7v1

[cs

.IR

] 8

Jul

201

9

Page 2: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

1 2 3 4 5Vocabulary Size 1e4

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9Co

here

nce-

Norm

alize

d Pe

rple

xity

LDAETM

Figure 1. Ratio of the normalized held-out perplex-ity for document completion and the topic coher-ence as as a function of the vocabulary size for theETM and LDA. While the performance of LDAdeteriorates for large vocabularies, the ETM main-tains good performance.

As a topic model, it discovers an interpretable la-tent semantic structure of the texts; as a word em-bedding, it provides a low-dimensional represen-tation of the meaning of words. It robustly ac-commodates large vocabularies and the long tailof language data.

Figure 1 illustrates the advantages. This figureplots the ratio between the predictive perplexityof held-out documents and the topic coherence,as a function of the size of the vocabulary. (Theperplexity has been normalized by the vocabularysize.) This is for a corpus of 11.2K articles fromthe 20NewsGroup and for 100 topics. The red lineis LDA; its performance deteriorates as the vocab-ulary size increases—the predictive performanceand the quality of the topics get worse. The blueline is the ETM; it maintains good performance,even as the vocabulary size gets large.

Like LDA, the ETM is a generative probabilis-tic model: each document is a mixture of topicsand each observed word is assigned to a particulartopic. In contrast to LDA, the per-topic conditionalprobability of a term has a log-linear form thatinvolves a low-dimensional representation of thevocabulary. Each term is represented by an em-bedding; each topic is a point in that embeddingspace; and the topic’s distribution over terms isproportional to the exponentiated inner product ofthe 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 eachtopic’s embedding and its closest words; these top-ics are about Christianity and sports.

Due to the topic representation in terms of apoint in the embedding space, the ETM is also ro-bust to the presence of stop words, unlike mostcommon topic models. When stop words are in-cluded in the vocabulary, the ETM assigns topicsto the corresponding area of the embedding space(we demonstrate this in Section 6).

As for most topic models, the posterior of thetopic proportions is intractable to compute. Wederive an efficient algorithm for approximating theposterior with variational inference (Jordan et al.,1999; Hoffman et al., 2013; Blei et al., 2017) andadditionally use amortized inference to efficientlyapproximate the topic proportions (Kingma andWelling, 2014; Rezende et al., 2014). The result-ing algorithm fits the ETM to large corpora withlarge vocabularies. The algorithm for the ETM caneither use previously fitted word embeddings, or fitthem jointly with the rest of parameters. (In partic-ular, Figures 1 to 3 were obtained with the versionof the ETM that obtains pre-fitted skip-gram wordembeddings.)

We compared the performance of the ETM toLDA and the neural variational document model(NVDM), a form of multinomial matrix factoriza-tion. The ETM provides good predictive perfor-mance, as measured by held-out log-likelihood ona document completion task (Wallach et al., 2009).It also provides meaningful topics, as measured bytopic coherence (Mimno et al., 2011) and topic di-versity, a metric that also indicates the quality ofthe topics. The ETM is especially robust to largevocabularies.

2 Related Work

This work develops a new topic model that extendsLDA. LDA has been extended in many ways, andtopic modeling has become a subfield of its own.For a review, see Blei (2012) and Boyd-Graberet al. (2017).

One of the goals in developing the ETM is toincorporate word similarity into the topic model,and there is previous research that shares this goal.These methods either modify the topic priors (Pet-terson et al., 2010; Zhao et al., 2017b; Shi et al.,

Page 3: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

pope

bishop

jesuschrist

presbyterian

cathedral

prayer

episcopal

churches

priest

romancatholic

god

rev

churchTopic 23

Figure 2. A topic about Christianity found bythe ETM on The New York Times. The topic isa point in the word embedding space.

finals

athletetrainer

leaguessquad

coaching

franchise

championships

athletes

soccer

teammates

playoff

coaches racing

playoffs

hockey

athletic

tournament

sport

seasons

championship

basketballfootball

baseballteams

coach

sportsplayerplayers

league

gamesgame

season

team

Topic 72

Topic 136

Topic 244

Figure 3. Topics about sports found by theETM. Each topic is a point in the word em-bedding space.

2017; Zhao et al., 2017a) or the topic assignmentpriors (Xie et al., 2015). For example Pettersonet al. (2010) use a word similarity graph (as givenby a thesaurus) to bias LDA towards assigningsimilar words to similar topics. As another ex-ample, Xie et al. (2015) model the per-word topicassignments of LDA using a Markov random fieldto account for both the topic proportions and thetopic assignments of similar words. These meth-ods use word similarity as a type of “side informa-tion” about language; in contrast, the ETM directlymodels the similarity (via embeddings) in its gen-erative process of words.

Other work has extended LDA to directly in-volve word embeddings. One common strategyis to convert the discrete text into continuous ob-servations of embeddings, and then adapt LDA togenerate real-valued data (Das et al., 2015; Xunet al., 2016; Batmanghelich et al., 2016; Xun et al.,2017). With this strategy, topics are Gaussian dis-tributions with latent means and covariances, andthe likelihood over the embeddings is modeledwith a Gaussian (Das et al., 2015) or a Von-MisesFisher distribution (Batmanghelich et al., 2016).The ETM differs from these approaches in that it isa model of categorical data, one that goes throughthe embeddings matrix. Thus it does not requirepre-fitted embeddings and, indeed, can learn em-beddings as part of its inference process.

There have been a few other ways of combiningLDA and embeddings. Nguyen et al. (2015) mixthe likelihood defined by LDA with a log-linearmodel that uses pre-fitted word embeddings; Bunkand Krestel (2018) randomly replace words drawnfrom a topic with their embeddings drawn from aGaussian; and Xu et al. (2018) adopt a geometric

perspective, using Wasserstein distances to learntopics and word embeddings jointly.

Another thread of recent research improvestopic modeling inference through deep neural net-works (Srivastava and Sutton, 2017; Card et al.,2017; Cong et al., 2017; Zhang et al., 2018).Specifically, these methods reduce the dimen-sion of the text data through amortized infer-ence and the variational auto-encoder (Kingmaand Welling, 2014; Rezende et al., 2014). To per-form inference in the ETM, we also avail ourselvesof amortized inference methods (Gershman andGoodman, 2014).

Finally, as a document model, the ETM also re-lates to works that learn per-document represen-tations as part of an embedding model (Le andMikolov, 2014; Moody, 2016; Miao et al., 2016).In contrast to these works, the document variablesin the ETM are part of a larger probabilistic topicmodel.

3 Background

The ETM builds on two main ideas, LDA and wordembeddings. Consider a corpus of D documents,where the vocabulary contains V distinct terms.Let wdn ∈ {1, . . . , V } denote the nth word in thedth document.

Latent Dirichlet allocation. LDA is a proba-bilistic generative model of documents (Blei et al.,2003). It posits K topics β1:K , each of which isa distribution over the vocabulary. LDA assumeseach document comes from a mixture of topics,where the topics are shared across the corpus andthe mixture proportions are unique for each docu-ment. The generative process for each document

Page 4: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

is the following:

1. Draw topic proportion θd ∼ Dirichlet(αθ).2. For each word n in the document:

(a) Draw topic assignment zdn ∼ Cat(θd).(b) Draw word wdn ∼ Cat(βzdn).

Here, Cat(·) denotes the categorical distribution.LDA places a Dirichlet prior on the topics, βk ∼Dirichlet(αβ) for k = 1, . . . ,K. The concentra-tion parameters αβ and αθ of the Dirichlet distri-butions are fixed model hyperparameters.

Word embeddings. Word embeddings providemodels of language that use vector representationsof words (Rumelhart and Abrahamson, 1973; Ben-gio et al., 2003). The word representations are fit-ted to relate to meaning, in that words with similarmeanings will have representations that are close.(In embeddings, the “meaning” of a word comesfrom the contexts in which it is used.)

We focus on the continuous bag-of-words(CBOW) variant of word embeddings (Mikolovet al., 2013b). In CBOW, the likelihood of eachword wdn is

wdn ∼ softmax(ρ>αdn). (1)

The embedding matrix ρ is a L× V matrix whosecolumns contain the embedding representations ofthe vocabulary, ρv ∈ RL. The vector αdn is thecontext embedding. The context embedding is thesum of the context embedding vectors (αv for eachword v) of the words surrounding wdn.

4 The Embedded Topic Model

The ETM is a topic model that uses embeddingrepresentations of both words and topics. It con-tains two notions of latent dimension. First, it em-beds the vocabulary in an L-dimensional space.These embeddings are similar in spirit to classi-cal word embeddings. Second, it represents eachdocument in terms of K latent topics.

In traditional topic modeling, each topic is a fulldistribution over the vocabulary. In the ETM, how-ever, the kth topic is a vector αk ∈ RL in the em-bedding space. We call αk a topic embedding—itis a distributed representation of the kth topic inthe semantic space of words.

In its generative process, the ETM uses the topicembedding to form a per-topic distribution over

the vocabulary. Specifically, the ETM uses a log-linear model that takes the inner product of theword embedding matrix and the topic embedding.With this form, the ETM assigns high probabilityto a word v in topic k by measuring the agreementbetween the word’s embedding and the topic’s em-bedding.

Denote the L × V word embedding matrix byρ; the column ρv is the embedding of v. Under theETM, the generative process of the dth documentis the following:

1. Draw topic proportions θd ∼ LN (0, I).2. For each word n in the document:

a. Draw topic assignment zdn ∼ Cat(θd).b. Draw the word wdn ∼ softmax(ρ>αzdn).

In Step 1, LN (·) denotes the logistic-normal dis-tribution (Aitchison and Shen, 1980; Blei and Laf-ferty, 2007); it transforms a standard Gaussianrandom variable to the simplex. A draw θd fromthis distribution is obtained as

δd ∼ N (0, I) ; θd = softmax(δd). (2)

(We replaced the Dirichlet with the logistic nor-mal to more easily use reparameterization in theinference algorithm; see Section 5.)

Steps 1 and 2a are standard for topic mod-eling: they represent documents as distributionsover topics and draw a topic assignment for eachobserved word. Step 2b is different; it uses theembeddings of the vocabulary ρ and the assignedtopic embedding αzdn to draw the observed wordfrom the assigned topic, as given by zdn.

The topic distribution in Step 2b mirrors theCBOW likelihood in Eq. 1. Recall CBOW usesthe surrounding words to form the context vectorαdn. In contrast, the ETM uses the topic embed-ding αzdn as the context vector, where the assignedtopic zdn is drawn from the per-document variableθd. The ETM draws its words from a documentcontext, rather than from a window of surround-ing words.

The ETM likelihood uses a matrix of word em-beddings ρ, a representation of the vocabulary ina lower dimensional space. In practice, it can ei-ther rely on previously fitted embeddings or learnthem as part of its overall fitting procedure. Whenthe ETM learns the embeddings as part of the fit-ting procedure, it simultaneously finds topics andan embedding space.

Page 5: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

When the ETM uses previously fitted embed-dings, it learns the topics of a corpus in a particu-lar embedding space. This strategy is particularlyuseful when there are words in the embedding thatare not used in the corpus. The ETM can hypothe-size how those words fit in to the topics because itcan calculate ρ>v αk, even for words v that do notappear in the corpus.

5 Inference and Estimation

We are given a corpus of documents{w1, . . . ,wD}, where wd is a collection ofNd words. How do we fit the ETM?

The marginal likelihood. The parameters of theETM are the embeddings ρ1:V and the topic em-beddings α1:K ; each αk is a point in the embed-ding space. We maximize the marginal likelihoodof the documents,

L(α, ρ) =D∑d=1

log p(wd |α, ρ). (3)

The problem is that the marginal likelihood ofeach document is intractable to compute. It in-volves a difficult integral over the topic propor-tions, which we write in terms of the untrans-formed proportions δd in Eq. 2,

p(wd |α, ρ) =∫p(δd)

Nd∏n=1

p(wdn | δd, α, ρ) dδd.

(4)

The conditional distribution of each wordmarginalizes out the topic assignment zdn,

p(wdn | δd, α, ρ) =K∑k=1

θdkβk,wdn. (5)

Here, θdk denotes the (transformed) topic propor-tions (Eq. 2) and βkv denotes a traditional “topic,”i.e., a distribution over words, induced by the wordembeddings ρ and the topic embedding αk,

βkv = softmax(ρ>αk)∣∣v. (6)

Eqs. 4 to 6 flesh out the likelihood in Eq. 3.

Variational inference. We sidestep the in-tractable integral with variational inference (Jor-dan et al., 1999; Blei et al., 2017). Variational in-ference 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: themodel parameters, as described above, and thevariational parameters, which tighten the boundson the marginal likelihoods.

To begin, posit a family of distributions ofthe untransformed topic proportions q(δd ; wd, ν).We use amortized inference, where the variationaldistribution of δd depends on both the documentwd and shared variational parameters ν. In par-ticular q(δd ; wd, ν) is a Gaussian whose meanand variance come from an “inference network,”a neural network parameterized by ν (Kingma andWelling, 2014). The inference network ingests thedocument wd and outputs a mean and varianceof δd. (To accommodate documents of varyinglength, we form the input of the inference networkby normalizing the bag-of-word representation ofthe document by the number of words Nd.)

We use this family of variational distributions tobound the log-marginal likelihood. The evidencelower bound (ELBO) is a function of the modelparameters and the variational parameters,

L(α, ρ, ν) =D∑d=1

Nd∑n=1

Eq [log p(wnd | δd, ρ, α)]

−D∑d=1

KL(q(δd;wd, ν) || p(δd)). (7)

As a function of the variational parameters,the first term encourages them to place masson topic proportions δd that explain the ob-served words; the second term encourages themto be close to the prior p(δd). As a func-tion of the model parameters, this objectivemaximizes the expected complete log-likelihood,∑

d log p(δd,wd |α, ρ).

We optimize the ELBO with respect to boththe model parameters and the variational param-eters. We use stochastic optimization, formingnoisy gradients by taking Monte Carlo approxima-tions of the full gradient through the reparameter-ization trick (Kingma and Welling, 2014; Titsiasand Lázaro-Gredilla, 2014; Rezende et al., 2014).We also use data subsampling to handle large col-lections of documents (Hoffman et al., 2013). Weset the learning rate with Adam (Kingma and Ba,2015). The procedure is shown in Algorithm 1,where the notation NN(x ; ν) represents a neuralnetwork with input x and parameters ν.

Page 6: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

Algorithm 1 Topic modeling with the ETM

Initialize model and variational parametersfor iteration i = 1, 2, . . . do

Compute βk = softmax(ρ>αk) for each topic kChoose a minibatch B of documentsfor each document d in B do

Get normalized bag-of-word representat. xdCompute µd = NN(xd ; νµ)Compute Σd = NN(xd ; νΣ)Sample θd ∼ LN (µd, Σd)for each word in the document do

Compute p(wdn | θd) = θ>d β·,wdn

end forend forEstimate the ELBO and its gradient (backprop.)Update model parameters α1:K

Update variational parameters (νµ, νΣ)end for

6 Empirical Study

We study the performance of the ETM and com-pare it to other unsupervised document models.A good document model should provide both co-herent patterns of language and an accurate dis-tribution of words, so we measure performancein terms of both predictive accuracy and topicinterpretability. We measure accuracy with log-likelihood on a document completion task (Rosen-Zvi et al., 2004; Wallach et al., 2009); we measuretopic interpretability as a blend of topic coherenceand diversity. We find that, of the interpretablemodels, the ETM is the one that provides betterpredictions and topics.

In a separate analysis (Section 6.1), we studythe robustness of each method in the presence ofstop words. Standard topic models fail in thisregime—since stop words appear in many doc-uments, every learned topic includes some stopwords, leading to poor topic interpretability. Incontrast, the ETM is able to use the informa-tion from the word embeddings to provide inter-pretable topics.2

Corpora. We study the 20Newsgroups corpusand the New York Times corpus.

The 20Newsgroup corpus is a collection ofnewsgroup posts. We preprocess the corpus by fil-tering stop words, words with document frequencyabove 70%, and tokenizing. To form the vocabu-

2Code is available upon request and will be released afterpublication.

lary, we keep all words that appear in more thana certain number of documents, and we vary thethreshold from 100 (a smaller vocabulary, whereV = 3,102) to 2 (a larger vocabulary, where V =52,258). After preprocessing, we further removeone-word documents from the validation and testsets. We split the corpus into a training set of11,260 documents, a test set of 7,532 documents,and a validation set of 100 documents.

The New York Times corpus is a larger collec-tion of news articles. It contains more than 1.8million articles, spanning the years 1987–2007.We follow the same preprocessing steps as for20Newsgroups. We form versions of this corpuswith vocabularies ranging from V = 5,921 toV = 212,237. After preprocessing, we use 85%of the documents for training, 10% for testing, and5% for validation.

Models. We compare the performance of theETM with two other document models: latentDirichlet allocation (LDA) and the neural varia-tional document model (NVDM).

LDA (Blei et al., 2003) is a standard topic modelthat posits Dirichlet priors for the topics βk andtopic proportions θd. (We set the prior hyper-parameters to 1.) It is a conditionally conjugatemodel, amenable to variational inference with co-ordinate ascent. We consider LDA because it isthe most commonly used topic model, and it has asimilar generative process as the ETM.

The NVDM (Miao et al., 2016) is a multinomialfactor model of documents; it posits the likelihoodwdn ∼ softmax(β>θd), where the K-dimensionalvector θd ∼ N (0, IK) is a per-document vari-able, and β is a real-valued matrix of size K × V .The NVDM uses a per-document real-valued latentvector θd to average over the embedding matrix βin the logit space. Like the ETM, the NVDM usesamortized variational inference to jointly learn theapproximate posterior over the document repre-sentation θd and the model parameter β.

NVDM is not interpretable as a topic model;its latent variables are unconstrained. We studya more interpretable variant of the NVDM whichconstrains θd to lie in the simplex, replacing itsGaussian prior with a logistic normal (Aitchisonand Shen, 1980). (This can be thought of as asemi-nonnegative matrix factorization.) We callthis document model ∆-NVDM.

Page 7: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

Table 1. Word embeddings learned by all document models (and skip-gram) on the New York Times withvocabulary size 118,363.

Skip-gram embeddings ETM embeddings

love family woman politics love family woman politicsloved families man political joy children girl politicalpassion grandparents girl religion loves son boy politicianloves mother boy politicking loved mother mother ideologyaffection friends teenager ideology passion father daughter speechesadore relatives person partisanship wonderful wife pregnant ideological

NVDM embeddings ∆-NVDM embeddings

love family woman politics love family woman politicsloves sons girl political miss home life politicalpassion life women politician young father marriage faithwonderful brother man politicians born son women marriagejoy son pregnant politically dream day read politiciansbeautiful lived boyfriend democratic younger mrs young election

We study two variants of the ETM, one wherethe word embeddings are pre-fitted and one wherethey are learned jointly with the rest of the param-eters. The variant with pre-fitted embeddings iscalled the “labeled ETM.” We use skip-gram em-beddings (Mikolov et al., 2013b).

Algorithm settings. Given a corpus, each modelcomes with an approximate posterior inferenceproblem. We use variational inference for all ofthe models and employ stochastic variational in-ference (SVI) (Hoffman et al., 2013) to speed upthe optimization. The minibatch size is 1,000 doc-uments. For LDA, we set the learning rate as sug-gested by Hoffman et al. (2013): the delay is 10and the forgetting factor is 0.85.

Within SVI, LDA enjoys coordinate ascent vari-ational updates, with 5 inner steps to optimizethe local variables. For the other models, we useamortized inference over the local variables θd.We use 3-layer inference networks and we set thelocal learning rate to 0.002. We use `2 regular-ization on the variational parameters (the weightdecay parameter is 1.2× 10−6).

Qualitative results. We first examine the embed-dings. The ETM, NVDM, and ∆-NVDM all in-volve a word embedding. We illustrate them byfixing a set of terms and calculating the wordsthat occur in the neighborhood around them. Forcomparison, we also illustrate word embeddings

learned by the skip-gram model.

Table 1 illustrates the embeddings of the differ-ent models. All the methods provide interpretableembeddings—words with related meanings areclose to each other. The ETM and the NVDM learnembeddings that are similar to those from the skip-gram. The embeddings of ∆-NVDM are differ-ent; the simplex constraint on the local variablechanges the nature of the embeddings.

We next look at the learned topics. Table 2 dis-plays the 7 most used topics for all methods, asgiven by the average of the topic proportions θd.LDA and the ETM both provide interpretable top-ics. Neither NVDM nor ∆-NVDM provide inter-pretable topics; their model parameters β are notinterpretable as distributions over the vocabularythat mix to form documents.

Quantitative results. We next study the mod-els quantitatively. We measure the quality ofthe topics and the predictive performance of themodel. We found that among models with inter-pretable topics, the ETM provides the best predic-tions.

We measure topic quality by blending two met-rics: topic coherence and topic diversity. Topiccoherence is a quantitative measure of the inter-pretability of a topic (Mimno et al., 2011). It isthe average pointwise mutual information of two

Page 8: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

Table 2. Top five words of seven most used topics from different document models on 1.8M documentsof the New York Times corpus with vocabulary size 212,237 and K = 300 topics.

LDAtime year officials mr city percent stateday million public president building million republicanback money department bush street company partygood pay report white park year billlong tax state clinton house billion mr

NVDMscholars japan gansler spratt assn ridership prycegingrich tokyo wellstone tabitha assoc mtv mickensfunds pacific mccain mccorkle qtr straphangers mckechnieinstitutions europe shalikashvili cheetos yr freierman mfumeendowment zealand coached vols nyse riders filkins

∆-NVDMconcerto servings nato innings treas patients democratssolos tablespoons soviet scored yr doctors republicanssonata tablespoon iraqi inning qtr medicare republicanmelodies preheat gorbachev shutout outst dr senatesoloist minced arab scoreless telerate physicians dole

Labeled ETMmusic republican yankees game wine court companydance bush game points restaurant judge millionsongs campaign baseball season food case stockopera senator season team dishes justice sharesconcert democrats mets play restaurants trial billion

ETMgame music united wine company yankees artteam mr israel food stock game museumseason dance government sauce million baseball showcoach opera israeli minutes companies mets workplay band mr restaurant billion season artist

words drawn randomly from the same document(Lau et al., 2014),

TC =1

K

K∑k=1

1

45

10∑i=1

10∑j=i+1

f(w(k)i , w

(k)j ),

where {w(k)1 , . . . , w

(k)10 } denotes the top-10 most

likely words in topic k. Here, f(·, ·) is the normal-ized pointwise mutual information,

f(wi, wj) =log

P (wi,wj)P (wi)P (wj)

− logP (wi, wj).

The quantity P (wi, wj) is the probability of wordswi and wj co-occurring in a document and P (wi)is the marginal probability of word wi. Weapproximate these probabilities with empiricalcounts.

The idea behind topic coherence is that a co-herent topic will display words that tend to oc-cur in the same documents. In other words,the most likely words in a coherent topic shouldhave high mutual information. Document modelswith higher topic coherence are more interpretabletopic models.

We combine coherence with a second metric,topic diversity. We define topic diversity to be thepercentage of unique words in the top 25 words ofall topics. Diversity close to 0 indicates redundanttopics; diversity close to 1 indicates more variedtopics. We define the overall metric for the qual-ity of a model’s topics as the product of its topicdiversity and topic coherence.

A good topic model also provides a good distri-bution of language. To measure predictive quality,

Page 9: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

1 0 1Predictive Power

1.5

1.0

0.5

0.0

0.5

1.0

1.5

Inte

rpre

tabi

lity

V=3102LDANVDM

-NVDMLabeled ETMETM

V=8496 V=18625 V=29461 V=52258

(a) Topic quality as measured by normalized product of topic coherence and topic diversity (the higher the better) vs. predictiveperformance as measured by normalized log-likelihood on document completion (the higher the better) on the 20NewsGroupdataset.

1 0 1Predictive Power

1.5

1.0

0.5

0.0

0.5

1.0

1.5

Inte

rpre

tabi

lity

V=9842

LDANVDM

-NVDMLabeled ETMETM(LE)

V=55627 V=74095 V=124725 V=212237

(b) Topic quality as measured by normalized product of topic coherence and topic diversity (the higher the better) vs. predictiveperformance as measured by normalized log-likelihood on document completion (the higher the better) on the New York Timesdataset.

Figure 4. Performance on the 20NewsGroups and the New York Times datasets for different vocabularysizes. On both plots, better models are on the top right corner. Overall, the ETM is a better topic model.

we calculate log likelihood on a document com-pletion task (Rosen-Zvi et al., 2004; Wallach et al.,2009). We divide each test document into two setsof words. The first half is observed: it induces adistribution over topics which, in turn, induces adistribution over the next words in the document.We then evaluate the second half under this distri-bution. A good document model should providehigher log-likelihood on the second half. (For allmethods, we approximate the likelihood by settingθd to the variational mean.)

We study both corpora and with different vocab-ularies. Figure 4 shows topic quality as a functionof predictive power. (To ease visualization, wenormalize both metrics by subtracting the meanand dividing by the standard deviation.) The bestmodels are on the upper right corner.

LDA predicts worst in almost all settings. On

20NewsGroups, the NVDM’s predictions are ingeneral better than LDA but worse than for theother methods; on the New York Times, the NVDMgives the best predictions. However, topic qual-ity for the NVDM is far below the other methods.(It does not provide “topics”, so we assess the in-terpretability of its β matrix.) In prediction, bothversions of the ETM are at least as good as thesimplex-constrained ∆-NVDM.

These figures show that, of the interpretablemodels, the ETM provides the best predictive per-formance while keeping interpretable topics. It isrobust to large vocabularies.

6.1 Stop words

We now study a version of the New York Times cor-pus that includes all stop words. We remove infre-

Page 10: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

our

together

never

good

very

whyright

best

passing

always

can

us

going

finebetter

we

just

what

way

lot

how

Topic 181

Figure 5. A topic containing stop words found bythe ETM on The New York Times. The ETM isrobust even in the presence of stop words.

quent words to form a vocabulary of size 10,283.Our goal is to show that the labeled ETM providesinterpretable topics even in the presence of stopwords, another regime where topic models typi-cally fail. In particular, given that stop words ap-pear in many documents, traditional topic modelslearn topics that contain stop words, regardless ofthe actual semantics of the topic. This leads topoor topic interpretability.

We fit LDA, the∆-NVDM, and the labeled ETMwith K = 300 topics. (We do not report theNVDM because it does not provide interpretabletopics.) Table 3 shows topic quality (the product oftopic coherence and topic diversity). Overall, thelabeled ETM gives the best performance in termsof topic quality.

While the ETM has a few “stop topics” that arespecific for stop words (see, e.g., Figure 5), ∆-NVDM and LDA have stop words in almost everytopic. (The topics are not displayed here for spaceconstraints.) The reason is that stop words co-occur in the same documents as every other word;therefore traditional topic models have difficultiestelling apart content words and stop words. The la-beled ETM recognizes the location of stop wordsin the embedding space; its sets them off on theirown topic.

7 Conclusion

We developed the ETM, a generative model ofdocuments that marries LDA with word embed-dings. The ETM assumes that topics and wordslive in the same embedding space, and thatwords are generated from a categorical distribu-

Table 3. Topic quality on the New York Times datain the presence of stop words. Topic quality isthe product of topic coherence and topic diver-sity (higher is better). The labeled ETM is robustto stop words; it achieves similar topic coherencethan when there are no stop words.

Coherence Diversity Quality

LDA 0.13 0.14 0.0173∆-NVDM 0.17 0.11 0.0187

Labeled ETM 0.18 0.22 0.0405

tion whose natural parameter is the inner productof the word embeddings and the embedding of theassigned topic.

The ETM learns interpretable word embeddingsand topics, even in corpora with large vocabu-laries. We studied the performance of the ETMagainst several document models. The ETM learnsboth coherent patterns of language and an accuratedistribution of words.

Acknowledgments

This work is funded by ONR N00014-17-1-2131,NIH 1U01MH115727-01, DARPA SD2 FA8750-18-C-0130, ONR N00014-15-1-2209, NSF CCF-1740833, the Alfred P. Sloan Foundation, 2Sigma,Amazon, and NVIDIA. FJRR is funded by the Eu-ropean Union’s Horizon 2020 research and inno-vation programme under the Marie Skłodowska-Curie grant agreement No. 706760. ABD is sup-ported by a Google PhD Fellowship.

References

J. Aitchison and S. Shen. 1980. Logistic nor-mal distributions: Some properties and uses.Biometrika, 67(2):261–272.

K. Batmanghelich, A. Saeedi, K. Narasimhan,and S. Gershman. 2016. Nonparametric spher-ical topic modeling with word embeddings.In Proceedings of the conference. Associationfor Computational Linguistics. Meeting, vol-ume 2016, page 537. NIH Public Access.

Y. Bengio, R. Ducharme, P. Vincent, and C. Jan-vin. 2003. A neural probabilistic language

Page 11: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

model. Journal of Machine Learning Research,3:1137–1155.

Y. Bengio, H. Schwenk, J.-S. Senécal, F. Morin,and J.-L. Gauvain. 2006. Neural probabilisticlanguage models. In Innovations in MachineLearning, pages 137–186. Springer.

D. M. Blei. 2012. Probabilistic topic models.Communications of the ACM, 55(4):77–84.

D. M. Blei, A. Kucukelbir, and J. D. McAuliffe.2017. Variational inference: A review for statis-ticians. Journal of the American Statistical As-sociation, 112(518):859–877.

D. M. Blei and J. D. Lafferty. 2007. A correlatedtopic model of Science. The Annals of AppliedStatistics, 1(1):17–35.

D. M. Blei, A. Y. Ng, and M. I. Jordan. 2003.Latent dirichlet allocation. Journal of machineLearning research, 3(Jan):993–1022.

J. Boyd-Graber, Y. Hu, and D. Mimno. 2017. Ap-plications of topic models. Foundations andTrends in Information Retrieval, 11(2–3):143–296.

S. Bunk and R. Krestel. 2018. Welda: Enhanc-ing topic models by incorporating local wordcontext. In Proceedings of the 18th ACM/IEEEon Joint Conference on Digital Libraries, pages293–302. ACM.

D. Card, C. Tan, and N. A. Smith. 2017. A neu-ral framework for generalized topic models. InarXiv:1705.09296.

Y. Cong, B. Chen, H. Liu, and M. Zhou. 2017.Deep latent Dirichlet allocation with topic-layer-adaptive stochastic gradient RiemannianMCMC. In International Conference on Ma-chine Learning.

R. Das, M. Zaheer, and C. Dyer. 2015. Gaus-sian LDA for topic models with word embed-dings. In Association for Computational Lin-guistics and International Joint Conference onNatural Language Processing (Volume 1: LongPapers).

S. J. Gershman and N. D. Goodman. 2014. Amor-tized inference in probabilistic reasoning. InAnnual Meeting of the Cognitive Science Soci-ety.

M. D. Hoffman, D. M. Blei, and F. Bach. 2010.Online learning for latent Dirichlet allocation.In Advances in Neural Information ProcessingSystems.

M. D. Hoffman, D. M. Blei, C. Wang, andJ. Paisley. 2013. Stochastic variational infer-ence. Journal of Machine Learning Research,14:1303–1347.

M. I. Jordan, Z. Ghahramani, T. S. Jaakkola, andL. K. Saul. 1999. An introduction to variationalmethods for graphical models. Machine Learn-ing, 37(2):183–233.

D. P. Kingma and J. L. Ba. 2015. Adam: Amethod for stochastic optimization. In Interna-tional Conference on Learning Representations.

D. P. Kingma and M. Welling. 2014. Auto-encoding variational Bayes. In InternationalConference on Learning Representations.

J. H. Lau, D. Newman, and T. Baldwin. 2014. Ma-chine reading tea leaves: Automatically evalu-ating topic coherence and topic model quality.In Conference of the European Chapter of theAssociation for Computational Linguistics.

Q. Le and T. Mikolov. 2014. Distributed represen-tations of sentences and documents. In Interna-tional Conference on Machine Learning.

O. Levy and Y. Goldberg. 2014. Neural wordembedding as implicit matrix factorization. InNeural Information Processing Systems, pages2177–2185.

Y. Li and Y. Tao. 2018. Word Embedding forUnderstanding Natural Language: A Survey.Springer International Publishing.

Y. Miao, L. Yu, and P. Blunsom. 2016. Neuralvariational inference for text processing. In In-ternational Conference on Machine Learning.

T. Mikolov, K. Chen, G. Corrado, and J. Dean.2013a. Efficient estimation of word represen-tations in vector space. ICLR Workshop Pro-ceedings. arXiv:1301.3781.

T. Mikolov, I. Sutskever, K. Chen, G. S. Corrado,and J. Dean. 2013b. Distributed representationsof words and phrases and their compositional-ity. In Neural Information Processing Systems,pages 3111–3119.

Page 12: Topic Modeling in Embedding Spaces · the hidden semantic structure in a collection of documents (Blei et al.,2003;Blei,2012). Topic models and their extensions have been applied

D. Mimno, H. M. Wallach, E. Talley, M. Leenders,and A. McCallum. 2011. Optimizing semanticcoherence in topic models. In Conference onEmpirical Methods in Natural Language Pro-cessing.

A. Mnih and K. Kavukcuoglu. 2013. Learn-ing word embeddings efficiently with noise-contrastive estimation. In Neural InformationProcessing Systems, pages 2265–2273.

C. E. Moody. 2016. Mixing dirichlet topic modelsand word embeddings to make lda2vec. arXivpreprint arXiv:1605.02019.

D. Q. Nguyen, R. Billingsley, L. Du, and M. John-son. 2015. Improving topic models with latentfeature word representations. Transactions ofthe Association for Computational Linguistics,3:299–313.

J. Pennington, R. Socher, and C. D. Manning.2014. Glove: Global vectors for word repre-sentation. In Conference on Empirical Methodson Natural Language Processing, volume 14,pages 1532–1543.

J. Petterson, W. Buntine, S. M. Narayanamurthy,T. S. Caetano, and A. J. Smola. 2010. Wordfeatures for latent dirichlet allocation. In Ad-vances in Neural Information Processing Sys-tems, pages 1921–1929.

D. J. Rezende, S. Mohamed, and D. Wierstra.2014. Stochastic backpropagation and ap-proximate inference in deep generative models.arXiv preprint arXiv:1401.4082.

M. Rosen-Zvi, T. Griffiths, M. Steyvers, andP. Smyth. 2004. The author-topic model for au-thors and documents. In Uncertainty in Artifi-cial Intelligence.

M. Rudolph, F. J. R. Ruiz, S. Mandt, and D. M.Blei. 2016. Exponential family embeddings.In Advances in Neural Information ProcessingSystems.

D. Rumelhart and A. Abrahamson. 1973. A modelfor analogical reasoning. Cognitive Psychol-ogy, 5(1):1–28.

B. Shi, W. Lam, S. Jameel, S. Schockaert, andK. P. Lai. 2017. Jointly learning word embed-dings and latent topics. In Proceedings of the40th International ACM SIGIR Conference on

Research and Development in Information Re-trieval, pages 375–384. ACM.

A. Srivastava and C. Sutton. 2017. Autoencodingvariational inference for topic models. arXivpreprint arXiv:1703.01488.

M. K. Titsias and M. Lázaro-Gredilla. 2014.Doubly stochastic variational Bayes for non-conjugate inference. In International Confer-ence on Machine Learning.

H. M. Wallach, I. Murray, R. Salakhutdinov, andD. Mimno. 2009. Evaluation methods for topicmodels. In International Conference on Ma-chine Learning.

P. Xie, D. Yang, and E. Xing. 2015. Incorporatingword correlation knowledge into topic model-ing. In Proceedings of the 2015 conference ofthe north American chapter of the associationfor computational linguistics: human languagetechnologies, pages 725–734.

H. Xu, W. Wang, W. Liu, and L. Carin. 2018. Dis-tilled Wasserstein learning for word embeddingand topic modeling. In Advances in Neural In-formation Processing Systems.

G. Xun, V. Gopalakrishnan, F. Ma, Y. Li, J. Gao,and A. Zhang. 2016. Topic discovery for shorttexts using word embeddings. In 2016 IEEE16th international conference on data mining(ICDM), pages 1299–1304. IEEE.

G. Xun, Y. Li, W. X. Zhao, J. Gao, and A. Zhang.2017. A correlated topic model using word em-beddings. In IJCAI, pages 4207–4213.

H. Zhang, B. Chen, D. Guo, and M. Zhou. 2018.WHAI: Weibull hybrid autoencoding inferencefor deep topic modeling. In International Con-ference on Learning Representations.

H. Zhao, L. Du, and W. Buntine. 2017a. A wordembeddings informed focused topic model. InAsian Conference on Machine Learning, pages423–438.

H. Zhao, L. Du, W. Buntine, and G. Liu. 2017b.Metalda: A topic model that efficiently incor-porates meta information. In 2017 IEEE Inter-national Conference on Data Mining (ICDM),pages 635–644. IEEE.