Machine Learning · Insper · E3.3

BERTopic

Advanced approach

Where do the topic names come from?

The path of this part

  1. Names by handc-TF-IDF on the 24 clusters, checked
  2. Tune the wordsstop words; KeyBERTInspired
  3. A fitted model as a toolsearch, new documents, plots
Each stage answers one question: can the names be reproduced by hand? → can they be improved without re-clustering? → what else does a fitted model do?
Stage 1 · can the names be reproduced by hand?

c-TF-IDF on the posts, by hand

Join the posts of each HDBSCAN cluster (−1 too), replace line breaks and tabs by spaces, count with a stop-word list, apply the class-based TF-IDF (c-TF-IDF). Predict: what will the outliers be named after?

clusterpoststop words, by hand
−1431space jpeg launch image
1567god jesus people church
0520team game hockey play
1566image graphics package processing
955card mode vesa vga
2352moon lunar prize money
Same top-5 words as BERTopic for every topic: True. HDBSCAN numbers clusters in no order; BERTopic renumbers them by size (cluster 1 → topic 0).
Stage 2 · can they be improved without re-clustering?

Tune the words, not the clusters

Predict. Topic 2 (image processing) with BERTopic's default vectorizer, which has no stop-word list: what will its top words look like?

topic 2, named by…top words
default vectorizerimage and for of to it or the graphics with
stop words removedimage graphics package processing software data analysis …
KeyBERTInspiredgraphical graphics rtrace plots tools interactive plotting …
KeyBERTInspired re-ranks the candidate words by the cosine between each word's embedding and the topic's typical documents. update_topics changes the words; the assignments stay identical.
Stage 3 · what else does a fitted model do?

A fitted model as a tool

read

get_topic(t) top words and scores · get_representative_docs(t) typical documents

search and label

find_topics("rocket engines") by meaning · transform(new_docs) new documents, no refit

draw

visualize_topics(), visualize_barchart(), visualize_documents(): interactive Plotly charts

merge and reassign

reduce_topics, reduce_outliers: the advanced part of E3.4 measures what they cost

Practice · at home

Your turn (advanced)

  • Another representation: MaximalMarginalRelevance(diversity=0.5) against KeyBERTInspired.
  • Search by meaning: three queries of your own with find_topics.
  • The outliers' words: do space, jpeg, launch, image describe the posts of topic −1?

In the lab: steps 8 to 10. Next: the advanced slides of E3.4.