question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: too many dimensions 'str'

See original GitHub issue

To 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:closed
  • Created 4 years ago
  • Comments:32 (9 by maintainers)

github_iconTop GitHub Comments

17reactions
ThilinaRajapaksecommented, May 14, 2020

For anyone else running into this. this is usually due to having strings in the labels column.

16reactions
Benarlcommented, Mar 3, 2020

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)))

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found