MaartenGr / MaartenGr/BERTopic

Utilizing the GPU of MacBook Pro M3 to accelerate the process of fit_transform

Open
#1,992 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
920
Avg merge
22h 24m
Merged PRs (30d)
5

Description

I am running BERTopic on a MacBook Pro M3, and the text data is nearly 190,000 Chinese sentences. It has taken two full days and still is not finished. By now it has run 2928 minutes. I wonder if that's because I did not utilize the GPU, but I do not know how. Any help is much appreciated!

Following is the code I used:

sampled_data2 = data1['2grams_filtered'].tolist()
sampled_data2_as_strings = [' '.join(tokens) for tokens in sampled_data2]

sentence_model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
embeddings = sentence_model.encode(sampled_data2_as_strings, show_progress_bar=True)

stopWord_Path='hit_stopwords.txt'
stopWord=[]
with open(stopWord_Path,'r',encoding='utf-8') as fr:
for word in fr.readlines():
stopWord.append(word.strip())

umap_model = UMAP(n_neighbors=100, n_components=2, min_dist=0.1, metric='cosine', random_state=42)

hdbscan_model = HDBSCAN(min_cluster_size=5, metric='euclidean', cluster_selection_method='eom', prediction_data=True,
min_samples=5, gen_min_span_tree=True)

vectorizer_model = CountVectorizer(ngram_range=(1, 2), stop_words=stopWord)

ctfidf_model = ClassTfidfTransformer(seed_words=['台独','蔡英文', '佩洛西'], bm25_weighting=True, reduce_frequent_words=True)

topic_model = BERTopic(embedding_model="distiluse-base-multilingual-cased-v1",
language="multilingual",
verbose=True,
calculate_probabilities=True,
umap_model=umap_model,
hdbscan_model=hdbscan_model,
vectorizer_model=vectorizer_model,
ctfidf_model=ctfidf_model,
nr_topics="auto",
top_n_words=15,
min_topic_size=120)

topics, probs = topic_model.fit_transform(sampled_data2_as_strings, embeddings)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BERTopic.fit_transform entry point and the supplied SentenceTransformer.encode call, then trace how the provided UMAP and HDBSCAN models are executed. Done means the issue can state whether this configuration supports GPU use on an M3 Mac and document the supported path or limitations.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.