MaartenGr / MaartenGr/BERTopic
Question/request about representative document truncation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hi Maarten,
I'm curious about the truncation at 255 characters of representative documents in both the `OpenAI` and `TextGeneration` representation models (at least).
https://github.com/MaartenGr/BERTopic/blob/58d90bc65e95a11718e63a0834809d156dcf431d/bertopic/representation/_textgeneration.py#L143C1-L147C67
I imagine it's helpful if you are paying for an API, but if using a local text generation model e.g. as in your Llama2 google colab example, is there any other reason that the representative documents have to be cut down so hard?
Could we have some control over the truncation e.g. add a `truncate: int = 255` parameter to the representation models and then:
```
for doc in docs:
doc = doc[:truncate] if truncate else doc
to_replace += f"- {doc}\n"
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with bertopic/representation/_textgeneration.py at the linked truncation logic, then locate the corresponding OpenAI representation implementation. Check how representative documents are passed into each model and whether existing tests cover their prompts. Done means both models expose configurable truncation while retaining the current default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100