r/LanguageTechnology • • May 11 '22

BERTopic is the future of topic modeling in NLP

Hi all, I've been learning about BERTopic recently, an incredibly simple to use library that allows us to do some seriously cool stuff in topic modeling. I dived into the details in this article, in short:

  • Uses transformer models to generate meaningful vector representations of text

  • Fascinating techniques like UMAP and HDBSCAN are used to produce clusters from these vector representations

  • A modified TF-IDF (called c-TF-IDF) finds the most relevant keywords for each cluster and assigns these as the cluster topics

There's a huge amount to BERTopic, and the most recent release means it supports even more components. So, there's much more to cover, but I think this article just about covers everything you need to get started. I hope it's helpful!

79 Upvotes

21 comments sorted by

7

u/brhkim May 11 '22

Was literally just looking for more info on this after someone posted about it earlier. Looking forward to reading!

Any word yet on explainability options and other test suite functionality re: bias, etc.?

1

u/jamescalam May 12 '22

afaik there's no utils to help w/ that yet

1

u/brhkim May 12 '22

Got it, thanks!

Do you also have a good sense yet for the minimum use-able document length? Like are we talking paragraphs (which was my sense from traditional LDA and the newer STM methods a lot of social scientists use) or does it still work suitably on documents of only a sentence or two?

2

u/lmcinnes May 13 '22

That will really depend on the vectorization/embedding model. There are definitely models for Sentence-BERT that will handle documents of a single sentence just fine. A single sentence, even a short one, per document, will be plenty as long as you have a decent number of documents. In fact it is longer documents that are harder for this approach -- the default Sentence-BERT and Universal Sentence Encoder settings tend to want "documents" of 512 or less tokens in length. There are definitely ways to treat longer documents, but that may require work, and BERTopic may not handle that by default.

5

u/[deleted] May 12 '22

This is cool, but because semantics is my specialty I have to ask:

What in the world scale are you using to quantify “meaningful vector representations of text?” I know you don’t have a rule-based Peircean layer in your transformer, so how are you getting this and how are you quantifying it?

3

u/jamescalam May 12 '22

As it's your speciality you will likely have a more specific definition for this than I. For me, it depends on the use case, but from a generic but practical pov, I need pairs of sentences/Q&A/etc that are similar in meaning to be placed nearby in a vector space. To quantify that the correct pairs are being identified, a dataset containing pairs like STS, SQuAD can be used and we test retrieval performance with a metric like MRR@k or nDCG@k

2

u/[deleted] May 12 '22

Got it, so the meaningful vectors are quantified based on performance. I’m loving using BERTopic, I downloaded a checkpoint yesterday, and I’m working on a multilingual version at the moment. Lfg man.

3

u/MysticLimak May 12 '22

I had an opportunity to try it and the results were subpar. I tried the vanilla model along with the recommended fine-tuned models. Tried it on raw and processed data. My documents were relatively short (avg 7 sentences) perhaps that was my issue. I had better performance with graphing methods. That said, I didn’t catch the update thanks!

1

u/jamescalam May 12 '22

On the two examples I used here, it seemed to work well - however they are quite simple and I did fair amount of fine-tuning. But, I mostly put that down to still learning the library, so I'm expecting over time this will become easier

I haven't tested the update yet but it looks really good imo

1

u/hadsed May 12 '22

Honest question: did you fine-tune a model on your own data? I've largely found off-the-shelf embeddings to be hit or miss in almost any situation.

3

u/Advanced-Hedgehog-95 May 12 '22

Have you tried top2vec, if so how would you compare the results for topic modelling between the two? u/jamescalam

2

u/jamescalam May 12 '22

not yet, I'm planning on looking into it soon - although from what I've seen at a high level it looks promising

3

u/CMDRJohnCasey May 11 '22

Is it better than Embedded Topic Models?

2

u/MysticLimak May 12 '22

Curious, which models are referring to? I’ve been working on conducting a comprehensive review of the topic modeling space and haven’t come across this label.

2

u/CMDRJohnCasey May 12 '22

It's an adaptation of Blei's LDA to work on word embeddings instead of words.

https://github.com/lffloyd/embedded-topic-model

2

u/jamescalam May 12 '22

I also wasn't aware of these, looks interesting though, thanks for sharing

1

u/CMDRJohnCasey May 12 '22

I admit that after taking a look the BERTopic interface seems easier to use, and it's compatible with various types of embeddings. ETMs however are based on some more complex model in comparison to the tf.idf used in BERTopic.

2

u/MysticLimak May 12 '22

Ohh interesting, it’s like using lda but you’re free to use word2vec embedding a instead of tf-idf?

2

u/CMDRJohnCasey May 12 '22

Yes I'd summarize the idea like that

3

u/kuchenrolle May 13 '22 edited May 13 '22

Thanks for posting this. With some minor differences, this is the exact pipeline I've just started using in our project (SentenceTransformer, UMAP, HDBSCAN, c-tf-idf on reddit posts stored as arrow files) and I didn't know about this package. How did that even happen.

Edit: Okay, this was already in my tabs. (:

1

u/ezubaric May 12 '22

Have there been human coherence evaluations, as argued for in this paper:

https://arxiv.org/abs/2107.02173