Sub topic 4
Dirichlet Priors: Alpha and Eta
This chapter assumes you know tokenisation, stop words, basic probability, and the idea that LDA represents documents with word counts. It focuses on how LDA uses prior distributions before it sees the corpus.
What a Dirichlet prior does
A Dirichlet distribution is a probability distribution over probability distributions. In LDA, it describes plausible mixtures before observing any words.
For a document, the mixture contains one probability for each topic. For a topic, the mixture contains one probability for each vocabulary word. The parameters of these Dirichlet distributions are called concentration parameters. LDA commonly names them alpha and eta.
These parameters do not directly choose topics or words. They influence how concentrated or spread out the learned distributions are.
| Parameter | Distribution affected | Main question |
|---|---|---|
| `alpha` | Document-topic distribution | How many topics should a document use? |
| `eta` | Topic-word distribution | How many words should a topic use? |
Alpha: document-topic mixtures
Suppose a corpus has four topics. A document-topic distribution might be:
[0.80, 0.10, 0.05, 0.05]
This document mainly uses one topic. Another document might use:
[0.25, 0.25, 0.25, 0.25]
A low, symmetric alpha encourages sparse mixtures. Documents tend to use only a few topics. This often matches news articles or research papers.
A high alpha encourages documents to spread probability across many topics. This can help when documents are short but genuinely discuss several themes.
With asymmetric alpha, different topics can have different expected prevalence. This is useful when you have a strong prior belief that some topics are common and others are rare, although many projects begin with a symmetric prior.
Eta: topic-word distributions
eta controls the word distribution for each topic. A low eta encourages a topic to concentrate probability on a smaller set of words. The resulting topics may be easier to label because their top words are distinctive.
A high eta produces broader word distributions. Topics share more vocabulary, which can help when synonyms or general terms are important. Too high a value can make topics difficult to distinguish.
The effect depends on vocabulary size, document length, and the number of topics. A value that works for one corpus may be unsuitable for another.
from gensim import corpora
from gensim.models import LdaModel
docs = [
["goal", "team", "match", "season"],
["election", "vote", "party", "policy"],
["coach", "league", "team", "win"],
["government", "vote", "law", "policy"],
]
dictionary = corpora.Dictionary(docs)
corpus = [dictionary.doc2bow(doc) for doc in docs]
lda = LdaModel(
corpus=corpus,
id2word=dictionary,
num_topics=2,
alpha="auto",
eta="auto",
passes=20,
random_state=42,
)
print(lda.get_document_topics(corpus[0], minimum_probability=0.0))With "auto", gensim learns these priors from the data. This is a useful starting point, but it does not guarantee meaningful topics. Compare several settings and inspect the results.
Exercise
A document is expected to discuss one main subject with occasional references to other subjects. Should you start with a relatively low or high alpha?
Show answer
Start with a relatively low alpha because it encourages a sparse document-topic mixture. Test it against alternatives and inspect example documents.