MilaNLProc /
honest
A Python package to compute HONEST, a score to measure hurtful sentence completions in language models. Published at NAACL 2021.
64/100 healthLoading repository data…
MilaNLProc / repository
A python package to run contextualized topic modeling. CTMs combine contextualized embeddings (e.g., BERT) with topic models to get coherent topics. Published at EACL and ACL 2021 (Bianchi et al.).
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
.. image:: https://img.shields.io/pypi/v/contextualized_topic_models.svg :target: https://pypi.python.org/pypi/contextualized_topic_models
.. image:: https://github.com/MilaNLProc/contextualized-topic-models/workflows/Python%20package/badge.svg :target: https://github.com/MilaNLProc/contextualized-topic-models/actions
.. image:: https://readthedocs.org/projects/contextualized-topic-models/badge/?version=latest :target: https://contextualized-topic-models.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
.. image:: https://img.shields.io/github/contributors/MilaNLProc/contextualized-topic-models :target: https://github.com/MilaNLProc/contextualized-topic-models/graphs/contributors/ :alt: Contributors
.. image:: https://img.shields.io/badge/License-MIT-blue.svg :target: https://lbesson.mit-license.org/ :alt: License
.. image:: https://pepy.tech/badge/contextualized-topic-models :target: https://pepy.tech/project/contextualized-topic-models :alt: Downloads
.. image:: https://colab.research.google.com/assets/colab-badge.svg :target: https://colab.research.google.com/drive/1fXJjr_rwqvpp1IdNQ4dxqN4Dp88cxO97?usp=sharing :alt: Open In Colab
Selected from shared topics, language and repository description—not editorial ratings.
MilaNLProc /
A Python package to compute HONEST, a score to measure hurtful sentence completions in language models. Published at NAACL 2021.
64/100 healthje-recopuerto /
A python package to run contextualized topic modeling. CTMs combine contextualized embeddings (e.g., BERT) with topic models to get coherent topics. Published at EACL and ACL 2021 (Bianchi et al.).
56/100 health.. image:: https://raw.githubusercontent.com/aleen42/badges/master/src/medium.svg :target: https://medium.com/towards-data-science/contextualized-topic-modeling-with-python-eacl2021-eacf6dfa576 :alt: Medium Blog Post
.. image:: https://img.shields.io/badge/youtube-video-red :target: https://www.youtube.com/watch?v=n1_G8K07KoM :alt: Video Tutorial
Contextualized Topic Models (CTM) are a family of topic models that use pre-trained representations of language (e.g., BERT) to support topic modeling. See the papers for details:
Pre-training is a Hot Topic: Contextualized Document Embeddings Improve Topic Coherence. ACL. https://aclanthology.org/2021.acl-short.96/Cross-lingual Contextualized Topic Models with Zero-shot Learning. EACL. https://www.aclweb.org/anthology/2021.eacl-main.143/.. image:: https://raw.githubusercontent.com/MilaNLProc/contextualized-topic-models/master/img/logo.png :align: center :width: 200px
Our new topic modeling family supports many different languages (i.e., the one supported by HuggingFace models) and comes in two versions: CombinedTM combines contextual embeddings with the good old bag of words to make more coherent topics; ZeroShotTM is the perfect topic model for task in which you might have missing words in the test data and also, if trained with multilingual embeddings, inherits the property of being a multilingual topic model!
The big advantage is that you can use different embeddings for CTMs. Thus, when a new embedding method comes out you can use it in the code and improve your results. We are not limited by the BoW anymore.
We also have Kitty <https://contextualized-topic-models.readthedocs.io/en/latest/kitty.html>_! A new submodule that can be used to create a human-in-the-loop
classifier to quickly classify your documents and create named clusters.
.. image:: https://raw.githubusercontent.com/MilaNLProc/contextualized-topic-models/master/img/logo_kitty.png :align: center :width: 200px
You can look at our medium_ blog post or start from one of our Colab Tutorials:
.. |colab1_2| image:: https://colab.research.google.com/assets/colab-badge.svg :target: https://colab.research.google.com/drive/1fXJjr_rwqvpp1IdNQ4dxqN4Dp88cxO97?usp=sharing :alt: Open In Colab
.. |colab2_2| image:: https://colab.research.google.com/assets/colab-badge.svg :target: https://colab.research.google.com/drive/1bfWUYEypULFk_4Tfff-Pb_n7-tSjEe9v?usp=sharing :alt: Open In Colab
.. |colab3_3| image:: https://colab.research.google.com/assets/colab-badge.svg :target: https://colab.research.google.com/drive/1upTRu4zSm1VMbl633n9qkIDA526l22E_?usp=sharing :alt: Open In Colab
.. |kitty_colab| image:: https://colab.research.google.com/assets/colab-badge.svg :target: https://colab.research.google.com/drive/18mKzaKnmBlBOHb1oiS5MtaTSyq47ys2X?usp=sharing :alt: Open In Colab
+--------------------------------------------------------------------------------+------------------+ | Name | Link | +================================================================================+==================+ | Combined TM on Wikipedia Data (Preproc+Saving+Viz) (stable v2.3.0) | |colab1_2| | +--------------------------------------------------------------------------------+------------------+ | Zero-Shot Cross-lingual Topic Modeling (Preproc+Viz) (stable v2.3.0) | |colab2_2| | +--------------------------------------------------------------------------------+------------------+ | Kitty: Human in the loop Classifier (High-level usage) (stable v2.2.0) | |kitty_colab| | +--------------------------------------------------------------------------------+------------------+ | SuperCTM and β-CTM (High-level usage) (stable v2.2.0) | |colab3_3| | +--------------------------------------------------------------------------------+------------------+
TL;DR
+ In CTMs we have two models. CombinedTM and ZeroShotTM, which have different use cases.
+ CTMs work better when the size of the bag of words **has been restricted to a number of terms** that does not go over **2000 elements**. This is because we have a neural model that reconstructs the input bag of word, Moreover, in CombinedTM we project the contextualized embedding to the vocab space, the bigger the vocab the more parameters you get, with the training being more difficult and prone to bad fitting. This is **NOT** a strict limit, however, consider preprocessing your dataset. We have a preprocessing_ pipeline that can help you in dealing with this.
+ Check the contextual model you are using, the **multilingual model one used on English data might not give results that are as good** as the pure English trained one.
+ **Preprocessing is key**. If you give a contextual model like BERT preprocessed text, it might be difficult to get out a good representation. What we usually do is use the preprocessed text for the bag of word creating and use the NOT preprocessed text for BERT embeddings. Our preprocessing_ class can take care of this for you.
+ CTM uses `SBERT`_, you should check it out to better understand how we create embeddings. SBERT allows us to use any embedding model. You might want to check things like `max length <https://www.sbert.net/examples/applications/computing-embeddings/README.html#input-sequence-length>`_.
Installing
Important: If you want to use CUDA you need to install the correct version of the CUDA systems that matches your distribution, see pytorch_.
Install the package using pip
.. code-block:: bash
pip install -U contextualized_topic_models
Models
An important aspect to take into account is which network you want to use:
the one that combines contextualized embeddings
and the BoW (`CombinedTM <https://contextualized-topic-models.readthedocs.io/en/latest/combined.html>`_) or the one that just uses contextualized embeddings (`ZeroShotTM <https://contextualized-topic-models.readthedocs.io/en/latest/zeroshot.html>`_)
But remember that you can do zero-shot cross-lingual topic modeling only with the `ZeroShotTM <https://contextualized-topic-models.readthedocs.io/en/latest/zeroshot.html>`_ model.
Contextualized Topic Models also support supervision (SuperCTM). You can read more about this on the `documentation <https://contextualized-topic-models.readthedocs.io/en/latest/introduction.html>`_.
.. image:: https://raw.githubusercontent.com/MilaNLProc/contextualized-topic-models/master/img/ctm_both.jpeg
:align: center
:width: 800px
We also have `Kitty <https://contextualized-topic-models.readthedocs.io/en/latest/kitty.html>`_: a utility you can use to do a simpler human in the loop classification of your
documents. This can be very useful to do document filtering. It also works in cross-lingual setting and
thus you might be able to filter documents in a language you don't know!
References
----------
If you find this useful you can cite the following papers :)
**ZeroShotTM**
::
@inproceedings{bianchi-etal-2021-cross,
title = "Cross-lingual Contextualized Topic Models with Zero-shot Learning",
author = "Bianchi, Federico and Terragni, Silvia and Hovy, Dirk and
Nozza, Debora and Fersini, Elisabetta",
booktitle = "Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume",
month = apr,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2021.eacl-main.143",
pages = "1676--1683",
}
**CombinedTM**
::
@inproceedings{bianchi-etal-2021-pre,
title = "Pre-training is a Hot Topic: Contextualized Document Embeddings Improve Topic Coherence",
author = "Bianchi, Federico and
Terragni, Silvia and
Hovy, Dirk",
booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 2: Short Papers)",
month = aug,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.acl-short.96",
doi = "10.18653/v1/2021.acl-short.96",
pages = "759--766",
}
Language-Specific and Multilingual
----------------------------------
Some of the examples below use a multilingual embedding model
:code:`paraphrase-multilingual-mpnet-base-v2`.
This means that the representations you are going to use are mutlilingual.
However you might need a broader coverage of languages or just one specific language.
Refer to the page in the documentation to see how to choose a model for another language.
In that case, you can check `SBERT`_ to find the perfect model to use.
Here, you can read more about `language-specific and mulitlingual <https://contextualized-topic-models.readthedocs.io/en/latest/language.html>`_.
Quick Overview
--------------
You should definitely take a look at the `documentation <https://contextualized-topic-models.readthedocs.io/en/latest/introduction.html>`_
to better understand how these topic models work.
Combined Topic Model
Here is how you can use the CombinedTM. This is a standard topic model that also uses contextualized embeddings. The good thing about CombinedTM is that it makes your topic much more coherent (see the paper https://arxiv.org/abs/2004.03974). n_components=50 specifies the number of topics.
.. code-block:: python
from contextualized_topic_models.models.ctm import CombinedTM
from contextualized_topic_models.utils.data_preparation import TopicModelDataPreparation
from contextualized_topic_models.utils.data_preparation import bert_embeddings_from_file
qt = TopicModelDataPreparation("all-mpnet-base-v2")
training_dataset = qt.fit(text_for_contextual=list_of_unpreprocessed_documents, text_for_bow=list_of_preprocessed_documents)
ctm = CombinedTM(bow_size=len(qt.vocab), contextual_size=768, n_components=50) # 50 topics
ctm.fit(training_dataset) # run the model
ctm.get_topics(2)
*Advanced Notes:
abdulsamie10 /
EmojifyAI is a Python package that suggests relevant emojis for a given input sentence using natural language processing techniques. It employs the BERT model to generate embeddings for the input sentence and the emojis' descriptions, and then finds the most similar emojis using cosine similarity.
WilliamGTa /
A python package to run contextualized topic modeling. CTMs combine contextualized embeddings (e.g., BERT) with topic models to get coherent topics. Published at EACL and ACL 2021 (Bianchi et al.).
52/100 health