ValueError: too many dimensions 'str'
See original GitHub issueTo Reproduce Steps to reproduce the behavior:
Here is my Colab Notebook you can run to to see the error https://gist.github.com/lenyabloko/adcb84ac04e5e10b7391d49b5bd0539c
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-0b9dcdf94c77> in <module>()
71
72 # Train the model
---> 73 model.train_model(train_df)
74
75 # Evaluate the model
1 frames
/usr/local/lib/python3.6/dist-packages/simpletransformers/classification/classification_model.py in train_model(self, train_df, multi_label, output_dir, show_running_loss, args, eval_df, verbose, **kwargs)
261 ]
262
--> 263 train_dataset = self.load_and_cache_examples(train_examples, verbose=verbose)
264
265 os.makedirs(output_dir, exist_ok=True)
/usr/local/lib/python3.6/dist-packages/simpletransformers/classification/classification_model.py in load_and_cache_examples(self, examples, evaluate, no_cache, multi_label, verbose, silent)
757
758 if output_mode == "classification":
--> 759 all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.long)
760 elif output_mode == "regression":
761 all_label_ids = torch.tensor([f.label_id for f in features], dtype=torch.float)
ValueError: too many dimensions 'str'
The problem arises when using
from simpletransformers.classification import ClassificationModel
import pandas as pd
prefix = '/content/'
train_df = pd.read_csv(prefix + 'train.csv', header=None)
train_df=train_df.drop(index=0)
model = ClassificationModel('roberta', 'roberta-base')
model.train_model(train_df)
Issue Analytics
- State:
- Created 4 years ago
- Comments:32 (9 by maintainers)
Top Results From Across the Web
too many dimensions 'str' error occuring - Stack Overflow
Trying to make a classifier for sentiments of texts with BERT model but getting ValueError : too many dimensions 'str'.
Read more >PyTorch ValueError: too many dimensions 'str'
I am trying to use torchvision.transforms to apply transformtation the training data, but getting the following traceback error: Traceback ...
Read more >ValueError: too many dimensions 'str' - Hugging Face Forums
I am getting multiple error when I try to train my model using trainer. I can't figure out how to resolve this Value...
Read more >pytorch运行错误:ValueError: too many dimensions 'str' - 博客园
pytorch运行错误:ValueError: too many dimensions 'str'. 问题:. 本人在使用BERT进行微调的时候,在读取数据的时候 ...
Read more >Basic Important Functions Of PyTorch - Morioh
2 # Intializing tensor with a string thows exception ----> 3 k = torch.tensor(['snehit']). ValueError: too many dimensions 'str' Hosted on Jovian.ml
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else running into this. this is usually due to having strings in the
labels
column.I figure it out, it comes from train_df[“label”], if you look closer you have actually a list (of list) of str, and not a list (of list) of int.
So you have to convert every line with this code :
train_df["label"] = train_df["label"].apply(lambda x: list(map(int, x)))