Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With BERT Text Classification, ValueError: too many dimensions 'str' error occuring

Trying to make a classifier for sentiments of texts with BERT model but getting ValueError : too many dimensions 'str'

That is the DataFrame for values of train data; so they are train_labels

0   notr
1   notr
2   notr
3   negative
4   notr
... ...
854 positive
855 notr
856 notr
857 notr
858 positive

and there is the code which is producing the error for

train_seq = torch.tensor(tokens_train['input_ids'])
train_mask = torch.tensor(tokens_train['attention_mask'])
train_y = torch.tensor(train_labels.tolist())

At train_y = torch.tensor(train_labels.tolist()); getting error: ValueError: too many dimensions 'str'

can you help me pleaseenter image description here

enter image description here

like image 416
KazımTibetSar Avatar asked Jan 20 '21 07:01

KazımTibetSar


1 Answers

I had the same problem: This worksfor me I guess you need to do it at the beginning of your code after reading csv: df['labels'] = df['labels'].replace(['negative','notr','positive'],[0,1,2])

then split for training and testing from these labels.

like image 95
mojimoji Avatar answered Sep 30 '22 07:09

mojimoji