'float' object is not subscriptable
This was based on the Amazon Review dataset on kaggle.
Here is my code to exectute
#Select only the name, rating, review text, review title column
raw = data[["name", "reviews.rating", 'reviews.text', 'reviews.title']]
#only select Kindle products
paperwhite_check = raw['name'].str.contains("Kindle")
paperwhite = raw[paperwhite_check == True]
paperwhite = paperwhite.reset_index()
paperwhite = paperwhite.drop('index', axis=1)
from bertopic import BERTopic
topic_model = BERTopic()
topic_model.fit_transform(paperwhite["reviews.title"])
This is the error I receive
/usr/local/lib/python3.7/dist-packages/sentence_transformers/models/Transformer.py in tokenize(self, texts)
85 batch1, batch2 = [], []
86 for text_tuple in texts:
---> 87 batch1.append(text_tuple[0])
88 batch2.append(text_tuple[1])
89 to_tokenize = [batch1, batch2]
TypeError: 'float' object is not subscriptable
I run the model on a dataset with 51 entries it works. (Selecting only Paperwhite)
I run the model on a dataset with 336 entries it doesn't work.
I run the model with 1596 entries it works again. (Full dataset)
Hmmm, I believe you are passing a pandas series and not a list of strings. Could you convert your documents to a list of strings and see what happens? Also, make sure that every single document is a string and does not contain any Nones.
mask = reviews['title'].str.len() >=1 reviews= reviews.loc[mask] reviews['title'] = reviews['title'].astype('str')
It has been a while since this issue has been active. So I am closing this issue for now. However, if you want to discuss this further, let me know and I'll make sure to reopen the issue!
Nones
I guess It solves the issue after changing these things
a very helpful thread for newbs... thanks.