1

I'm trying to import bertopic but it gives the following error. I tried different versions and re create a new environment. But it's still same. I'm using Apple M2 Pro processor

lib version
BERTopic 0.15.0
HDBSCAN 0.8.29
umap-learn 0.5.3 

TypeError                                 Traceback (most recent call last)
Cell In[3], line 4
      2 import pandas as pd
      3 # import matplotlib.pyplot as plt
----> 4 from bertopic import BERTopic
      5 import gensim
      6 import gensim.corpora as corpora

File ~/miniforge3/envs/bertopic/lib/python3.8/site-packages/bertopic/__init__.py:1
----> 1 from bertopic._bertopic import BERTopic
      3 __version__ = "0.15.0"
      5 __all__ = [
      6     "BERTopic",
      7 ]

File ~/miniforge3/envs/bertopic/lib/python3.8/site-packages/bertopic/_bertopic.py:37
     34 from typing import List, Tuple, Union, Mapping, Any, Callable, Iterable
     36 # Models
---> 37 import hdbscan
     38 from umap import UMAP
     39 from sklearn.preprocessing import normalize

File ~/miniforge3/envs/bertopic/lib/python3.8/site-packages/hdbscan/__init__.py:1
----> 1 from .hdbscan_ import HDBSCAN, hdbscan
      2 from .robust_single_linkage_ import RobustSingleLinkage, robust_single_linkage
      3 from .validity import validity_index

File ~/miniforge3/envs/bertopic/lib/python3.8/site-packages/hdbscan/hdbscan_.py:40
     37 from .plots import CondensedTree, SingleLinkageTree, MinimumSpanningTree
     38 from .prediction import PredictionData
---> 40 FAST_METRICS = KDTree.valid_metrics + BallTree.valid_metrics + ["cosine", "arccos"]
     42 # Author: Leland McInnes <[email protected]>
     43 #         Steve Astels <[email protected]>
     44 #         John Healy <[email protected]>
     45 #
     46 # License: BSD 3 clause
     47 from numpy import isclose

TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'builtin_function_or_method'

1 Answer 1

4

This is tracked in a Github issue and is due to a change in scikit-learn.

To avoid this bug, you could install scikit-learn < 1.3.0. (pip install -U scikit-learn==1.2.2) The creator of HDBScan has a fix in mind, so likely at some point this will work with later scikit-learn versions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.