BERTopic icon indicating copy to clipboard operation
BERTopic copied to clipboard

'float' object is not subscriptable

Open brandon-incubeta opened this issue 4 years ago • 5 comments

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)

brandon-incubeta avatar Feb 01 '22 09:02 brandon-incubeta

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.

MaartenGr avatar Feb 01 '22 10:02 MaartenGr

mask = reviews['title'].str.len() >=1 reviews= reviews.loc[mask] reviews['title'] = reviews['title'].astype('str')

fsysean avatar Feb 02 '22 02:02 fsysean

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!

MaartenGr avatar Mar 20 '22 07:03 MaartenGr

Nones

I guess It solves the issue after changing these things

TakshPanchal avatar Jun 08 '22 08:06 TakshPanchal

a very helpful thread for newbs... thanks.

simonjackman avatar Aug 04 '22 08:08 simonjackman