Fine-Tuned Topic Modeling

Machine Learning
Introduced by
Bianchi et al.; Grootendorst, M.
Year
2020–2022
Type
Fine-tuned neural topic model
Family
Deep learning / NLP / CV

What does it do?

Fine-tuned topic modeling uses pre-trained language models, such as BERT or Sentence-BERT, to discover latent topics in document collections.

Instead of relying on word co-occurrence counts, it encodes documents as contextual embeddings and groups them, and the encoder can optionally be further trained on domain text first. It is often considered when classical models such as LDA or NMF give weak topics on short or specialised texts, although the gain depends on the corpus and should be checked with coherence measures.

The intuition behind the method

Classical topic models such as LDA treat text largely as bags of words and miss how meaning depends on context. Neural topic models instead encode each document as a dense vector that reflects its meaning in context, and topics are formed by grouping and summarising these vectors. If the encoder is further trained on domain text, such as scientific abstracts, clinical notes or social media posts, it can learn domain vocabulary and phrasing that generic pre-training may not cover. Whether the resulting topics are more readable than LDA topics on a given corpus has to be checked with coherence measures and by inspecting the topics.

History

Probabilistic topic modelling is represented by Latent Dirichlet Allocation (Blei et al., 2003), which established the standard probabilistic approach to topic modelling. Bianchi et al. (2021) extended contextualized topic models to cross-lingual settings with zero-shot learning. The BERTopic preprint (Grootendorst, 2022) presents a neural topic modelling approach that uses a class-based TF-IDF procedure to describe topics.

When to use it

Choose this approach when documents are short (for example posts or abstracts) or use specialised vocabulary (biomedical, legal, financial), and LDA or NMF gives poor coherence on that corpus. It also suits multilingual collections when a multilingual sentence encoder is available, since one encoder can handle mixed-language text. Avoid it when the analysis depends on an explicit generative model with topic-word probabilities, as in LDA, when the corpus is very small (fewer than a few hundred documents, where clusters of dense embeddings become unstable), or when compute is severely limited, because embedding a large corpus and running fine-tuning costs considerably more than fitting LDA. Before adopting it, compare it with LDA or NMF on the same corpus using coherence measures.

Limitations and considerations

  • Substantially higher compute and memory demands than classical probabilistic topic models, since every document must be encoded before any topic is formed.
  • No explicit generative probabilistic model: the pipeline does not produce posterior topic distributions comparable to LDA's document-topic and topic-word parameters.
  • The number of topics is not controlled by a likelihood criterion such as LDA's perplexity. In density-based clustering pipelines it is shaped indirectly by settings such as the neighbourhood size and minimum cluster size, while variational neural models take it as an explicit hyperparameter.
  • Fine-tuning requires curating in-domain text and a hyperparameter search, because aggressive adaptation can overwrite general language knowledge in the pre-trained encoder.
  • Density-based clustering can leave documents unassigned, so the topic shares reported may not account for the whole corpus.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Contextual encoders can represent the same word differently depending on its surrounding text, whereas bag-of-words models such as LDA treat each word independently of its context.
  • Pre-trained encoders carry general language knowledge, so usable topics can be obtained from a modest in-domain corpus without training a language model from scratch.
  • A multilingual sentence encoder places texts in several languages in one embedding space, so topics can be discovered across languages without separate per-language models.
  • Fine-tuning on unlabelled domain text can adapt the encoder to the corpus vocabulary, which may make topic labels easier for domain experts to interpret.
  • Because the encoder is a separate component of the pipeline, a better pre-trained model can be substituted without changing the clustering and term-scoring steps.

Applications

  • Thematic analysis of scientific literature, systematically identifying research fronts and gaps.
  • Social media analysis, where short posts give classical LDA little word co-occurrence signal.
  • Customer feedback and review mining in specialized product domains.
  • Clinical note and biomedical text exploration, where jargon-heavy vocabulary may lower LDA coherence.
  • Multilingual corpus analysis combining texts in several languages without building separate models.
  • News and policy document monitoring, tracking how topics evolve over time in large archives.

How it works

How it works

1

Each document or sentence is encoded as a dense contextual vector by a pre-trained language model such as Sentence-BERT or all-MiniLM. The encoder can be used frozen, as in transfer learning, or it can first be adapted to domain text (see the fine-tune step), which may help where generic pre-training under-represents specialised vocabulary.

2

The embeddings are reduced in dimensionality, commonly with UMAP, and then grouped with a density-based or centroid-based method such as HDBSCAN or k-means, so that each cluster is a candidate topic. Documents that do not fit any dense group can be discarded or assigned to a noise category. This keeps the remaining clusters tight but means that not every document receives a topic.

3

Each cluster is described by its most distinctive terms, scored by contrasting term frequency within the cluster against the rest of the corpus. The top-ranked terms serve as the human-readable topic label.

4

When domain adaptation is needed, the language model is further trained on unlabelled in-domain text, using masked language modelling or a contrastive objective, before the embeddings are computed. Supervised fine-tuning is possible only if externally labelled documents with topic assignments are available; this turns the task into supervised classification rather than unsupervised topic discovery, and such labels are often not available. This stage is only needed for adaptation, so it can be skipped when a suitable pre-trained encoder already exists.

5

Topics are assessed with coherence measures such as C_V or NPMI, computed over a reference corpus, together with topic diversity and inspection of the top-N words per topic. Performance on a downstream classification or retrieval task using held-out data gives an extrinsic check on topic quality.

Common pitfalls

  • Judging topic quality only by reading the top words. Coherence (C_V or NPMI) and topic diversity should be computed alongside inspection.
  • Fine-tuning on a small domain corpus, which can cause catastrophic forgetting of general language knowledge in the encoder.
  • Choosing a generic encoder such as all-MiniLM without checking whether its pre-training text resembles the study domain.
  • Leaving random seeds unset for UMAP and the clustering step, so that repeated runs give different topics and the results cannot be reproduced.
  • Reporting only topic labels without coherence and diversity scores, which makes it hard to compare runs or to set the method against LDA or NMF baselines.

Frequently asked questions

How is fine-tuned topic modeling different from standard LDA?

LDA models word co-occurrence with a probabilistic generative process and treats each word independently of context. Fine-tuned neural topic modeling encodes entire sentences or documents into contextual embeddings before discovering topics, capturing polysemy and semantic similarity that word-level counts do not represent. The tradeoff is that LDA provides explicit topic-word probability distributions, which this pipeline does not produce.

Do I always need to fine-tune the language model backbone, or can I use a frozen encoder?

A frozen general-purpose encoder (like all-MiniLM-L6-v2 or paraphrase-multilingual-mpnet) can work well for many domains and is simpler to deploy than a fine-tuned backbone. Fine-tuning the backbone is most beneficial when your corpus uses highly specialized vocabulary (clinical, legal, or proprietary terminology) that is underrepresented in the pre-training corpus.

How do I choose the number of topics?

It depends on the variant. In density-based clustering pipelines the number of clusters emerges from HDBSCAN's density estimation, and granularity is steered indirectly through UMAP's n_neighbors and HDBSCAN's min_cluster_size. For variational neural topic models, the number of topics is a hyperparameter that is typically chosen by maximizing coherence (C_V or NPMI) over a validation set.

What metrics should I report in a paper?

Report topic coherence (C_V or NPMI computed over a held-out or external reference corpus), topic diversity (the proportion of unique words across all top-N topic words), and ideally an extrinsic metric such as classification accuracy on a downstream task. Compare against LDA or NMF as baselines.

Is this approach suitable for very small datasets?

It is risky below a few hundred documents. Clustering dense embeddings of a tiny corpus yields unstable, low-diversity topics. For small corpora, consider LDA with informative priors, or aggregate short documents before embedding.

Related methods

Sources

  1. Bianchi, F., Terragni, S., Hovy, D., Nozza, D., & Fersini, E. (2021). Cross-lingual Contextualized Topic Models with Zero-shot Learning. Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics, 1676–1683.

    Open DOI reference
  2. Grootendorst, M. (2022). BERTopic: Neural topic modeling with a class-based TF-IDF procedure. arXiv preprint arXiv:2203.05794.

    Open publication reference