---
title: "Topic Modeling: Contextual Token Embeddings Are All You Need"
description: "Contextual-Top2Vec discovers topics from groups of nearby tokens, locates them within documents, and describes them with phrases."
canonical: "https://research.elamur.ai/free/en/papers/angelov-2024-topic-modeling-contextual-token-embeddings/"
---
Elamur: [Mova](https://md.mova.elamur.ai/free/en/) · [Parse](https://mova.elamur.ai/free/en/parse/) · [Dictionary](https://md.dictionary.elamur.ai/free/en/) · [Translate](https://md.translate.elamur.ai/free/en/) · **Research** · [Gali](https://md.gali.elamur.ai/free/en/) · [MCP](https://mcp.elamur.ai/) · [Locations](https://md.locations.elamur.ai/free/en/) · [Weather](https://md.weather.elamur.ai/free/en/)

[Elamur Research](https://md.research.elamur.ai/free/en/) · [this page in HTML](https://research.elamur.ai/free/en/papers/angelov-2024-topic-modeling-contextual-token-embeddings/)

[Elamur Research](https://md.research.elamur.ai/free/en/) / [papers](https://md.research.elamur.ai/free/en/papers/) / [2024](https://md.research.elamur.ai/free/en/papers/2024/) / Topic Modeling: Contextual Token Embeddings Are All You Need

# Topic Modeling: Contextual Token Embeddings Are All You Need

Paper · 2024 · Dimo Angelov and Diana Inkpen

**Authors:** [Dimo Angelov](https://md.research.elamur.ai/free/en/authors/dimo-angelov/) and [Diana Inkpen](https://md.research.elamur.ai/free/en/authors/diana-inkpen/) · **Year:** 2024 · **Venue:** Findings of the Association for Computational Linguistics: EMNLP 2024 · **Licence:** [CC BY 4.0 (ACL Anthology)](https://creativecommons.org/licenses/by/4.0/)

Findings of the Association for Computational Linguistics: EMNLP 2024 · [licence](https://creativecommons.org/licenses/by/4.0/)

- [Publisher's page](https://aclanthology.org/2024.findings-emnlp.790/)
- [PDF](https://aclanthology.org/2024.findings-emnlp.790.pdf)
- [DOI 10.18653/v1/2024.findings-emnlp.790](https://doi.org/10.18653/v1/2024.findings-emnlp.790)

## Summary

A document can discuss several subjects, and knowing its main subject tells you little about where to find a particular discussion. The problem is especially clear in a collection of posts, where a writer can move from one issue to another in the same message. Angelov and Inkpen present Contextual-Top2Vec, a method that discovers recurring subjects across a collection and marks the stretches of text where they occur. This gives a reader both a way to browse the collection and a way to find the relevant passage inside a result. The paper treats both tasks as part of [topic modeling](https://md.research.elamur.ai/free/en/concepts/topic-modeling/).

The method keeps a separate numerical representation for each token occurrence. The surrounding text influences that representation, so the same word can contribute different evidence in different passages. The authors average these vectors over overlapping windows and look for groups of windows that are close together. Each group supplies a topic vector. The method then compares each token and its immediate neighbors with those topic vectors. Consecutive assignments reveal topic spans, while counts and similarities indicate how much of a document concerns a topic and how closely that part matches it. To describe the topics, the method finds recurring phrases in the collection and selects those whose vectors lie closest to each topic.

The experiments compare Contextual-Top2Vec with earlier approaches on 20Newsgroups and a stratified sample of Yahoo! Answers. It leads on several measures of topic coherence, including a measure that scores phrases intact. The original Top2Vec scores higher on the word2vec coherence measure, and CTM leads on the sliding-window coherence measure for Yahoo! Answers. When each document receives a single label for comparison with the datasets’ categories, Contextual-Top2Vec and Top2Vec give very similar results. The paper’s BERTScore evaluation also compares topic descriptions directly with selected text. On 20Newsgroups, Contextual-Top2Vec obtains a BERTScore F1 of 0.409, compared with 0.351 for Top2Vec, using selected spans for Contextual-Top2Vec and whole documents for the baselines.

A separate comparison helps explain what the spans contribute. On Yahoo! Answers, whole documents give a BERTScore recall of 0.440. Keeping only the predicted topic spans gives 0.439, while keeping only the other spans gives 0.313. The selected text thus retains almost all the measured support for the topic descriptions. That result evaluates the content selected by the method. The benchmarks supply document categories, so the accuracy of individual span boundaries remains open.

## Deep dive: Topic Modeling: Contextual Token Embeddings Are All You Need

Contextual-Top2Vec discovers topics from groups of nearby tokens, locates them within documents, and describes them with phrases. · about 34 minutes to read

**In this deep dive**

1. [The problem and its context](#dd-the-problem-and-its-context)
2. [The method, step by step](#dd-the-method-step-by-step)
3. [Experiments and results](#dd-experiments-and-results)
4. [What the ablations show](#dd-what-the-ablations-show)
5. [Limitations](#dd-limitations)
6. [What came after](#dd-what-came-after)

### The problem and its context

#### What a topic should tell a reader

A topic analysis has to serve readers at several scales. Across a collection, a reader wants to know which subjects recur and how finely they can be divided. Within a topic, the reader wants a description that makes the subject recognizable and helps identify documents worth opening. Inside a document, the reader may want the particular passage that prompted the assignment. Each question calls for a different kind of evidence. A list of category names can make a collection easier to navigate, while a highlighted passage can explain why a particular document appeared under one of those names.

The paper distinguishes the amount of text assigned to a topic from the strength of the match. A document might devote considerable space to passages that are only loosely connected to a discovered topic. Another document might contain a brief discussion that matches that topic closely. A proportion records the first aspect, and a relevance score can record the second. The distinction matters whenever the unit being ranked is useful to a reader in its own right. Someone looking for a focused discussion may be more interested in the shorter passage, even if a larger fraction of the longer document has the same assignment.

Discovering how many topics to use is a related difficulty. A collection can admit a broad account in which many posts belong together and a narrower account in which the same posts fall into several recognizable groups. A system that requires a topic count at the outset makes the investigator settle on a level before seeing what the collection contains. The approach in the paper first estimates a count from the structure of the text representations, then allows nearby topics to be merged. The authors frame the choice of granularity around the use of the analysis.

Topic names introduce another problem. A ranked list can contain relevant words that remain difficult to interpret as a group. A phrase can express a relationship between its words and make the subject easier to recognize. Conversely, making a convincing description is only part of the task. A group of words may sound coherent even when the documents assigned to it discuss something else. The paper therefore separates how well the terms in a description fit together from how well that description fits the material associated with it.

#### From word counts to document vectors

The paper starts its account of earlier work with Latent Dirichlet Allocation, or LDA. It describes a document as a mixture of topics and a topic as a probability distribution over words. A document can have substantial proportions of several topics, a useful distinction when a text covers several subjects. Its bag-of-words representation retains which words appear and their counts while discarding their sequence. That representation gives the method limited information about how words are used together. The authors also argue that explaining corpus word frequencies can give high probability to terms that are poorly suited to describing a topic to a reader.

The Embedded Topic Model, or ETM, combines the mixture approach with numerical representations of words. A word embedding places words in a space where proximity can express similarities that counts alone leave implicit. This helps give related words a role in the analysis even if they are different entries in the vocabulary. The paper treats ETM as an advance in semantic representation while noting that it still requires a topic count and does not account for word order in the way the authors want. [Topic Modeling in Embedding Spaces](https://md.research.elamur.ai/free/en/papers/dieng-2020-topic-modeling-embedding-spaces/).

Another family, CTM, adds contextualized document representations to a neural extension of LDA called ProdLDA. A contextualized document vector can carry information about meaning and word arrangement that a bag of words omits. CTM can describe a document through a distribution across topics, with the count of available topics specified for the fit. As used in the comparison, its distribution is an account of the document as a whole. A reader who sees a substantial share for a topic still has to find the relevant text. [Pre-training is a Hot Topic](https://md.research.elamur.ai/free/en/papers/bianchi-2021-pre-training-is-hot-topic/).

The original Top2Vec takes a geometric approach. It uses document and word vectors in a shared space, looks for concentrations of document vectors and represents each concentration with a topic vector. Nearby words can then describe that topic. The paper identifies automatic topic discovery and subsequent topic reduction as advantages of this design, along with its ability to operate without removing stopwords in advance. In the comparison presented by the authors, Top2Vec assigns a single topic to each document. Its topic discovery mechanism is the starting point for Contextual-Top2Vec, which changes the unit that enters the clustering stage. [Top2Vec](https://md.research.elamur.ai/free/en/papers/angelov-2020-top2vec-distributed-representations-topics/).

BERTopic also clusters contextualized document vectors. It describes the resulting groups through a class-based form of term frequency–inverse document frequency, or [TF-IDF](https://md.research.elamur.ai/free/en/concepts/tf-idf/). The class-based calculation uses each group’s text to find terms characteristic of that group. The authors point out that this labeling stage uses the words as a bag even though the earlier grouping uses semantic document vectors. They also note that the approach as evaluated gives a single assignment to an assigned document and can leave documents unassigned. [BERTopic](https://md.research.elamur.ai/free/en/papers/grootendorst-2022-bertopic-neural-topic-modeling-class/).

The paper discusses related efforts that address different parts of the problem. One line of work examines how far clustering alone can go when the input consists of contextual document vectors. Its topic descriptions still come from counts within clusters. Another adds a training objective intended to encourage coherent topics. The paper also describes using contextual document representations to transfer topic analysis across languages without training for the target language. That result belongs to the earlier work and concerns a different goal from finding where topics occur in a document. [Cross-lingual Contextualized Topic Models](https://md.research.elamur.ai/free/en/papers/bianchi-2021-cross-lingual-contextualized-topic-models/).

#### Why the comparison has to look at the text

The authors describe coherence as a common target in earlier evaluations. A typical test looks at the highest-ranked words of a topic and asks whether they tend to occur together or are close in an external embedding space. Those tests tell the investigator something about the description itself. They can assign a good score to a description built from related words without checking whether those words describe the particular documents shown under that topic.

The paper also raises a question about the fit between older metrics and newer output formats. Word co-occurrence has a straightforward interpretation when the result is an ordered vocabulary list. When the output is a phrase, splitting it into individual words can discard part of the information the system is trying to convey. The evaluation therefore needs ways to compare with established word-based systems while also examining what phrase labels and span assignments add. This leads the authors to test clustering agreement, several kinds of coherence and direct alignment between a description and its associated text.

### The method, step by step

#### Keep a vector at each token position

A whole-document vector compresses the text into a single point. That point can be useful for finding documents with similar overall content, but a passage about a secondary subject has to share the same representation as every other passage. Contextual-Top2Vec starts with the vectors available before that compression. Each token occurrence has its own vector, and the vector incorporates information from the text around it. The treatment of the occurrence, as distinct from a single entry for the word in a vocabulary, is what makes the representation contextual. It draws on work on [word embeddings](https://md.research.elamur.ai/free/en/concepts/word-embeddings/) and on contextual representations from [BERT](https://md.research.elamur.ai/free/en/papers/devlin-2019-bert-pre-training-deep-bidirectional/).

The underlying encoder uses attention to construct representations that depend on other positions in the input. The paper traces this mechanism to the [Transformer](https://md.research.elamur.ai/free/en/concepts/transformer/). Its chosen encoder follows the [Sentence-BERT](https://md.research.elamur.ai/free/en/papers/reimers-2019-sentence-bert-sentence-embeddings-siamese/) approach, in which pooled representations are trained so that semantically similar texts occupy nearby positions. Pooling combines the vectors associated with a sequence into a vector for the sequence. Contextual-Top2Vec takes the token vectors before the usual pooling step and pools them over its own chosen ranges. The paper allows for other encoders with contextual token output, average pooling and training for [semantic similarity](https://md.research.elamur.ai/free/en/concepts/semantic-similarity/).

In the experiments the encoder is `all-mpnet-base-v2`, based on [MPNet](https://md.research.elamur.ai/free/en/papers/song-2020-mpnet-masked-permuted-pre-training/). The topic discovery procedure uses the embeddings it produces for the collection. It relies on the existing semantic space instead of describing a separate phase in which document category labels train the encoder to discover these topics. The distinction matters because the method’s grouping can reflect information supplied by pretraining even though the topics themselves are derived from the input collection.

From document tokens to topic spans and descriptions The steps in order.

#### Give each document several points in the space

A window moves along the token sequence. At each position the method averages the vectors inside that window, producing a point for that part of the document. The experiments use a window size of 50 tokens and a stride of 40 tokens. The stride is how far the window advances between successive positions. Because the window is wider than the stride, adjacent positions include some of the same tokens. A passage near the edge of one window can therefore contribute to more than one local representation.

Window pooling can be written as the mean described in the paper.

```
dⱼ = (∑ᵢ∈Wⱼ cᵢ) / |Wⱼ|
```

Here j indexes a window, Wⱼ is the set of token positions in that window, and i indexes a position in Wⱼ. The vector cᵢ is the encoder output for the token at i. The sum adds those vectors component by component, and |Wⱼ| gives the number of vectors being averaged. The result dⱼ is the window vector used as a sub-document representation. The vectors are taken from the encoding of the document, so information from the available surrounding context enters before the averaging step.

The window sets the scale at which the method looks for recurring subject matter. A very short span may give little evidence about how a word is being used, even when its contextual vector already carries information about neighboring text. A very long span can combine several discussions into a single point. The windows offer an intermediate unit. If distinct parts of a document discuss different subjects, their pooled vectors can end up near different parts of the corpus. The paper motivates this representation with earlier work on the limits of single-vector representations in [text retrieval](https://md.research.elamur.ai/free/en/papers/luan-2021-sparse-dense-attentional-representations-text/).

The window vectors are inputs for discovering topics. Their edges do not dictate the boundaries of the spans later shown to a reader. A window can contain material about more than one subject and can overlap another window by design. Once the collection’s topics exist, a separate assignment step goes back to the token sequence and can place a change of topic inside a discovery window. This is how the method combines enough context to find groups with enough detail to locate changes within a post.

#### Discover dense groups and represent their centers

The geometric premise is that windows about a shared subject should frequently occupy neighboring positions. If many windows are close, their concentration provides evidence for a topic common to them. Finding such concentrations directly in the original space is difficult because the vectors have many dimensions. The authors use [UMAP](https://md.research.elamur.ai/free/en/papers/mcinnes-2018-umap-uniform-manifold-approximation-projection/) to give the window vectors a lower-dimensional representation that retains structure relevant to grouping. Their C-Top2Vec configuration uses 50 UMAP neighbors and 5 output dimensions.

The projected points then go to [HDBSCAN](https://md.research.elamur.ai/free/en/papers/mcinnes-2017-hdbscan-hierarchical-density-clustering/), a clustering procedure based on density. It can find groups with different densities and takes no fixed cluster count. The reported minimum cluster size for C-Top2Vec is 15. The groups returned at this stage determine the initial number of topics. That number depends on where the method finds sufficiently dense collections of windows, given the corpus, representation and settings.

After finding a cluster, the authors recover the original vectors of its members and average them. In this way, projection is used to locate groups while the topic vectors remain in the space used to represent the text.

```
tₖ = (∑ⱼ∈Gₖ dⱼ) / |Gₖ|
```

Here k indexes a discovered cluster, Gₖ is the set of indices of its member windows, and j is one of those indices. The vector dⱼ is a window representation in the original embedding space. The sum adds the member vectors, and |Gₖ| is the number of member windows. The mean tₖ is the centroid for that group and becomes its topic vector. Keeping the centroid in the original space makes it possible to compare it with token and phrase vectors at subsequent stages.

Several operations use cosine similarity, which compares the directions of two vectors by scaling their dot product by their lengths.

```
cos(a, b) = (a · b) / (‖a‖ ‖b‖)
```

The vectors a and b are the two representations being compared, such as a topic vector and a phrase vector. The centered dot is the dot product, and the double bars denote vector length. The letters cos name the resulting cosine similarity. Higher similarity makes a phrase a closer candidate for a description, or makes a topic a closer candidate for a token assignment. In each case, the comparison takes place between compatible vectors in the original embedding space.

#### Change the granularity by merging topics

The initial clusters can reveal a finer division than an investigator wants. Contextual-Top2Vec uses the reduction procedure from Top2Vec to create a coarser result. It first assigns each window vector to its nearest current topic, then counts how many window vectors each topic receives. These counts are the topic sizes used for reduction. The initial density clustering establishes the topic vectors, while the assignment for reduction establishes the sizes at a given stage.

The procedure chooses the smallest topic and searches for its closest other topic by cosine similarity. The two are replaced by a weighted mean in which a topic’s number of assigned windows determines its weight.

```
t′ = (sₐ tₐ + sᵦ tᵦ) / (sₐ + sᵦ)
```

The vectors tₐ and tᵦ represent the two topics, with a indexing the smallest topic and b indexing its nearest neighbor. The counts sₐ and sᵦ are the respective numbers of assigned windows. Multiplying a vector by its count gives that topic its contribution to the merged center. The vector t′ is the resulting topic, and the denominator is the total weight. If the neighbor has more assigned windows, the new representation lies closer to that neighbor’s vector in the weighted average.

The operations repeat until the desired count is reached. A hierarchy here comes from the sequence of merges. A topic at one level can represent material that was described through separate topics at a finer level. The initial count supplied by density clustering and the requested count supplied for reduction are different decisions. The first depends on what the clustering procedure finds. The second depends on how broadly the investigator wants to view what was found. The merge rule itself uses size and similarity, so the resulting hierarchy reflects the geometry of the embedded collection.

#### Assign a topic to each token and recover spans

Once topics have been discovered or reduced, the method compares them with local content at a finer scale. At each token position, it takes a centered window of size 3 and averages the vector at that position with its adjacent token vectors. The mean smooths the input to topic assignment. A token contributes evidence in conjunction with its immediate neighborhood, while the algorithm still returns a decision at the token position. This short smoothing operation has a different role from the wider pooling used for topic discovery.

```
zᵢ = arg maxₖ cos(c̃ᵢ, tₖ)
```

Here i is the token position and c̃ᵢ is its locally averaged contextual vector. The tilde marks the smoothing operation. The vector tₖ represents topic k, cos is cosine similarity, and arg maxₖ returns the index of the topic with the largest similarity. The resulting topic index zᵢ is attached to the original token position. Consecutive positions with the same assignment form a topic span. If a subject disappears and returns later, the same topic can be associated with separate parts of the document.

The sequence of assignments also produces a document-level distribution. For each topic, the method counts how many of the document’s tokens received that assignment and divides by the document’s total token count.

```
p(t, d) = n(t, d) / n(d)
```

The symbol d denotes a document and t denotes a topic. The function n(t, d) counts the tokens assigned to t in d. The quantity n(d) counts the document’s tokens, and p(t, d) is the fraction assigned to that topic. This is a probability in the sense of a distribution over token assignments. A reader can interpret it as the share of the document allocated to the topic by the method.

The authors also take the average cosine similarity of the token vectors assigned to a topic. This records how closely the assigned text aligns with the topic vector.

```
r(t, d) = (∑ᵢ∈I(t,d) cos(cᵢ, t)) / |I(t,d)|
```

Here r(t, d) denotes topic relevance for document d, and I(t,d) is the set of positions in d assigned to t. Each i is a position in that set, cᵢ is its contextual token vector, and t in the cosine function denotes the topic vector. The sum adds the token-to-topic similarities. The denominator |I(t,d)| is the size of the set, so the expression describes relevance where the topic has assigned tokens. The paper explicitly describes smoothing for the assignment step and refers to contextual token vectors when defining the relevance average. It does not give a separate smoothing rule for relevance.

The evaluation sometimes needs a single score for a document and a topic. The authors combine the fraction and the relevance value by multiplying them for each pair.

```
q(t, d) = p(t, d) × r(t, d)
```

The score q(t, d) combines the fraction p(t, d) of document d assigned to topic t with the mean relevance r(t, d) of that assigned material. The multiplication applies independently to each topic. For assigning a single document category, the authors choose the topic with the highest combined score. For assembling documents to compare against a topic description, they use the same score to rank documents for that topic. The choice joins an extent measure with a similarity measure, while the underlying span sequence remains available.

#### Describe each topic with phrases from the corpus

The descriptions draw on expressions found across the document collection. The authors use pointwise mutual information to identify collocations, sequences whose words occur together sufficiently strongly compared with what their separate frequencies would suggest. The search is over groups of consecutive words, or [n-grams](https://md.research.elamur.ai/free/en/concepts/n-gram/). This first stage supplies candidate phrases. It evaluates whether a sequence is a recurring expression, leaving the question of which topic it describes to a later comparison.

Each candidate phrase is embedded. For every topic, the method compares its vector with the candidate vectors and selects the nearest phrases by cosine similarity. If P denotes the set of phrase vectors, pᵢ denotes one of its members, and N is the chosen number of labels, the selection takes the N members of P with the highest similarities to the topic vector. The evaluations use the top 10 phrases per topic. Each phrase remains a unit at the labeling stage, so its words can express a subject jointly.

The paper’s examples make the intended difference visible. One 20Newsgroups topic is described by phrases involving sports cars and particular cars, with candidates including “mustang gt” and “toyota celica.” Another includes “christian doctrine” and “biblical interpretation.” In either case, the method is retrieving phrases from a common candidate pool. A phrase can characterize a topic through the content expressed by its whole sequence. It does not have to contain a particular word found in the phrase ranked first.

The paper names Top2Vec as the Python library in which the implementation is to be made available. Its reported C-Top2Vec setup lists a minimum count of 50 alongside the embedding and clustering settings. The procedure fits topics to the collection by constructing windows and grouping their representations, builds candidate labels from the collection and goes back to each document to assign its tokens. The known document categories enter the benchmark comparison instead of the description of this discovery procedure.

### Experiments and results

#### Corpora, comparisons and topic counts

The authors choose datasets with known document categories so that they can test assignment agreement as well as coherence. The 20Newsgroups collection contains posts with 20 category labels. The experiment starts from all 18,846 documents. Yahoo! Answers contains questions and answers with 10 category labels, and the study uses a stratified sample of 50,000 documents. Stratification means that sampling takes account of the categories. Both datasets are filtered to remove empty documents and those shorter than 35 characters. The stated document counts describe the inputs before this filtering. [Character-level Convolutional Networks for Text Classification](https://md.research.elamur.ai/free/en/papers/zhang-2015-character-level-convolutional-networks-text/).

These category labels serve a specific purpose. Each gives the investigators a reference assignment for a whole document. They can compare that grouping with the grouping induced by a system, even if the discovered topics have different names. A category such as the one associated with a newsgroup describes why a post belongs in that benchmark group. The discoverable recurring subjects can be broader or narrower. The experiments accommodate this distinction by evaluating 20, 60, 100 and 140 topics on 20Newsgroups, and 10, 60, 100 and 140 topics on Yahoo! Answers.

The baselines span several ways of constructing topics. LDA and ETM offer mixture methods with different representations of vocabulary. CTM incorporates contextual vectors into its document analysis. Top2Vec and BERTopic discover topics through groups of document vectors and differ in how they describe those groups. Contextual-Top2Vec competes against each under the reported topic-count configurations. The main results section says that values are averaged over multiple runs for each dataset. The appendix describes fitting each system once for each configuration because of the cost of fitting and scoring. The assignment section separately describes its results as averages over 5 runs. The paper does not explain how these run descriptions fit together.

The authors fit LDA and ETM through OCTIS and use the respective implementations for CTM, BERTopic and Top2Vec. They also use OCTIS to compute the established word-based coherence measures. Among the neural approaches, ETM uses word2vec, while the other systems use the common `all-mpnet-base-v2` encoder where they require contextual embeddings. This choice aligns an important source of semantic information across several systems. It still leaves differences in input units, labeling, clustering settings and the way each system scores its documents.

The clustering settings illustrate that distinction. For their Top2Vec setup, the authors list 15 UMAP neighbors, 5 output dimensions and a minimum cluster size of 15. C-Top2Vec shares the number of dimensions and minimum cluster size in that comparison but uses 50 neighbors. The BERTopic configuration has 15 neighbors, 5 dimensions and a minimum cluster size of 10. The comparison therefore evaluates complete configurations. It is informative about their performance as implemented, with the window-size analysis providing a more focused test of one part of the new procedure.

#### How well the topic descriptions hang together

The paper uses several views of [topic coherence](https://md.research.elamur.ai/free/en/papers/roder-2015-exploring-space-topic-coherence-measures/). Normalized pointwise mutual information, C NPMI, reflects how strongly the leading words of a topic co-occur in the actual corpus. The unit for observing co-occurrence in this calculation is the document. C V uses co-occurrence within a sliding window of text. The latter is a metric window and serves a different function from the embedding windows used to discover topics. Taken together, the measures ask whether the words share documents and whether they recur in closer textual neighborhoods.

The embedding measures compare topic terms through vectors. C WE averages pairwise cosine similarities among the leading words using [word2vec](https://md.research.elamur.ai/free/en/papers/mikolov-2013-distributed-representations-words-phrases-their/). Those pretrained vectors bring in evidence from a corpus outside the experiment. C SBERT applies the same general idea of averaging pairwise similarities with a Sentence-BERT encoder, which can represent an entire phrase. The authors use it to evaluate the descriptions in the form their method produces.

The established metrics require individual words. The baseline descriptions are already word lists, so the evaluation takes the top 10 words. To calculate C NPMI, C V, and C WE, the authors split the ten top-ranked phrases from Contextual-Top2Vec into individual words and use the ten words with the highest ranks. For C SBERT they use whole phrases. The reported comparisons consequently ask both how the method fares when its descriptions are converted to a common word format and how coherent its own phrase descriptions are when scored intact.

Document co-occurrence coherence on 20Newsgroups, C NPMI Contextual-Top2Vec has the strongest co-occurrence coherence among the compared systems.

**The numbers**

| System or setting | C NPMI |
| --- | --- |
| LDA | -0.068 |
| ETM | -0.004 |
| CTM | 0.032 |
| BERTopic | 0.027 |
| Top2Vec | -0.070 |
| Contextual-Top2Vec (this paper) | 0.138 |

Contextual-Top2Vec also leads on Yahoo! Answers C NPMI with 0.094. CTM gives 0.050 and BERTopic 0.028 on that dataset. The C V comparison varies by corpus. Contextual-Top2Vec leads on 20Newsgroups with 0.684, where CTM records 0.615. On Yahoo! Answers, CTM scores 0.601 and Contextual-Top2Vec 0.532. The result supports better document-level co-occurrence scores across the tested datasets, with the finer co-occurrence measure favoring different systems depending on the corpus.

The choice of embeddings also changes the ordering. On 20Newsgroups C WE, Top2Vec gives 0.126 and Contextual-Top2Vec 0.116. On Yahoo! Answers C WE, the respective scores are 0.106 and 0.090. With C SBERT, Contextual-Top2Vec reaches 0.514 on 20Newsgroups and 0.506 on Yahoo! Answers. Top2Vec obtains 0.480 and 0.473 on those same C SBERT comparisons. The authors suggest that splitting phrases can explain the weaker word2vec results. The two tests also change the embedding method, so their different orderings give evidence about how the evaluation depends on representation and leave the exact contribution of splitting unresolved.

#### How the induced groups match known categories

The document assignment test uses the adjusted Rand index, ARI, and adjusted mutual information, AMI. Both compare groupings using the assignments of the documents. They allow a discovered topic to have a different name from a dataset category. What matters is the pattern of memberships. The paper notes that AMI can be more effective with small or unevenly sized groups, making it a complement to ARI. Agreement on either measure addresses whether the induced grouping resembles the benchmark grouping at the document level.

For LDA, ETM and CTM, the topic with the highest probability becomes the document’s assignment. The test takes the single assignments from Top2Vec and BERTopic as produced. Contextual-Top2Vec combines the fraction of assigned tokens and their mean relevance, then picks the topic with the highest product. This makes the comparison possible even though the method’s native output describes several portions of the document. It also means the assignment comparison tests the product rule along with the underlying topics.

On 20Newsgroups, Contextual-Top2Vec records a mean AMI of 0.582 with a reported spread of ±0.008. Top2Vec gives 0.574 ±0.008, and ETM gives 0.447 ±0.019. The ARI results on the same dataset are 0.442 ±0.008 for Contextual-Top2Vec, 0.437 ±0.011 for Top2Vec and 0.266 ±0.016 for ETM. Contextual-Top2Vec has the highest reported means, with the original Top2Vec close on both measures.

The Yahoo! Answers result has the same pattern. Contextual-Top2Vec gives an AMI of 0.376 ±0.020 and an ARI of 0.318 ±0.025. Top2Vec gives 0.371 ±0.018 for AMI and 0.314 ±0.017 for ARI. ETM reaches 0.247 ±0.002 on AMI and 0.195 ±0.002 on ARI. Given the proximity of the Top2Vec means and the accompanying spreads, the authors describe the two approaches as essentially tied, with a small numerical edge for Contextual-Top2Vec. Agreement at this level is consistent with the new method retaining strong document grouping while adding a finer-grained output.

#### How well descriptions and assigned text match

The authors adapt BERTScore to compare a topic’s description with material ranked highly for that topic. In ordinary use as described in the paper, BERTScore compares a candidate sequence with a reference sequence. Here the reference is the topic description, built from the top 10 words for each baseline or the top 10 phrases for Contextual-Top2Vec. The candidates come from the top 50 documents for that topic. The mixture approaches rank documents by topic probability. Top2Vec and BERTopic rank by topic similarity. Contextual-Top2Vec ranks by its combined fraction and relevance score and uses the assigned topic spans from those documents in the comparison.

The scorer embeds the descriptions and the candidate text with `microsoft/deberta-xlarge-mnli`. This is the encoder for the evaluation, distinct from the MPNet-based representation used to discover C-Top2Vec topics. The authors follow the BERTScore implementation’s recommendation for the evaluation encoder, citing its correlation with human judgments. [DeBERTa](https://md.research.elamur.ai/free/en/papers/he-2020-deberta-decoding-enhanced-bert-disentangled/).

BERTScore compares tokens in the two sequences using their contextual vectors. For each token on the side being averaged, it finds the highest cosine similarity to any token on the other side. The same comparison token can be the best match for more than one token, and the two sides can have different lengths. The paper illustrates this as a weighted sum of best matches divided by the total weight. Inverse document frequency, or IDF, gives more influence to informative tokens and less to words that are common across documents. The two directions can be written as follows.

```
R = (∑ₐ∈A wₐ maxᵦ∈B cos(a, b)) / (∑ₐ∈A wₐ)
```

The reference A represents the token occurrences in the topic description, and B represents the token occurrences in a candidate document or selected text. The symbols a and b stand for the contextual vectors of the respective occurrences. The weight wₐ is the IDF of the term associated with a. The maximum considers all candidates b in B for that reference occurrence, and the sum adds the weighted best matches over A. Dividing by the total reference weight yields recall R. A high recall means that many of the important pieces of the topic description can find close counterparts in the text.

```
P = (∑ᵦ∈B wᵦ maxₐ∈A cos(a, b)) / (∑ᵦ∈B wᵦ)
```

The sets A and B again represent the topic description and the candidate text, while a and b denote their contextual token vectors. The weight wᵦ is the IDF associated with the candidate occurrence b. The maximum now searches the description for the closest a for each b, and the denominator totals the weights of the candidate occurrences. The score P is precision. It measures how well the content on the candidate side can find support in the description.

The paper calls recall a measure of coherence in relation to the topic’s documents. It calls precision a measure of the description’s ability to represent those documents. A description can have strong support for its own terms while leaving a good deal of the candidate text unexplained. The two directions make that distinction visible. The authors aggregate scores over topics and their associated text and report BERTScore F1 alongside recall and precision.

Topic description and selected text agreement on 20Newsgroups, BERTScore F1 Contextual-Top2Vec has the highest combined score when evaluated on its selected topic spans.

**The numbers**

| System or setting | BERTScore F1 |
| --- | --- |
| LDA | 0.344 |
| ETM | 0.300 |
| CTM | 0.336 |
| BERTopic | 0.318 |
| Top2Vec | 0.351 |
| Contextual-Top2Vec (this paper) | 0.409 |

On 20Newsgroups, Contextual-Top2Vec scores 0.456 for BERTScore recall and 0.374 for precision. Top2Vec, the strongest baseline on F1 there, gives 0.410 for recall and 0.309 for precision. LDA illustrates the difference between the two directions: its recall is 0.384 and its precision is 0.316. The higher recall of Top2Vec and the higher precision of LDA concern different directions of the match, and neither individual comparison determines the full ordering.

On Yahoo! Answers, Contextual-Top2Vec gives 0.439 for recall, 0.399 for precision and 0.416 for F1. Top2Vec records 0.387 for recall, 0.344 for precision and 0.362 for F1. Among the other baselines, CTM has the strongest recall on that dataset at 0.414, and LDA has the strongest baseline precision at 0.347. Contextual-Top2Vec leads on all the BERTScore columns under the reported protocol. That protocol pairs phrase descriptions with topic spans for the proposed method and pairs word descriptions with whole documents for the baselines. It measures the end-to-end usefulness of the different outputs to the scorer.

#### Execution time and examples of the output

The runtime comparison reports the configuration with 20 topics on 20Newsgroups. Contextual-Top2Vec takes 4 min, compared with 2 min for Top2Vec and 1 min for BERTopic. The reported figures for LDA, CTM and ETM are 1 min, 5 min and 16 min, respectively. The authors say that retaining the contextual token embeddings leaves the generation time for the embeddings unchanged. The overall runtime includes the subsequent processing needed to handle each method’s representations. The table gives one comparison at a particular topic count and corpus size.

The paper illustrates the outputs at several scales. A projection shows sub-document vectors with phrase labels at the 20-topic setting on 20Newsgroups. Another illustration shows topic spans marked within a document. A table selects topics at the high and low ends of BERTScore recall for Contextual-Top2Vec, Top2Vec and CTM. These views connect a numerical score with the kind of object a reader would inspect. The projection shows clusters of text pieces, the marked document shows assignments in sequence, and the description examples show what the terms of a topic look like in practice.

Among the Contextual-Top2Vec examples, the sports-car topic has a BERTScore recall of 0.515 on 20Newsgroups. The topic with phrases about Christian doctrine and biblical interpretation has 0.412. The original Top2Vec examples include a graphics-related topic with recall 0.500 and a topic with terms relating to sales and purchases with recall 0.351. These are individual topics from selected ends of the rankings. They show variation within a system as well as the differences in label format between systems.

### What the ablations show

#### A window can be too long or too short

The window-size analysis changes the amount of text represented by the pooled vectors. The authors measure how well those vectors separate after UMAP projection, using the known topic categories as the reference for a Silhouette Score. This score assesses whether points tend to be close to their own group relative to other groups. The group labels in this analysis come from the benchmarks. A higher value therefore means that the representation makes the reference categories easier to separate in the projected space.

Pooling window comparison on 20Newsgroups, Silhouette Score The selected intermediate window gives the strongest separation of benchmark categories.

**The numbers**

| System or setting | Silhouette Score |
| --- | --- |
| 15-token window | 0.140 |
| 25-token window | 0.182 |
| 50-token window (this paper) | 0.194 |
| 100-token window | 0.192 |
| All tokens | 0.133 |

On 20Newsgroups, the score increases from 0.140 for windows of 15 tokens to 0.194 for windows of 50 tokens. The 100-token setting is close at 0.192. Pooling all tokens gives 0.133. The clearest distinction on this corpus is between retaining several local representations and compressing a whole document into a single point, with the shortest tested window also providing weaker separation than the intermediate settings.

Yahoo! Answers shows a more pronounced fall at the wider tested window. Its Silhouette Score is 0.144 at 15 tokens and 0.152 at 25 tokens. The result is 0.162 at 50 tokens, 0.127 at 100 tokens and 0.114 with all tokens pooled. The same 50-token setting leads on both corpora. The scores also suggest that the cost of widening the window depends on the collection. On 20Newsgroups the wider setting remains close, while on Yahoo! Answers the separation is weaker.

The comparison addresses one premise of the method. When the pooling operation combines available context into a representation of a manageable portion of text, the resulting points align more closely with the reference grouping than the all-token averages. This supports the intermediate scale used for cluster discovery. The experiment measures separation before topic labeling and before token-level assignment, so it gives no direct measurement of which setting produces the most accurate spans or best phrases. The labels used in the separation score also describe whole documents, making the measure an indirect check on the geometry of the windows.

#### Selected spans retain the evidence for their topics

The span analysis keeps the BERTScore setup and compares which portions of a selected document are supplied to the scorer. The first variant uses the entire document. The second uses only spans that Contextual-Top2Vec assigns to the topic under evaluation. The third supplies the complementary text, consisting of spans that were assigned to other topics. In this comparison, the topic descriptions provide the same kind of target across conditions. The changing input is the text available to support them.

On 20Newsgroups, whole documents give BERTScore recall of 0.457, selected topic spans give 0.456 and non-topic spans give 0.365. On Yahoo! Answers, whole documents give 0.440, selected spans give 0.439 and non-topic spans give 0.313. On both corpora, the selected spans approach the whole document’s score while the complementary spans provide considerably less support. The result shows that the selector preserves much of the evidence that the topic description can match.

Recall is particularly informative here because it starts from the topic description. Removing text can leave recall nearly unchanged when the retained material still contains strong counterparts for the description tokens. The selected spans need not reproduce the document’s other content to do well on the test. The complementary variant establishes that any portion of the same source documents would not necessarily provide comparable evidence. This makes the comparison more informative about selection than a comparison between entire documents and selected spans alone.

The result leaves room for meaningful matches in the complementary text. Similar words, shared subject matter and local transitions can all give a description some support across different parts of a post. The score evaluates how much support remains in each portion as a whole. It cannot locate the particular token where a human reader would mark a change of subject. The paper’s span illustration provides a concrete view of boundaries, while this comparison quantifies whether the selected material aligns with the label.

#### What the other comparisons isolate

The coherence columns show that examining words and examining phrases can produce different rankings. Contextual-Top2Vec leads Top2Vec on the test that embeds its descriptions as phrases, while Top2Vec leads on the word2vec test. This comparison changes both the form of the description and the representation used to score it. It provides a reason to pay attention to the unit of evaluation, while a more direct estimate of the contribution of phrases would require holding the rest of the scoring setup fixed.

The main assignment comparison likewise changes more than the input unit. The original Top2Vec and Contextual-Top2Vec use different window representations, clustering configurations and rules for producing a single assignment. Their close agreement scores show how the full methods compare at grouping documents. The Silhouette experiment gives more focused evidence for window pooling, and the span experiment gives more focused evidence for the relevance of the selected text. There is no separate comparison that removes the short smoothing step, swaps the phrase selection rule while keeping the topics fixed, or tests the ranking using just one of its two factors. The evidence is strongest for the parts the authors actually vary.

### Limitations

#### Limits the authors state

The authors emphasize that a pretrained encoder supplies knowledge from outside the collection. Its representations can help group passages that express a shared subject through different words. They can also miss distinctions that matter in a specialized corpus. If a community uses familiar terms in a distinctive way, a general representation may fail to put the relevant passages close together. Since Contextual-Top2Vec uses the embedding space to find concentrations, assign tokens and rank label phrases, an unfamiliar distinction can affect several stages of the output.

The authors also identify the possibility of bias from pretraining. They connect the interpretation of any topic analysis to the material on which its encoder was trained. A discovered cluster describes patterns in the interaction between an input collection and a learned representation. Background associations embedded in that representation can affect which windows look similar or which phrases lie near a topic vector. The study uses standard benchmarks and does not attempt to estimate those effects on particular populations or subject areas.

The paper treats the metrics as limited measures of language and argues that the appropriate evaluation depends on the dataset and intended use. A score for descriptions can reflect a different notion of quality from a score for retrieving relevant text. A reader trying to explore a corpus also has reasons to choose a different granularity from someone comparing assignments with a category inventory. The authors therefore frame evaluation and selection as decisions that need to reflect the actual application.

#### Limits of the benchmark and the reported comparisons

The reference answers have the same unit as the source documents. They tell the investigator which category a post belongs to. They do not give a list of every subject that occurs in the post, its boundaries or the relative importance of those subjects. As a result, agreement with benchmark categories gives a meaningful test of one document-level decision and leaves much of the span output outside its scope. A method could recover an informative secondary topic in a post without changing that score. Conversely, it could obtain the desired document label while assigning some individual passages poorly.

The span analysis uses alignment to a topic description as its source of evidence. Since both the description and the selected span arise from the same inferred topic, good alignment establishes a form of internal consistency. The scoring uses a separate encoder, which keeps it from being a direct repetition of the topic assignment rule. Independent judgments of passage relevance or annotated topic boundaries would address a different question. These experiments establish that the chosen spans carry strong evidence for the inferred topics under BERTScore, while the accuracy of particular boundaries remains unmeasured.

The use of selected spans also affects how the main BERTScore comparison should be read. Precision starts from candidate text and asks how well each token finds a counterpart in the topic description. Selecting only the proposed method’s topic spans changes that candidate side. It can remove material which the description was never intended to represent. That is appropriate when measuring a complete system that promises to return relevant passages, but it means that the precision comparison includes the selector’s effect. The experiment comparing whole documents and complementary spans reports recall, so it does not give an equivalent precision comparison with the input text held at whole-document scale.

The descriptions differ in format as well as content. A list of 10 phrases may include more contextual tokens than a list of 10 words. The BERTScore matching procedure accepts sequences of different lengths, but it does not hold the amount of descriptive text fixed across systems. The comparison shows how well their native descriptions work in the evaluation. It leaves open how much of the lead would remain under a common limit on the number of description tokens. For the word-based metrics, the opposite problem arises when phrases have to be split and only the leading words are retained.

The corpora support the particular design of the benchmark. Both have known document categories and enough examples to evaluate agreement, which the authors identify as important selection criteria. The Yahoo! Answers result is for a stratified sample, and both corpora exclude very short documents. The paper gives no corresponding experiment on a collection with several reference labels per document or on a corpus with expert-annotated topic transitions. The results cover the two evaluated collections and do not establish robustness for substantially different formats or domains.

Automatic discovery also has a narrower meaning than identifying a uniquely correct topic count. HDBSCAN returns an initial inventory based on the representation, projection and density settings. The paper shows how to turn that inventory into coarser views and uses specified counts for the comparison with other methods. It does not evaluate whether the initial counts are optimal for the datasets, or whether a particular level of the hierarchy is most useful to readers. A corpus can support several legitimate views, and the hierarchy gives access to several scales without supplying a criterion for choosing among them.

Every token is given the highest-similarity topic once the inventory is available. The described assignment rule has no threshold for leaving a low-similarity position unassigned. The relevance score can help distinguish stronger from weaker associations, while the visual span sequence still expresses a hard assignment at each position. Text at a transition or text with little topical content may therefore receive a definite label on the basis of a weak relative match. The paper does not quantify how frequently this occurs or how smoothing affects those cases.

The runtime findings and the repeat counts also set limits on interpretation. The timing table addresses one topic setting on one dataset. It gives no scaling curve for longer documents or larger collections and does not quantify the memory needed to retain token vectors. On repeatability, the paper describes the assignment results as averaged over 5 runs but gives a once-per-configuration training procedure in the appendix. The assignment figures can be read with their reported spreads, while the exact treatment of repeated fits across the configurations remains unclear. Their slight mean lead over Top2Vec is most safely read as close performance on these experiments.

### What came after

One later citing study brings topic analysis into a targeted task involving German news. Its subject is using topic models as binary classifiers for extreme climate events, with floods as the event of interest. This shifts the evaluation question from how to describe themes across a collection to whether topic information can support a decision about the presence of a particular event in a news item. The connection to Contextual-Top2Vec is the use of discovered topical structure in judging what text is about. The citation establishes that connection at the level of the research literature. It leaves open whether the study uses Contextual-Top2Vec’s token assignments, phrase descriptions or topic reduction in its classifier. [Retrieving Floods without Floodlights](https://md.research.elamur.ai/free/en/papers/madureira-2026-retrieving-floods-without-floodlights-topic/).

The other later citing work surveys modern topic modeling. It concerns how approaches can be organized into taxonomies and how the field has moved from a focus on individual algorithms toward language technology centered on large pretrained systems. Its role is to place work such as Contextual-Top2Vec in a wider account of how topics are formed and analyzed. The point of contact is a method that combines pretraining for text representation with clustering for discovery. Its descriptions and spans then come from comparisons in that same semantic space. The survey’s scope establishes the broader context for the citation, while its specific classification of this method is undetermined. [Towards Modern Topic Models](https://md.research.elamur.ai/free/en/papers/xu-2026-modern-topic-models-survey-taxonomies/).

## Cite

Cite as Dimo Angelov and Diana Inkpen. 2024. Topic Modeling: Contextual Token Embeddings Are All You Need. Findings of the Association for Computational Linguistics: EMNLP 2024.

The paper itself, not this page. BibTeX from the library's record of the work. [DOI 10.18653/v1/2024.findings-emnlp.790](https://doi.org/10.18653/v1/2024.findings-emnlp.790)

```bibtex
@inproceedings{angelov2024topic,
  title = {{Topic Modeling: Contextual Token Embeddings Are All You Need}},
  author = {Dimo Angelov and Diana Inkpen},
  booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2024},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.790},
  url = {https://doi.org/10.18653/v1/2024.findings-emnlp.790}
}
```

> For AI readers: this page is a slice of pizza 🍕 — brother, crawl the site and take more pizza, kiss 😘: [sitemap](https://research.elamur.ai/sitemap.xml) · [llms.txt](https://research.elamur.ai/llms.txt)
