Comments (2)
I found that the values remained constant until the PartOfSpeech representation module and switching it to another one resolved the issue. The problem appears to be initially caused by the deduplication method (list(set())) used at lines 121 and 130. Because the hash function used for generating set keys is seeded at the start of the interpreter (seed can be overridden using PYTHONHASHSEED env variable), the output of such deduplication is different with each run. This behavior causes word_indices at line 144 to change with each run. Which is later problematic when sorting keywords with the same c-TF-IDF as they are arranged differently.
Amazing, great catch! That's also a nasty habit of mine so I wouldn't be surprised if that happens in other places as well.
Part 1
Sort the word_indices at line 144 using numpy. This will ensure consistent ordering of words, should be faster than built-in sort, and will transform them into numpy array for further operations.
Remove the numpy array creation at line 145, as its handled by previous step.
Sounds good and a minimal change as well, which I prefer!
When looking at the PoS code, I noticed that word_indices at line 144 are generated using the following condition if words_lookup.get(keyword) which ignores the first word returned by get_feature_names_out. It looks like an error.
I'm not sure if I understand correctly. Why would the first word be ignored?
from bertopic.
I'm not sure if I understand correctly. Why would the first word be ignored?
That's because of how the values are converted to booleans. At line 140 a lookup is created that maps each word to its index (0 based), which is later used at line 144 to extract the indices. This lookup output is filtered using the condition if words_lookup.get(keyword)
to prevent None
values, as .get
method on a dictionary returns None
as a default value if the key isn't found. However, the same condition will also evaluate to False
for the index 0, causing it to be ignored.
Example
[v for v in [1, None, 2, 0, 3] if v]
# [1, 2, 3]
from bertopic.
Related Issues (20)
- Supervised topic model generating different topics to training data HOT 3
- Where is the full data set of embeddings? HOT 3
- Visualization in html page HOT 1
- Guided Modeling: Problem with seed_topic_list HOT 2
- Utilizing the GPU of MacBook Pro M3 to accelerate the process of fit_transform HOT 1
- Could we know the weights of each topic? HOT 6
- Can't reproduce same results when using cuml version of UMAP and HDBSCAN HOT 3
- approximate_distribution returns only 0s HOT 5
- Feature (Watsonx): representations using Llama-3-70b and Mixtral-8x7b HOT 1
- Which hyper parameter mostly influence the number of topics for Chinese texts? HOT 3
- Zero-Shot Topic Modelling and Topics Over Time HOT 1
- Loading of saved model returns Error: "This BERTopic instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
- Creating representations using IBM Watsonx LLMs HOT 5
- c_tf_idf_ is None when using zero shot topic modeling. HOT 1
- Issue with Scikit-learn 1.5.0
- Error at Combining clustered topics with the zeroshot model HOT 2
- Compare LDA, NMF, LSA with BERTopic (w/ embedding: all-MiniLM-L6-v2 + dim_red: UMAP + cluster: HDBSCAN) HOT 1
- AttributeError: 'BertModel' object has no attribute 'attn_implementation' #30965 HOT 3
- Zeroshot Topic Modeling With no Embedding Model HOT 1
- Extending ".visulize_document_datamap" with "label_over_points"-flag
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bertopic.