MaartenGr / MaartenGr/BERTopic
n-gram Keywords need delimiting in OpenAI()
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 think there is a bug in the OpenAI representation model in the way the prompt is generated. The keywords are only separated by a space, not a comma, which is problematic for n-grams > 1.
https://github.com/MaartenGr/BERTopic/blob/244215afebbd982f2d54678f5104af174a72688a/bertopic/representation/_openai.py#L203-L209
Without proper delimiting I end up with a prompt like this:
```
I have a topic that contains the following documents:
- Legumes for mitigation of climate change and the provision of feedstock for biofuels and biorefineries. A review.
- A global spectral library to characterize the world's soil.
- Classification of natural flow regimes in Australia to support environmental flow management.
- Laboratory characterisation of shale properties.
- Effects of climate extremes on the terrestrial carbon cycle: concepts, processes and potential future impacts.
- Threat of plastic pollution to seabirds is global, pervasive, and increasing.
- Pushing the limits in marine species distribution modelling: lessons from the land present challenges and opportunities.
- Land-use futures in the shared socio-economic pathways.
- The WULCA consensus characterization model for water scarcity footprints: assessing impacts of water consumption based on available water remaining (AWARE).
- BIOCHAR APPLICATION TO SOIL: AGRONOMIC AND ENVIRONMENTAL BENEFITS AND UNINTENDED CONSEQUENCES.
The topic is described by the following keywords: food land use global properties climate using review potential change different production environmental data changes high study based years model models time used area future terrestrial plant field analysis management
Based on the information above, extract a short topic label in the following format:
topic:
```
TextGeneration and Cohere look to be okay.
https://github.com/MaartenGr/BERTopic/blob/244215afebbd982f2d54678f5104af174a72688a/bertopic/representation/_textgeneration.py#L130-L136
It would also be helpful to have some way to generate an example prompt with [DOCUMENTS] and [KEYWORDS] applied to help with testing so the user can actually see what's being sent. I've got a custom class bc I'm using ChatGPT on AWS so I've got extra loggers in there but its it difficult to actually see the prompt in context with standard BERTopic.
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 in bertopic/representation/_openai.py at lines 203-209 and compare the keyword formatting with bertopic/representation/_textgeneration.py at lines 130-136. Confirm that n-gram keywords are visibly delimited in the generated OpenAI prompt, and consider how an example prompt with [DOCUMENTS] and [KEYWORDS] could be exposed for testing.
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
- Clearly specified
- Newbie friendliness
- 55/100