Comments (3)
Apologies, managed to try it on GPU enabled cloud server and it was significantly faster.
from bertopic.
Yes! Using a GPU is highly recommended to speed-up the inference at the sentence-transformers stage.
However, if you do not have a GPU available to you, then you can actually use TF-IDF instead since BERTopic
allows for custom embeddings to be passed:
from bertopic import BERTopic
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import TfidfVectorizer
# Create TF-IDF sparse matrix
docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data']
vectorizer = TfidfVectorizer(min_df=5)
embeddings = vectorizer.fit_transform(docs)
# Run BERTopic with embeddings
model = BERTopic(allow_st_model=True)
topics, probabilities = model.fit_transform(docs, embeddings)
Note that I used the parameter allow_st_model
which basically uses a sentence-transformer model to fine-tune the topic representation. This should be very efficient regardless of using a GPU since you would only need to embed a few hundred words. However, you can set this to False
if you do not want to be using a sentence-transformer model at all.
EDIT: Did not saw your response but I will leave this up here for those who are interested in other embedding methods.
from bertopic.
Thanks @MaartenGr ! This was very useful.
from bertopic.
Related Issues (20)
- Best-performing embedding models? HOT 1
- Skip topic representation when reducing topics wiht nr_topic parameter HOT 1
- Issue with loading BERTopic model. 'NNDescent' object has no attribute '_bit_trees' HOT 3
- Problem with fitting and transforming model HOT 2
- Semantic Sentence Tokenization HOT 1
- self._c_tf_idf can make more efficient use of vectorizer model HOT 3
- Drop support for Python 3.7 HOT 3
- Issue when using topic representation HOT 1
- Reducing Outliers of Loaded Model HOT 1
- `IndexError: list index out of range` when using zeroshot_topic_list in 0.16.1 HOT 10
- Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28`How to slove this problem?
- Alternatively, you can pin your installation to the old version, e.g. `pip install openai==0.28` HOT 1
- Add support for Python 3.10+ HOT 2
- [inhomogeneous shape unresolved] [Colab] ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part. HOT 1
- Huggingface transformer does not load as expected HOT 3
- BERTopic with large dataset (10-20 Million) HOT 1
- datamap visualisation does not work. HOT 1
- datamap visulisation does not work. HOT 3
- Request: Zeroshot option to assign unassigned documents to outliers rather than reclustering HOT 3
- should we reduce the dimensionality of topic_model.topic_embeddings_ ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bertopic.