Favicon of Top2Vec

Top2Vec

An open-source Python library for topic modeling and semantic search, with automatic topic discovery and document-level or token-level analysis.

Screenshot of Top2Vec website

Top2Vec is an open-source Python library for researchers and developers who want to discover themes in text collections and search documents by meaning. It determines the number of topics automatically and connects topics, documents and words through a shared embedding space. The license is BSD-3-Clause.

Its classic model works with short text and doesn't require stop word lists, stemming or lemmatization. You can inspect topic sizes and hierarchies, search topics by keyword, retrieve documents by topic or keyword, and find similar documents or words. These search functions sit alongside topic discovery, so the same model supports both exploring a collection and finding relevant text within it.

Contextual Top2Vec identifies multiple themes within a single document and locates the passages associated with each topic. It provides topic distributions and relevance scores for whole documents, plus topic assignments and scores for individual tokens. This mode supports all-MiniLM-L6-v2 and all-mpnet-base-v2.

The classic model uses Doc2Vec by default, training embeddings on your own collection. That approach can suit large datasets or specialized vocabulary. It also supports pretrained Universal Sentence Encoder and BERT Sentence Transformer embeddings, including universal-sentence-encoder-multilingual and distiluse-base-multilingual-cased for multilingual collections. Doc2Vec can learn from different languages, but it doesn't align those languages with one another. RESTful-Top2Vec can expose a trained model through an API.

Similar to Top2Vec