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.

[HuggingFace] AttributeError("'str' object has no attribute 'item'",)

See original GitHub issue

Describe the bug I get this error every time I try fine tuning BERT with W&B: AttributeError("'str' object has no attribute 'item'",) …whether it’s your example in Google Colab or it’s my own fine-tuning experiment with my own machine & dataset.

To Reproduce

  1. Go to https://colab.research.google.com/drive/1SQ-FOgji8AiyrQ08sIVfDiA8OUw4bC12?usp=sharing#scrollTo=JL9OqcavmYVb
  2. Click Run All
  3. See error

Screenshots image

Additional context Python 3.7.9 wandb 0.10.12 torch 1.7.0+cu110 transformers 4.1.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

25reactions
acd424commented, May 6, 2021

I found the the docs on migrating from previous packages useful - paragraph 4.

https://huggingface.co/transformers/migration.html

I added ‘return_dict=False’ to my model argument and it worked as it should.

8reactions
MehmetKUTANcommented, May 18, 2021

When running the Bert algorithm, I have the same problem, I get the AttributeError (“‘str’ object has no attribute ‘item’”,) error in the loss.item () statement. solution: Since there is an unequaled value to the total_train_loss value, When I set the value for “loss” I did “return_dict = False”. Problem solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[HuggingFace] AttributeError("'str' object has no attribute 'item'",)
When running the Bert algorithm, I have the same problem, I get the AttributeError ("'str' object has no attribute 'item'",) error in the...
Read more >
AttributeError: 'str' object has no attribute 'size' - Stack Overflow
python - Huggingface error during training: AttributeError: 'str' object has no attribute 'size' - Stack Overflow. Stack Overflow for Teams – ...
Read more >
'str' object has no attribute 'dtype' when pretraining wav2vec2 ...
I was trying to pretrain the word2vec2.0 using this file. However, I get the following error when I reach the training phase: AttributeError...
Read more >
Item = {key: torch.tensor(val[idx]) for key, val in self.encodings ...
I get this error when loading the new test file (it does not have label) ... in self.encodings.items()} AttributeError: 'list' object has no...
Read more >
SebastianS/github-issues · Datasets at Hugging Face
AbstractFileSystem) -> bool: AttributeError: 'EntryPoint' object has no attribute 'AbstractFileSystem' ``` ## Suggested fix ...
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