MaartenGr / MaartenGr/BERTopic

ValueError: setting an array element with a sequence. Trying guided topic modelling.

Open
#1,421 6 comments 4 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

Get the following error:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

When running the following code (copied straight from docs):

    from sklearn.datasets import fetch_20newsgroups

    docs = fetch_20newsgroups(
        subset="all", remove=("headers", "footers", "quotes")
    )["data"]

    seed_topic_list = [
        ["drug", "cancer", "drugs", "doctor"],
        ["windows", "drive", "dos", "file"],
        ["space", "launch", "orbit", "lunar"],
    ]

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

python 3.11

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 by running the documented Python example with BERTopic and the provided seed_topic_list to reproduce the ValueError. Trace the guided topic modelling path used by fit_transform; done means the example runs successfully without the inhomogeneous-shape error and produces topics and probabilities.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.