error AttributeError: 'tuple' object has no attribute 'logits'

See original GitHub issue

Environment info

AttributeError Traceback (most recent call last) <ipython-input-4-594fed3b7299> in <module>() 6 input = tokenizer.encode(sequence, return_tensors=“pt”) 7 mask_token_index = torch.where(input == tokenizer.mask_token_id)[1] ----> 8 token_logits = model(input).logits 9 mask_token_logits = token_logits[0, mask_token_index, :] 10 top_5_tokens = torch.topk(mask_token_logits, 5, dim=1).indices[0].tolist()

AttributeError: ‘tuple’ object has no attribute ‘logits’

  • transformers version: Successfully installed sacremoses-0.0.43 sentencepiece-0.1.91 tokenizers-0.8.1rc2 transformers-3.3.1
  • Platform: Masked Language Modeling - Colab PyTorch
  • Python version: Python 3.6.9
  • PyTorch version (GPU?):
  • Tensorflow version (GPU?):
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

Who can help

Information

Model I am using (Bert, XLNet …):

The problem arises when using:

  • [V ] the official example scripts: (give details below)
  • my own modified scripts: (give details below)

The tasks I am working on is:

  • an official GLUE/SQUaD task: (give the name)
  • my own task or dataset: (give details below)

To reproduce

Steps to reproduce the behavior:

  1. Summary of the tasks Open Colab Pytorch
  2. Masked Language Modeling example

Expected behavior

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
patrickvonplatencommented, Oct 7, 2020

Can you replace:

token_logits = model(input).logits

by

token_logits = model(input, return_dict=True).logits

and see if the error persists?

0reactions
WeiShi-9commented, Oct 16, 2022

I fixed this problem by update transfromers from 3.0.2 to 4.23.1(the latest version in 2022.10.16)

Read more comments on GitHub >

github_iconTop Results From Across the Web

The question-answering example in the doc throws an ...
Admittedly I am a beginner to HuggingFace, though I do have some ... AttributeError: 'tuple' object has no attribute 'start_logits'```.
Read more >
AttributeError: 'tuple' object has no attribute 'log_softmax'
This is a well known problem. Try one the following solutions: disable aux_logits when the model is created here by also passing ...
Read more >
Python AttributeError: 'tuple' object has no attribute
AttributeError: 'tuple' object has no attribute. Learn Data Science with. This error occurs when attempting to access the values of a tuple incorrectly....
Read more >
If input.dim() == 2 and bias is not None: AttributeError: 'tuple ...
If input.dim() == 2 and bias is not None: AttributeError: 'tuple' object has no attribute 'dim.
Read more >
AttributeError: 'tuple' object has no attribute in Python
The Python "AttributeError: 'tuple' object has no attribute" occurs when we access an attribute that doesn't exist on a tuple. To solve the ......
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