MaartenGr / MaartenGr/BERTopic

flan-t5 for

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

Hi @MaartenGr,

I hope you are doing well. I am getting the following error when using the flan-t5 model for topic representation. Any solution for this? Thanks

```
from transformers import pipeline
from bertopic.representation import TextGeneration

prompt = "I have a topic described by the following keywords: [KEYWORDS]. Based on the previous keywords, what is this topic about?"

# Create your representation model
generator = pipeline('text2text-generation', model='google/flan-t5-base')
representation_model = TextGeneration(generator)

topic_model_t5 = BERTopic(representation_model=representation_model)
```

Error:

----> 2 topics, probs = topic_model_t5.fit_transform(docs)
3 print(topic_model_t5.get_topic_info())

[/usr/local/lib/python3.10/dist-packages/bertopic/representation/_textgeneration.py](https://localhost:8080/#) in extract_topics(self, topic_model, documents, c_tf_idf, topics)
145
146 # Prepare prompt
--> 147 truncated_docs = [truncate_document(topic_model, self.doc_length, self.tokenizer, doc) for doc in docs]
148 prompt = self._create_prompt(truncated_docs, topic, topics)
149 self.prompts_.append(prompt)

TypeError: 'NoneType' object is not iterable

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 traceback entry point in bertopic/representation/_textgeneration.py, especially extract_topics around line 147, and reproduce the provided flan-t5 example. Trace why truncate_document receives or produces None, then verify that BERTopic.fit_transform completes without the reported TypeError.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.