# Supervised BERTopic with multiple topics per document

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%3E%5C
**Category:** Models\
**Created:** [November 9, 2023, 9:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630 "2023-11-09T09:30:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![noahts](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@noahts](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnoahts)%5C
**Post date:** [November 9, 2023, 9:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F1 "2023-11-09T09:30:14Z")

</div>

Hello -  
We have a collection of about 100.000 Danish articles that have topics assigned to them by profesionals. We would like to build a model that can help them with suggestions when new articles need to be cataloged with topics.

I have looked into BERTopic and I can see there is a guide on how to do supervised topic modeling ([https://maartengr.github.io/BERTopic/getting\_started/supervised/supervised.html](https://maartengr.github.io/BERTopic/getting_started/supervised/supervised.html)), and there is another guide on how to deal with the situation where there is more than one topic per document ([https://maartengr.github.io/BERTopic/getting\_started/distribution/distribution.html](https://maartengr.github.io/BERTopic/getting_started/distribution/distribution.html)). I am unsure if it is possible/easy to combine the two approaches.

Does anybody have experience with such a task? Is BERTopic a good framework here?

Thanks,

/Noah

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 9, 2023, 12:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F2 "2023-11-09T12:09:13Z")

</div>

Lookup the calculate\_probabilities=True flag. This should generate the probabilities of each topic so you are doing both steps in one go.

Alternatively you can also consider a two step process like the one outlined here [Topic modelling and multiclass text classification using transformers | by Paulo Yun Cha | Oct, 2023 | Medium](https://medium.com/@pauloyc/topic-modelling-and-multiclass-text-classification-using-transformers-6fc3ee69c15d)

---

<div class="post-metadata">

**Author:** ![noahts](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@noahts](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnoahts)%5C
**Post date:** [November 9, 2023, 2:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F3 "2023-11-09T14:40:24Z")

</div>

Thanks, that’s certainly relevant and much appreciated.

I’m sorry I didn’t state it clearly before, but the setup is that each of the documents in our training data has multiple topics assigned (3-6, not more than that), and I am not sure how to feed that into the model in either of the setups described. What am I missing?

Thanks again,  
/Noah

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 12, 2023, 7:35am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F4 "2023-11-12T07:35:11Z")

</div>

How many topics do you have? You can consider a slightly different approach like in this workbook if you don’t have a large (20+) number of topics.

> **[Multi label Classification of PubMed Articles](https://www.kaggle.com/code/owaiskhan9654/multi-label-classification-of-pubmed-articles)**
>
> Explore and run machine learning code with Kaggle Notebooks | Using data from PubMed MultiLabel Text Classification Dataset MeSH

or this one

> **[SciBERT Multi Label Classification](https://www.kaggle.com/code/prithvijaunjale/scibert-multi-label-classification)**
>
> Explore and run machine learning code with Kaggle Notebooks | Using data from \[Private Datasource\]

---

<div class="post-metadata">

**Author:** ![noahts](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@noahts](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnoahts)%5C
**Post date:** [November 13, 2023, 10:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F5 "2023-11-13T10:17:27Z")

</div>

Thanks again. I’ll definitely have a look at it, but we have thousands of topics, so I am not sure if this will work. But it might be used as inspiration for new ideas!

---

<div class="post-metadata">

**Author:** ![panigrah](https://avatars.discourse-cdn.com/v4/letter/p/bb73d2/32.png) [@panigrah](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpanigrah)%5C
**Post date:** [November 13, 2023, 12:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F6 "2023-11-13T12:07:46Z")

</div>

What is the ratio of topics to documents? If 1k of topics for 100k docs, perhaps need to look at this as a hierarchical classification or is it a summarisation problem where you are trying to create a keyword summary for each doc.

Perhaps scikit will work better for this. See the example here. [Working With Text Data — scikit-learn 1.3.2 documentation](https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html)

---

<div class="post-metadata">

**Author:** ![juhoinkinen](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/juhoinkinen/32/32436_2.png) [@juhoinkinen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjuhoinkinen)%5C
**Post date:** [November 16, 2023, 8:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F7 "2023-11-16T20:19:27Z")

</div>

@noahts You could take a look at [Annif](https://github.com/NatLibFi/Annif).

If you have a vocabulary (a list of all the possible topics), then Annif could be readily applied to your task. Or maybe you can construct a vocabulary from the all the topics already assigned to articles?

Annif is a more traditional ML tool for (extreme) multilabel classification intended for libraries, archives and museums. The YSO vocabulary in use at the demo page [annif.org](http://annif.org) has a vocabulary with over 30 000 concepts (i.e. topics).

---

<div class="post-metadata">

**Author:** ![juhoinkinen](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/juhoinkinen/32/32436_2.png) [@juhoinkinen](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjuhoinkinen)%5C
**Post date:** [November 16, 2023, 8:22pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fsupervised-bertopic-with-multiple-topics-per-document%2F61630%2F8 "2023-11-16T20:22:41Z")

</div>

The [YSO vocabulary is the General Finnish ontology](https://finto.fi/yso/en/?clang=en) maintained at National Library of Finland.

(Yeah, as a new user at the forum I had a limit of max. 2 links per post.)
