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.

Behavior of shift_tokens_right on padded input_ids

See original GitHub issue

System Info

  • transformers version: 4.20.1

Who can help?

@patrickvonplaten @patil-suraj @sgugger

Reproduction

When I applied shift_tokens_right on a padded input_ids, I get this

from transformers import AutoTokenizer
from transformers.models.bart.modeling_flax_bart import shift_tokens_right

tokenizer = AutoTokenizer.from_pretrained("roberta-base")
labels = tokenizer("My dog is cute", padding='max_length', max_length=8, return_tensors='np').input_ids
decoder_input_ids = shift_tokens_right(labels, tokenizer.pad_token_id, tokenizer.eos_token_id)

print(tokenizer.batch_decode(labels))
# ['<s>My dog is cute</s><pad><pad>']

print(tokenizer.batch_decode(decoder_input_ids))
# ['</s><s>My dog is cute</s><pad>']

Expected behavior

Should the desired behavior of shift_token_right be the following?

print(tokenizer.batch_decode(labels))
# ['<s>My dog is cute</s><pad><pad>']

print(tokenizer.batch_decode(decoder_input_ids))
# ['</s><s>My dog is cute<pad><pad>']

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
duongna21commented, Sep 23, 2022

@patrickvonplaten Thanks for elaborating on it. Totally agree with you that it doesn’t matter with seq2seq training. I just tried to make sure it doesn’t create any side-effect somewhere 😄.

1reaction
LysandreJikcommented, Jul 26, 2022

Pinging @patil-suraj and @patrickvonplaten regarding the shift_tokens_right method and its purpose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[SOLVED!] Behavior of shift_tokens_right on padded input_ids ...
When I applied shift_tokens_right on a padded input_ids, I get this ... Should the desired behavior of shift_token_right be the following?
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