Coder Social home page Coder Social logo

Does GPU help? about bertopic HOT 3 CLOSED

maartengr avatar maartengr commented on May 10, 2024
Does GPU help?

from bertopic.

Comments (3)

lppier avatar lppier commented on May 10, 2024 1

Apologies, managed to try it on GPU enabled cloud server and it was significantly faster.

from bertopic.

MaartenGr avatar MaartenGr commented on May 10, 2024 1

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.

lppier avatar lppier commented on May 10, 2024

Thanks @MaartenGr ! This was very useful.

from bertopic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.