MaartenGr / MaartenGr/BERTopic

ImportError: cannot import name 'StaticEmbedding' from 'sentence_transformers.models'

Open
#2,331 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

### Have you searched existing issues? 🔎

- [x] I have searched and found no existing issues

### Desribe the bug

Title pretty much says it all.

```
BERTopic/bertopic/backend/_sentencetransformers.py:4
from sentence_transformers.models import StaticEmbedding
```

Looks like this is an issue with versions. SentenceTransformer didn't add Model2Vec till
https://github.com/MaartenGr/BERTopic/pull/2245
but there's no requirement that the new version of SentenceTransformer is installed.

I'll submit a PR to fix this, but I don't know what solution you'd prefer. I think the best option is to move that import from line 4 to line 58, since it appears that's the only place it's needed. I'll make a PR and test it.

### Reproduction

```python
from bertopic.backend._sentencetransformers import SentenceTransformerBackend

```

### BERTopic Version

v0.17.0

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 bertopic/backend/_sentencetransformers.py, especially the import at line 4 and the StaticEmbedding use around line 58. Run the reported import of SentenceTransformerBackend with the affected dependency versions and inspect the project requirements. Done means the backend imports successfully without requiring an incompatible SentenceTransformer version.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.