Latent Dirichlet allocation

{{Short description|Probability model}}

{{distinguish|linear discriminant analysis}}

{{technical|date=August 2017}}

In natural language processing, latent Dirichlet allocation (LDA) is a Bayesian network (and, therefore, a generative statistical model) for modeling automatically extracted topics in textual corpora. The LDA is an example of a Bayesian topic model. In this, observations (e.g., words) are collected into documents, and each word's presence is attributable to one of the document's topics. Each document will contain a small number of topics.

History

In the context of population genetics, LDA was proposed by J. K. Pritchard, M. Stephens and P. Donnelly in 2000.{{cite journal

| last1 = Pritchard | first1 = J. K.

| last2 = Stephens | first2 = M.

| last3 = Donnelly | first3 = P.

| title = Inference of population structure using multilocus genotype data.

| journal = Genetics

| volume = 155

| issue = 2

| pages = pp. 945–959

| date = June 2000

| doi = 10.1093/genetics/155.2.945

| issn = 0016-6731

| url = http://genetics.org/content/155/2/945

| pmid = 10835412

| pmc = 1461096

}}{{cite journal

| last3 = Pritchard | first3 = J. K.

| last2 = Stephens | first2 = M.

| last1 = Falush | first1 = D.

| title = Inference of population structure using multilocus genotype data: linked loci and correlated allele frequencies.

| journal = Genetics

| volume = 164

| issue = 4

| pages = pp. 1567–1587

| date = 2003

| doi = 10.1093/genetics/164.4.1567

| pmid = 12930761

| pmc = 1462648}}

LDA was applied in machine learning by David Blei, Andrew Ng and Michael I. Jordan in 2003.{{cite journal

|last1 = Blei

|first1 = David M.

|last2 = Ng

|first2 = Andrew Y.

|last3 = Jordan

|first3 = Michael I

|authorlink3 = Michael I. Jordan

|title = Latent Dirichlet Allocation

|journal = Journal of Machine Learning Research

|date = January 2003

|volume = 3

|pages = pp. 993–1022

|url = http://jmlr.csail.mit.edu/papers/v3/blei03a.html

|doi = 10.1162/jmlr.2003.3.4-5.993

|editor1-last = Lafferty

|editor1-first = John

|issue = 4–5

|access-date = 2006-12-19

|archive-url = https://web.archive.org/web/20120501152722/http://jmlr.csail.mit.edu/papers/v3/blei03a.html

|archive-date = 2012-05-01

|url-status = dead

}}

Overview

= Population genetics =

In population genetics, the model is used to detect the presence of structured genetic variation in a group of individuals. The model assumes that alleles carried by individuals under study have origin in various extant or past populations. The model and various inference algorithms allow scientists to estimate the allele frequencies in those source populations and the origin of alleles carried by individuals under study. The source populations can be interpreted ex-post in terms of various evolutionary scenarios.

In association studies, detecting the presence of genetic structure is considered a necessary preliminary step to avoid confounding.

= Clinical psychology, mental health, and social science =

In clinical psychology research, LDA has been used to identify common themes of self-images experienced by young people in social situations.{{cite journal

|last1 = Chiu

|first1 = Kin

|last2 = Clark

|first2 = David

|last3 = Leigh

|first3 = Eleanor

|authorlink3 =

|title = Characterising Negative Mental Imagery in Adolescent Social Anxiety

|journal = Cognitive Therapy and Research

|date = July 2022

|volume = 46

|pages = 956–966

|doi = 10.1007/s10608-022-10316-x

|issue =5

|pmid = 36156987

|pmc = 9492563

}} Other social scientists have used LDA to examine large sets of topical data from discussions on social media (e.g., tweets about prescription drugs).{{Cite journal |last1=Parker |first1=Maria A. |last2=Valdez |first2=Danny |last3=Rao |first3=Varun K. |last4=Eddens |first4=Katherine S. |last5=Agley |first5=Jon |date=2023 |title=Results and Methodological Implications of the Digital Epidemiology of Prescription Drug References Among Twitter Users: Latent Dirichlet Allocation (LDA) Analyses |journal=Journal of Medical Internet Research |language=EN |volume=25 |issue=1 |pages=e48405 |doi=10.2196/48405|pmid=37505795 |pmc=10422173 |s2cid=260246078 |doi-access=free }}

Additionally, supervised Latent Dirichlet Allocation with covariates (SLDAX) has been specifically developed to combine latent topics identified in texts with other manifest variables. This approach allows for the integration of text data as predictors in statistical regression analyses, improving the accuracy of mental health predictions. One of the main advantages of SLDAX over traditional two-stage approaches is its ability to avoid biased estimates and incorrect standard errors, allowing for a more accurate analysis of psychological texts.Mcauliffe, J., & Blei, D. (2007). Supervised Topic Models. Advances in Neural Information Processing Systems, 20. https://proceedings.neurips.cc/paper/2007/hash/d56b9fc4b0f1be8871f5e1c40c0067e7-Abstract.html{{Cite journal |last1=Wilcox |first1=Kenneth Tyler |last2=Jacobucci |first2=Ross |last3=Zhang |first3=Zhiyong |last4=Ammerman |first4=Brooke A. |date=October 2023 |title=Supervised latent Dirichlet allocation with covariates: A Bayesian structural and measurement model of text and covariates. |url=https://doi.apa.org/doi/10.1037/met0000541 |journal=Psychological Methods |language=en |volume=28 |issue=5 |pages=1178–1206 |doi=10.1037/met0000541 |pmid=36603124 |issn=1939-1463}}

In the field of social sciences, LDA has proven to be useful for analyzing large datasets, such as social media discussions. For instance, researchers have used LDA to investigate tweets discussing socially relevant topics, like the use of prescription drugs and cultural differences in China.{{Cite journal |last=Guntuku |first=Sharath Chandra |last2=Talhelm |first2=Thomas |last3=Sherman |first3=Garrick |last4=Fan |first4=Angel |last5=Giorgi |first5=Salvatore |last6=Wei |first6=Liuqing |last7=Ungar |first7=Lyle H. |date=2024-12-24 |title=Historical patterns of rice farming explain modern-day language use in China and Japan more than modernization and urbanization |url=https://www.nature.com/articles/s41599-024-04053-7 |journal=Humanities and Social Sciences Communications |language=en |volume=11 |issue=1 |pages=1–21 |doi=10.1057/s41599-024-04053-7 |issn=2662-9992|arxiv=2308.15352 }} By analyzing these large text corpora, it is possible to uncover patterns and themes that might otherwise go unnoticed, offering valuable insights into public discourse and perception in real time.{{Cite journal |last1=Laureate |first1=Caitlin Doogan Poet |last2=Buntine |first2=Wray |last3=Linger |first3=Henry |date=2023-12-01 |title=A systematic review of the use of topic models for short text social media analysis |journal=Artificial Intelligence Review |language=en |volume=56 |issue=12 |pages=14223–14255 |doi=10.1007/s10462-023-10471-x |issn=1573-7462 |pmc=10150353 |pmid=37362887}}{{Cite journal |last1=Parker |first1=Maria A. |last2=Valdez |first2=Danny |last3=Rao |first3=Varun K. |last4=Eddens |first4=Katherine S. |last5=Agley |first5=Jon |date=2023-07-28 |title=Results and Methodological Implications of the Digital Epidemiology of Prescription Drug References Among Twitter Users: Latent Dirichlet Allocation (LDA) Analyses |journal=Journal of Medical Internet Research |language=EN |volume=25 |issue=1 |pages=e48405 |doi=10.2196/48405 |doi-access=free |pmc=10422173 |pmid=37505795}}

= Musicology =

In the context of computational musicology, LDA has been used to discover tonal structures in different corpora.{{cite journal

|last1 = Lieck

|first1 = Robert

|last2 = Moss

|first2 = Fabian C.

|last3 = Rohrmeier

|first3 = Martin

|authorlink3 = Lieck Robert

|title = The Tonal Diffusion Model

|journal = Transactions of the International Society for Music Information Retrieval

|date = October 2020

|volume = 3

|pages = pp. 153–164

|doi = 10.5334/tismir.46

|issue = 1

|s2cid = 225158478

|doi-access = free

}}

= Machine learning =

One application of LDA in machine learning - specifically, topic discovery, a subproblem in natural language processing – is to discover topics in a collection of documents, and then automatically classify any individual document within the collection in terms of how "relevant" it is to each of the discovered topics. A topic is considered to be a set of terms (i.e., individual words or phrases) that, taken together, suggest a shared theme.

For example, in a document collection related to pet animals, the terms dog, spaniel, beagle, golden retriever, puppy, bark, and woof would suggest a DOG_related theme, while the terms cat, siamese, Maine coon, tabby, manx, meow, purr, and kitten would suggest a CAT_related theme. There may be many more topics in the collection – e.g., related to diet, grooming, healthcare, behavior, etc. that we do not discuss for simplicity's sake. (Very common, so called stop words in a language – e.g., "the", "an", "that", "are", "is", etc., – would not discriminate between topics and are usually filtered out by pre-processing before LDA is performed. Pre-processing also converts terms to their "root" lexical forms – e.g., "barks", "barking", and "barked" would be converted to "bark".)

If the document collection is sufficiently large, LDA will discover such sets of terms (i.e., topics) based upon the co-occurrence of individual terms, though the task of assigning a meaningful label to an individual topic (i.e., that all the terms are DOG_related) is up to the user, and often requires specialized knowledge (e.g., for collection of technical documents). The LDA approach assumes that:

  1. The semantic content of a document is composed by combining one or more terms from one or more topics.
  2. Certain terms are ambiguous, belonging to more than one topic, with different probability. (For example, the term training can apply to both dogs and cats, but are more likely to refer to dogs, which are used as work animals or participate in obedience or skill competitions.) However, in a document, the accompanying presence of specific neighboring terms (which belong to only one topic) will disambiguate their usage.
  3. Most documents will contain only a relatively small number of topics. In the collection, e.g., individual topics will occur with differing frequencies. That is, they have a probability distribution, so that a given document is more likely to contain some topics than others.
  4. Within a topic, certain terms will be used much more frequently than others. In other words, the terms within a topic will also have their own probability distribution.

When LDA machine learning is employed, both sets of probabilities are computed during the training phase, using Bayesian methods and an Expectation Maximization algorithm.

LDA is a generalization of older approach of probabilistic latent semantic analysis (pLSA), The pLSA model is equivalent to LDA under a uniform Dirichlet prior distribution.{{cite conference

| last = Girolami

| first = Mark

| author2 = Kaban, A.

| title = On an Equivalence between PLSI and LDA

| url = https://archive.org/details/sigir2003proceed0000inte

| conference = Proceedings of SIGIR 2003

| publisher = Association for Computing Machinery

| location = New York

| year = 2003

| isbn = 1-58113-646-3

| url-access = registration

}}

pLSA relies on only the first two assumptions above and does not care about the remainder.

While both methods are similar in principle and require the user to specify the number of topics to be discovered before the start of training (as with K-means clustering) LDA has the following advantages over pLSA:

  • LDA yields better disambiguation of words and a more precise assignment of documents to topics.
  • Computing probabilities allows a "generative" process by which a collection of new “synthetic documents” can be generated that would closely reflect the statistical characteristics of the original collection.
  • Unlike LDA, pLSA is vulnerable to overfitting especially when the size of corpus increases.
  • The LDA algorithm is more readily amenable to scaling up for large data sets using the MapReduce approach on a computing cluster.

Model

Image:Latent Dirichlet allocation.svg representing the LDA model]] With plate notation, which is often used to represent probabilistic graphical models (PGMs), the dependencies among the many variables can be captured concisely. The boxes are "plates" representing replicates, which are repeated entities. The outer plate represents documents, while the inner plate represents the repeated word positions in a given document; each position is associated with a choice of topic and word. The variable names are defined as follows:

: M denotes the number of documents

: N is number of words in a given document (document i has N_i words)

: α is the parameter of the Dirichlet prior on the per-document topic distributions

: β is the parameter of the Dirichlet prior on the per-topic word distribution

: \theta_i is the topic distribution for document i

: \varphi_k is the word distribution for topic k

: z_{ij} is the topic for the j-th word in document i

: w_{ij} is the specific word.

File:Smoothed_LDA.png

The fact that W is grayed out means that words w_{ij} are the only observable variables, and the other variables are latent variables.

As proposed in the original paper, a sparse Dirichlet prior can be used to model the topic-word distribution, following the intuition that the probability distribution over words in a topic is skewed, so that only a small set of words have high probability. The resulting model is the most widely applied variant of LDA today. The plate notation for this model is shown on the right, where K denotes the number of topics and \varphi_1, \dots, \varphi_K are V-dimensional vectors storing the parameters of the Dirichlet-distributed topic-word distributions (V is the number of words in the vocabulary).

It is helpful to think of the entities represented by \theta and \varphi as matrices created by decomposing the original document-word matrix that represents the corpus of documents being modeled. In this view, \theta consists of rows defined by documents and columns defined by topics, while \varphi consists of rows defined by topics and columns defined by words. Thus, \varphi_1, \dots, \varphi_K refers to a set of rows, or vectors, each of which is a distribution over words, and \theta_1, \dots, \theta_Mrefers to a set of rows, each of which is a distribution over topics.

= Generative process =

To actually infer the topics in a corpus, we imagine a generative process whereby the documents are created, so that we may infer, or reverse engineer, it. We imagine the generative process as follows. Documents are represented as random mixtures over latent topics, where each topic is characterized by a distribution over all the words. LDA assumes the following generative process for a corpus D consisting of M documents each of length N_i:

1. Choose \theta_i \sim \operatorname{Dir}(\alpha) , where i \in \{ 1,\dots,M \} and

\mathrm{Dir}(\alpha) is a Dirichlet distribution with a symmetric parameter \alpha which typically is sparse (\alpha < 1)

2. Choose \varphi_k \sim \operatorname{Dir}(\beta) , where k \in \{ 1,\dots,K \} and \beta typically is sparse

3. For each of the word positions i, j, where i \in \{ 1,\dots,M \} , and j \in \{ 1,\dots,N_i \}

: (a) Choose a topic z_{i,j} \sim\operatorname{Multinomial}(\theta_i).

: (b) Choose a word w_{i,j} \sim\operatorname{Multinomial}( \varphi_{z_{i,j}}).

(Note that multinomial distribution here refers to the multinomial with only one trial, which is also known as the categorical distribution.)

The lengths N_i are treated as independent of all the other data generating variables (w and z). The subscript is often dropped, as in the plate diagrams shown here.

=Definition=

A formal description of LDA is as follows:

class="wikitable"

|+Definition of variables in the model

! Variable !! Type !! Meaning

Kintegernumber of topics (e.g. 50)
Vintegernumber of words in the vocabulary (e.g. 50,000 or 1,000,000)
Mintegernumber of documents
N_{d=1 \dots M}integernumber of words in document d
Nintegertotal number of words in all documents; sum of all N_d values, i.e. N = \sum_{d=1}^{M} N_d
\alpha_{k=1 \dots K}positive realprior weight of topic k in a document; usually the same for all topics; normally a number less than 1, e.g. 0.1, to prefer sparse topic distributions, i.e. few topics per document
\boldsymbol\alphaK-dimensional vector of positive realscollection of all \alpha_k values, viewed as a single vector
\beta_{w=1 \dots V}positive realprior weight of word w in a topic; usually the same for all words; normally a number much less than 1, e.g. 0.001, to strongly prefer sparse word distributions, i.e. few words per topic
\boldsymbol\betaV-dimensional vector of positive realscollection of all \beta_w values, viewed as a single vector
\varphi_{k=1 \dots K,w=1 \dots V}probability (real number between 0 and 1)probability of word w occurring in topic k
\boldsymbol\varphi_{k=1 \dots K}V-dimensional vector of probabilities, which must sum to 1distribution of words in topic k
\theta_{d=1 \dots M,k=1 \dots K}probability (real number between 0 and 1)probability of topic k occurring in document d
\boldsymbol\theta_{d=1 \dots M}K-dimensional vector of probabilities, which must sum to 1distribution of topics in document d
z_{d=1 \dots M,w=1 \dots N_d}integer between 1 and Kidentity of topic of word w in document d
\mathbf{Z}N-dimensional vector of integers between 1 and Kidentity of topic of all words in all documents
w_{d=1 \dots M,w=1 \dots N_d}integer between 1 and Videntity of word w in document d
\mathbf{W}N-dimensional vector of integers between 1 and Videntity of all words in all documents

We can then mathematically describe the random variables as follows:

:

\begin{align}

\boldsymbol\varphi_{k=1 \dots K} &\sim \operatorname{Dirichlet}_V(\boldsymbol\beta) \\

\boldsymbol\theta_{d=1 \dots M} &\sim \operatorname{Dirichlet}_K(\boldsymbol\alpha) \\

z_{d=1 \dots M,w=1 \dots N_d} &\sim \operatorname{Categorical}_K(\boldsymbol\theta_d) \\

w_{d=1 \dots M,w=1 \dots N_d} &\sim \operatorname{Categorical}_V(\boldsymbol\varphi_{z_{dw}})

\end{align}

Inference

{{See also|Dirichlet-multinomial distribution}}

Learning the various distributions (the set of topics, their associated word probabilities, the topic of each word, and the particular topic mixture of each document) is a problem of statistical inference.

= Monte Carlo simulation =

The original paper by Pritchard et al. used approximation of the posterior distribution by Monte Carlo simulation.

Alternative proposal of inference techniques include Gibbs sampling.{{cite journal

|title=Finding scientific topics

|first1=Thomas L. |last1=Griffiths

|first2=Mark |last2=Steyvers

|journal=Proceedings of the National Academy of Sciences

|volume=101

|issue=Suppl. 1

|pages=5228–5235

|date=April 6, 2004

|doi=10.1073/pnas.0307752101

|pmid=14872004

|pmc=387300

|bibcode=2004PNAS..101.5228G |doi-access=free }}

= Variational Bayes =

The original ML paper used a variational Bayes approximation of the posterior distribution.

= Likelihood maximization =

A direct optimization of the likelihood with a block relaxation algorithm proves to be a fast alternative to MCMC.{{cite journal

|title=Fast model-based estimation of ancestry in unrelated individuals

|first1=David H. |last1=Alexander

|first2=John |last2=Novembre

|first3=Kenneth |last3=Lange

|journal=Genome Research

|volume=19

|issue=9 |pages=1655–1664

|doi=10.1101/gr.094052.109

|pmid=19648217 |pmc=2752134 |year=2009 }}

= Unknown number of populations/topics =

In practice, the optimal number of populations or topics is not known beforehand. It can be estimated by approximation of the posterior distribution with reversible-jump Markov chain Monte Carlo.

= Alternative approaches =

Alternative approaches include expectation propagation.{{cite conference

| last = Minka | first = Thomas

|author2=Lafferty, John

| title = Expectation-propagation for the generative aspect model

| url = https://research.microsoft.com/~minka/papers/aspect/minka-aspect.pdf

| conference = Proceedings of the 18th Conference on Uncertainty in Artificial Intelligence

| year = 2002

| publisher = Morgan Kaufmann

| location = San Francisco, CA

| isbn = 1-55860-897-4

}}

Recent research has been focused on speeding up the inference of latent Dirichlet allocation to support the capture of a massive number of topics in a large number of documents. The update equation of the collapsed Gibbs sampler mentioned in the earlier section has a natural sparsity within it that can be taken advantage of. Intuitively, since each document only contains a subset of topics K_d, and a word also only appears in a subset of topics K_w, the above update equation could be rewritten to take advantage of this sparsity.{{cite conference

| last = Yao

| first = Limin |author2=Mimno, David |author3=McCallum, Andrew

| title = Efficient methods for topic model inference on streaming document collections

| conference = 15th ACM SIGKDD international conference on Knowledge discovery and data mining

| year = 2009

}}

: p(Z_{d,n} = k) \propto \frac{\alpha\beta}{C_k^{\neg n} + V\beta} + \frac{C_k^d \beta}{C_k^{\neg n} + V\beta} + \frac{C_k^w(\alpha + C_k^d)}{C_k^{\neg n} + V\beta}

In this equation, we have three terms, out of which two are sparse, and the other is small. We call these terms a, b and c respectively. Now, if we normalize each term by summing over all the topics, we get:

:

A = \sum_{k=1}^K \frac{\alpha\beta}{C_k^{\neg n} + V\beta}

:

B = \sum_{k=1}^K \frac{C_k^d \beta}{C_k^{\neg n} + V\beta}

:

C = \sum_{k=1}^K \frac{C_k^w(\alpha + C_k^d)}{C_k^{\neg n} + V\beta}

Here, we can see that B is a summation of the topics that appear in document d, and C is also a sparse summation of the topics that a word w is assigned to across the whole corpus. A on the other hand, is dense but because of the small values of \alpha & \beta, the value is very small compared to the two other terms.

Now, while sampling a topic, if we sample a random variable uniformly from s \sim U(s|\mid A+B+C), we can check which bucket our sample lands in. Since A is small, we are very unlikely to fall into this bucket; however, if we do fall into this bucket, sampling a topic takes O(K) time (same as the original Collapsed Gibbs Sampler). However, if we fall into the other two buckets, we only need to check a subset of topics if we keep a record of the sparse topics. A topic can be sampled from the B bucket in O(K_d) time, and a topic can be sampled from the C bucket in O(K_w) time where K_d and K_w denotes the number of topics assigned to the current document and current word type respectively.

Notice that after sampling each topic, updating these buckets is all basic O(1) arithmetic operations.

= Aspects of computational details =

Following is the derivation of the equations for collapsed Gibbs sampling, which means \varphis and \thetas will be integrated out. For simplicity, in this derivation the documents are all assumed to have the same length N_{}. The derivation is equally valid if the document lengths vary.

According to the model, the total probability of the model is:

: P(\boldsymbol{W}, \boldsymbol{Z}, \boldsymbol{\theta}, \boldsymbol{\varphi};\alpha,\beta) = \prod_{i=1}^K P(\varphi_i;\beta) \prod_{j=1}^M P(\theta_j;\alpha) \prod_{t=1}^N

P(Z_{j,t}\mid\theta_j)P(W_{j,t}\mid\varphi_{Z_{j,t}}) ,

where the bold-font variables denote the vector version of the variables. First, \boldsymbol{\varphi} and \boldsymbol{\theta} need to be integrated out.

:\begin{align}

& P(\boldsymbol{Z}, \boldsymbol{W};\alpha,\beta) = \int_{\boldsymbol{\theta}} \int_{\boldsymbol{\varphi}} P(\boldsymbol{W}, \boldsymbol{Z}, \boldsymbol{\theta}, \boldsymbol{\varphi};\alpha,\beta) \, d\boldsymbol{\varphi} \, d\boldsymbol{\theta} \\

= {} & \int_{\boldsymbol{\varphi}} \prod_{i=1}^K P(\varphi_i;\beta) \prod_{j=1}^M \prod_{t=1}^N P(W_{j,t}\mid\varphi_{Z_{j,t}}) \, d\boldsymbol{\varphi} \int_{\boldsymbol{\theta}} \prod_{j=1}^M P(\theta_j;\alpha) \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \, d\boldsymbol{\theta}.

\end{align}

All the \thetas are independent to each other and the same to all the \varphis. So we can treat each \theta and each \varphi separately. We now focus only on the \theta part.

: \int_{\boldsymbol{\theta}} \prod_{j=1}^M P(\theta_j;\alpha) \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \,d\boldsymbol{\theta} = \prod_{j=1}^M \int_{\theta_j} P(\theta_j;\alpha) \prod_{t=1}^N

P(Z_{j,t}\mid\theta_j) \, d\theta_j.

We can further focus on only one \theta as the following:

: \int_{\theta_j} P(\theta_j;\alpha) \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \, d\theta_j .

Actually, it is the hidden part of the model for the j^{th} document. Now we replace the probabilities in the above equation by the true distribution expression to write out the explicit equation.

:\int_{\theta_j} P(\theta_j;\alpha) \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \, d\theta_j = \int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{\alpha_i - 1} \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \, d\theta_j.

Let n_{j,r}^i be the number of word tokens in the j^{th} document with the same word symbol (the r^{th} word in the vocabulary) assigned to the i^{th} topic. So, n_{j,r}^i is three dimensional. If any of the three dimensions is not limited to a specific value, we use a parenthesized point (\cdot) to

denote. For example, n_{j,(\cdot)}^i denotes the number of word tokens in the j^{th} document assigned to the i^{th} topic. Thus, the right most part of the above equation can be rewritten as:

: \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) = \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i} .

So the \theta_j integration formula can be changed to:

:\int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{\alpha_i - 1} \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i} \, d\theta_j = \int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i+\alpha_i - 1} \, d\theta_j.

The equation inside the integration has the same form as the Dirichlet distribution. According to the Dirichlet distribution,

:\int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right)}{\prod_{i=1}^K \Gamma(n_{j,(\cdot)}^i+\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i+\alpha_i - 1} \, d\theta_j =1 .

Thus,

:\begin{align}

& \int_{\theta_j} P(\theta_j;\alpha) \prod_{t=1}^N P(Z_{j,t}\mid\theta_j) \, d\theta_j = \int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i+\alpha_i - 1} \, d\theta_j \\ [8pt]

= {} & \frac{\Gamma\left (\sum_{i=1}^K \alpha_i \right )}{\prod_{i=1}^K \Gamma(\alpha_i)}\frac{\prod_{i=1}^K \Gamma(n_{j,(\cdot)}^i+\alpha_i)}{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right )} \int_{\theta_j} \frac{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right)}{\prod_{i=1}^K \Gamma(n_{j,(\cdot)}^i+\alpha_i)} \prod_{i=1}^K \theta_{j,i}^{n_{j,(\cdot)}^i+\alpha_i - 1} \, d\theta_j \\ [8pt]

= {} & \frac{\Gamma\left(\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)}\frac{\prod_{i=1}^K \Gamma(n_{j,(\cdot)}^i+\alpha_i)}{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right)}.

\end{align}

Now we turn our attention to the \boldsymbol{\varphi} part. Actually, the derivation of the \boldsymbol{\varphi} part is very similar to the \boldsymbol{\theta} part. Here we only list the steps of the derivation:

:\begin{align}

& \int_{\boldsymbol{\varphi}} \prod_{i=1}^K P(\varphi_i;\beta) \prod_{j=1}^M \prod_{t=1}^N P(W_{j,t}\mid\varphi_{Z_{j,t}}) \, d\boldsymbol{\varphi} \\[8pt]

= {} & \prod_{i=1}^K \int_{\varphi_i} P(\varphi_i;\beta) \prod_{j=1}^M \prod_{t=1}^N P(W_{j,t}\mid \varphi_{Z_{j,t}}) \, d\varphi_i\\ [8pt]

= {} & \prod_{i=1}^K \int_{\varphi_i} \frac{\Gamma\left(\sum_{r=1}^V \beta_r \right)}{\prod_{r=1}^V \Gamma(\beta_r)} \prod_{r=1}^V \varphi_{i,r}^{\beta_r - 1} \prod_{r=1}^V \varphi_{i,r}^{n_{(\cdot),r}^i} \, d\varphi_i \\ [8pt]

= {} & \prod_{i=1}^K \int_{\varphi_i} \frac{\Gamma\left(\sum_{r=1}^V \beta_r \right)}{\prod_{r=1}^V \Gamma(\beta_r)} \prod_{r=1}^V \varphi_{i,r}^{n_{(\cdot),r}^i+\beta_r - 1} \, d\varphi_i \\ [8pt]

= {} & \prod_{i=1}^K \frac{\Gamma\left(\sum_{r=1}^V \beta_r \right)}{\prod_{r=1}^V \Gamma(\beta_r)}\frac{\prod_{r=1}^V \Gamma(n_{(\cdot),r}^i+\beta_r)}{\Gamma\left(\sum_{r=1}^V n_{(\cdot),r}^i+\beta_r \right)}.

\end{align}

For clarity, here we write down the final equation with both \boldsymbol{\phi} and \boldsymbol{\theta} integrated out:

: P(\boldsymbol{Z}, \boldsymbol{W};\alpha,\beta) = \prod_{j=1}^M \frac{\Gamma\left(\sum_{i=1}^K \alpha_i \right )}{\prod_{i=1}^K \Gamma(\alpha_i)}\frac{\prod_{i=1}^K \Gamma(n_{j,(\cdot)}^i+\alpha_i)}{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right)} \times \prod_{i=1}^K \frac{\Gamma\left (\sum_{r=1}^V \beta_r \right )}{\prod_{r=1}^V \Gamma(\beta_r)}\frac{\prod_{r=1}^V

\Gamma(n_{(\cdot),r}^i+\beta_r)}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^i+\beta_r \right)}.

The goal of Gibbs Sampling here is to approximate the distribution of P(\boldsymbol{Z}\mid\boldsymbol{W};\alpha,\beta). Since P(\boldsymbol{W};\alpha,\beta) is invariable for any of Z, Gibbs Sampling equations can be derived from P(\boldsymbol{Z}, \boldsymbol{W};\alpha,\beta) directly. The key point is to derive the following conditional probability:

: P(Z_{(m,n)}\mid\boldsymbol{Z_{-(m,n)}}, \boldsymbol{W};\alpha,\beta)=\frac{P(Z_{(m,n)}, \boldsymbol{Z_{-(m,n)}},\boldsymbol{W};\alpha,\beta)} {P(\boldsymbol{Z_{-(m,n)}}, \boldsymbol{W};\alpha,\beta)} ,

where Z_{(m,n)} denotes the Z hidden variable of the n^{th} word token in the m^{th} document. And further we assume that the word

symbol of it is the v^{th} word in the vocabulary. \boldsymbol{Z_{-(m,n)}} denotes all the Zs but Z_{(m,n)}. Note that Gibbs Sampling needs only to sample a value for Z_{(m,n)}, according to the above probability, we do not need the exact value of

:P \left (Z_{m,n}\mid\boldsymbol{Z_{-(m,n)}}, \boldsymbol{W};\alpha,\beta \right )

but the ratios among the probabilities that Z_{(m,n)} can take value. So, the above equation can be simplified as:

: \begin{align}

P (&Z_{(m,n)}=v\mid \boldsymbol{Z_{-(m,n)}}, \boldsymbol{W};\alpha,\beta ) \\ [8pt]

&\propto P (Z_{(m,n)}=v,\boldsymbol{Z_{-(m,n)}},\boldsymbol{W};\alpha,\beta ) \\ [8pt]

&= \left(\frac{\Gamma\left(\sum_{i=1}^K \alpha_i \right)}{\prod_{i=1}^K \Gamma(\alpha_i)}\right)^M \prod_{j\neq m} \frac{\prod_{i=1}^K \Gamma \left (n_{j,(\cdot)}^i+\alpha_i \right )}{\Gamma\left (\sum_{i=1}^K n_{j,(\cdot)}^i+\alpha_i \right)} \left( \frac{\Gamma\left (\sum_{r=1}^V \beta_r \right)}{\prod_{r=1}^V \Gamma(\beta_r)}\right)^K \prod_{i=1}^K \prod_{r\neq v} \Gamma \left (n_{(\cdot),r}^i+\beta_r \right )\frac{\prod_{i=1}^K \Gamma \left (n_{m,(\cdot)}^i+\alpha_i \right )}{\Gamma\left (\sum_{i=1}^K n_{m,(\cdot)}^i+\alpha_i \right )} \prod_{i=1}^K \frac{ \Gamma \left (n_{(\cdot),v}^i+\beta_v \right )} {\Gamma \left (\sum_{r=1}^V n_{(\cdot),r}^i+\beta_r \right )} \\ [8pt]

&\propto \frac{\prod_{i=1}^K \Gamma \left (n_{m,(\cdot)}^i+\alpha_i \right )}{\Gamma\left (\sum_{i=1}^K n_{m,(\cdot)}^i+\alpha_i \right)} \prod_{i=1}^K \frac{ \Gamma \left (n_{(\cdot),v}^i+\beta_v \right )}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^i+\beta_r \right )}\\ [8pt]

&\propto \prod_{i=1}^K \Gamma \left (n_{m,(\cdot)}^i+\alpha_i \right ) \prod_{i=1}^K \frac{\Gamma \left (n_{(\cdot),v}^i+\beta_v \right )}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^i+\beta_r \right )}.

\end{align}

Finally, let n_{j,r}^{i,-(m,n)} be the same meaning as n_{j,r}^i but with the Z_{(m,n)} excluded. The above equation can be further simplified leveraging the property of gamma function. We first split the summation and then merge it back to obtain a k-independent summation, which could be dropped:

:\begin{align}

&\propto \prod_{i\neq k} \Gamma \left (n_{m,(\cdot)}^{i,-(m,n)}+\alpha_i \right ) \prod_{i\neq k} \frac{ \Gamma \left (n_{(\cdot),v}^{i,-(m,n)}+\beta_v \right )}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^{i,-(m,n)}+\beta_r \right )} \Gamma \left (n_{m,(\cdot)}^{k,-(m,n)}+\alpha_k + 1 \right ) \frac{\Gamma \left (n_{(\cdot),v}^{k,-(m,n)}+\beta_v + 1 \right )}{\Gamma\left(\sum_{r=1}^V n_{(\cdot),r}^{k,-(m,n)} + \beta_r +1 \right)} \\ [8pt]

&= \prod_{i\neq k} \Gamma \left (n_{m,(\cdot)}^{i,-(m,n)}+\alpha_i \right ) \prod_{i\neq k} \frac{\Gamma \left (n_{(\cdot),v}^{i,-(m,n)}+\beta_v \right )}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^{i,-(m,n)} + \beta_r \right )} \Gamma \left (n_{m,(\cdot)}^{k,-(m,n)}+\alpha_k \right ) \frac{\Gamma \left (n_{(\cdot),v}^{k,-(m,n)}+\beta_v \right )} {\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^{k,-(m,n)}+\beta_r \right )} \left (n_{m,(\cdot)}^{k,-(m,n)}+\alpha_k \right ) \frac{n_{(\cdot),v}^{k,-(m,n)}+\beta_v } {\sum_{r=1}^V n_{(\cdot),r}^{k,-(m,n)}+\beta_r} \\ [8pt]

&= \prod_{i} \Gamma \left (n_{m,(\cdot)}^{i,-(m,n)}+\alpha_i \right ) \prod_{i} \frac{ \Gamma \left (n_{(\cdot),v}^{i,-(m,n)}+\beta_v \right )}{\Gamma\left (\sum_{r=1}^V n_{(\cdot),r}^{i,-(m,n)}+\beta_r \right )} \left (n_{m,(\cdot)}^{k,-(m,n)}+\alpha_k \right ) \frac{n_{(\cdot),v}^{k,-(m,n)}+\beta_v } {\sum_{r=1}^V n_{(\cdot),r}^{k,-(m,n)}+\beta_r} \\ [8pt]

&\propto \left (n_{m,(\cdot)}^{k,-(m,n)}+\alpha_k \right ) \frac{n_{(\cdot),v}^{k,-(m,n)}+\beta_v } {\sum_{r=1}^V n_{(\cdot),r}^{k,-(m,n)}+\beta_r}

\end{align}

Note that the same formula is derived in the article on the Dirichlet-multinomial distribution, as part of a more general discussion of integrating Dirichlet distribution priors out of a Bayesian network.

Related problems

= Related models =

Topic modeling is a classic solution to the problem of information retrieval using linked data and semantic web technology.{{cite journal |last1=Lamba |first1=Manika |last2=Madhusudhan |first2=Margam |title=Mapping of topics in DESIDOC Journal of Library and Information Technology, India: a study |journal=Scientometrics |date=2019 |volume=120 |issue=2 |pages=477–505 |doi=10.1007/s11192-019-03137-5 |s2cid=174802673 }} Related models and techniques are, among others, latent semantic indexing, independent component analysis, probabilistic latent semantic indexing, non-negative matrix factorization, and Gamma-Poisson distribution.

The LDA model is highly modular and can therefore be easily extended. The main field of interest is modeling relations between topics. This is achieved by using another distribution on the simplex instead of the Dirichlet. The Correlated Topic Model{{cite journal

| last = Blei

| first = David M.

|author2=Lafferty, John D.

| title = Correlated topic models

| url = https://papers.nips.cc/paper/2005/file/9e82757e9a1c12cb710ad680db11f6f1-Paper.pdf

| journal = Advances in Neural Information Processing Systems

| volume = 18

| year = 2005

}} follows this approach, inducing a correlation structure between topics by using the logistic normal distribution instead of the Dirichlet. Another extension is the hierarchical LDA (hLDA),{{cite conference

| last = Blei

| first = David M.

| author2 = Jordan, Michael I.

| author3 = Griffiths, Thomas L.

| author4 = Tenenbaum, Joshua B

| title = Hierarchical Topic Models and the Nested Chinese Restaurant Process

| url = https://proceedings.neurips.cc/paper/2003/file/7b41bfa5085806dfa24b8c9de0ce567f-Paper.pdf

| conference = Advances in Neural Information Processing Systems 16: Proceedings of the 2003 Conference

| publisher = MIT Press

| isbn = 0-262-20152-6

| year = 2004

| author2-link = Michael I. Jordan

}} where topics are joined together in a hierarchy by using the nested Chinese restaurant process, whose structure is learnt from data. LDA can also be extended to a corpus in which a document includes two types of information (e.g., words and names), as in the LDA-dual model.{{cite conference

| last = Shu

| first = Liangcai |author2=Long, Bo |author3=Meng, Weiyi

| title = A Latent Topic Model for Complete Entity Resolution

| url = http://www.cs.binghamton.edu/~meng/pub.d/icde09-LatentTopic.pdf

| conference = 25th IEEE International Conference on Data Engineering (ICDE 2009)

| year = 2009

}}

Nonparametric extensions of LDA include the hierarchical Dirichlet process mixture model, which allows the number of topics to be unbounded and learnt from data.

As noted earlier, pLSA is similar to LDA. The LDA model is essentially the Bayesian version of pLSA model. The Bayesian formulation tends to perform better on small datasets because Bayesian methods can avoid overfitting the data. For very large datasets, the results of the two models tend to converge. One difference is that pLSA uses a variable d to represent a document in the training set. So in pLSA, when presented with a document the model has not seen before, we fix \Pr(w \mid z)—the probability of words under topics—to be that learned from the training set and use the same EM algorithm to infer \Pr(z \mid d)—the topic distribution under d. Blei argues that this step is cheating because you are essentially refitting the model to the new data.

= Spatial models =

In evolutionary biology, it is often natural to assume that the geographic locations of the individuals observed bring some information about their ancestry. This is the rational of various models for geo-referenced genetic data.{{cite journal

| last1 = Guillot | first1 = G.

| last2 = Estoup | first2 = A.

| last3 = Mortier | first3 = F.

| last4 = Cosson | first4 = J.

| title = A spatial statistical model for landscape genetics

| journal = Genetics

| volume = 170

| issue = 3

| pages = pp. 1261–1280

| doi = 10.1534/genetics.104.033803

| pmid = 15520263

| pmc = 1451194

| year = 2005

}}{{cite journal

| last1 = Guillot | first1 = G.

| last2 = Leblois | first2 = R.

| last3 = Coulon | first3 = A.

| last4 = Frantz | first4 = A.

| title = Statistical methods in spatial genetics

| journal = Molecular Ecology

| volume = 18

| issue = 23

| pages = pp. 4734–4756

| doi = 10.1111/j.1365-294X.2009.04410.x

| pmid = 19878454

| year = 2009

| doi-access = free| bibcode = 2009MolEc..18.4734G

}}

Variations on LDA have been used to automatically put natural images into categories, such as "bedroom" or "forest", by treating an image as a document, and small patches of the image as words;{{cite journal|last=Li|first=Fei-Fei|author2=Perona, Pietro |title=A Bayesian Hierarchical Model for Learning Natural Scene Categories|journal=Proceedings of the 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'05)|volume=2|pages=524–531}} one of the variations is called spatial latent Dirichlet allocation.{{cite journal|last=Wang|first=Xiaogang|author2=Grimson, Eric |title=Spatial Latent Dirichlet Allocation|journal=Proceedings of Neural Information Processing Systems Conference (NIPS)|year=2007|url = https://papers.nips.cc/paper/2007/file/ec8956637a99787bd197eacd77acce5e-Paper.pdf}}

See also

References

{{Reflist}}