Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Whisper Tokenizer] Skip special tokens when decoding with timestamps #23945

Merged
merged 2 commits into from
Jun 2, 2023

Conversation

sanchit-gandhi
Copy link
Contributor

What does this PR do?

Decoding with timestamps always returns the special tokeniser tokens, ignoring the argument skip_special_tokens. This PR fixes this behaviour to respect skip_special_tokens, both with and without timestamp decoding.

Before:

from transformers import WhisperTokenizer

tokenizer = WhisperTokenizer.from_pretrained("openai/whisper-tiny")

encoded_input = [
    50258, 50363, 50364, 634, 575, 12525, 22618, 1968, 6144,
    35617, 20084, 1756, 311, 589, 307, 534, 10281, 934,
    439, 293, 50676, 50676, 393, 4411, 294, 309, 457,
    707, 295, 33301, 286, 392, 6628, 13, 50836, 50257,
]

tokenizer.decode(encoded_input, decode_with_timestamps=True, skip_special_tokens=True)

Output:

<|startoftranscript|><|notimestamps|><|0.00|> He has grave doubts whether Sir Frederick Layton's work is really Greek after all and<|6.24|><|6.24|> can discover in it but little of rocky Ithaca.<|9.44|><|endoftext|>

Now:

tokenizer.decode(encoded_input, decode_with_timestamps=True, skip_special_tokens=True)

Output:

<|0.00|> He has grave doubts whether Sir Frederick Layton's work is really Greek after all and<|6.24|><|6.24|> can discover in it but little of rocky Ithaca.<|9.44|>

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch and thanks for adding tests 😉

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 2, 2023

The documentation is not available anymore as the PR was closed or merged.

@sanchit-gandhi sanchit-gandhi requested a review from sgugger June 2, 2023 10:17
Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

@sanchit-gandhi sanchit-gandhi merged commit c9cf337 into huggingface:main Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants