You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab中UMAP导入失败求助:ImportError无法从umap导入UMAP

解决Google Colab中UMAP导入错误的潜在问题及方案

1. 安装包名称混淆

你安装的umap是无关第三方包,真正提供UMAP算法的是umap-learn。卸载错误包并安装正确版本:

!pip uninstall -y umap
!pip install umap-learn

2. 版本兼容性问题

BERTopic对UMAP版本有严格依赖,版本不匹配会导致导入失败。建议安装BERTopic官方推荐的兼容版本:

!pip install umap-learn==0.5.3

3. Colab预装依赖冲突

Colab默认预装部分库,可能与手动安装的包产生冲突。按以下顺序在干净运行时安装依赖:

  • 重启Colab运行时
  • 依次执行安装命令:
!pip install sentence_transformers
!pip install umap-learn
!pip install bertopic

4. 导入路径修正

部分UMAP版本需要从umap.umap_模块导入UMAP类,替换原有导入语句:

from umap.umap_ import UMAP
修正后的完整代码
from bertopic import BERTopic
from sentence_transformers import SentenceTransformer
from umap.umap_ import UMAP

docs = abstracts
sentence_model = SentenceTransformer("neuml/pubmedbert-base-embeddings")
embeddings = sentence_model.encode(docs, show_progress_bar = False)

topic_model = BERTopic()
topics, probs = topic_model.fit_transform(docs, embeddings = embeddings)

topic_model.visualize_documents(docs, embeddings = embeddings)

内容的提问来源于stack exchange,提问作者konichiwow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 06:03:23