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

Fix skip_special_tokens for Wav2Vec2CTCTokenizer._decode #29311

Conversation

msublee
Copy link
Contributor

@msublee msublee commented Feb 27, 2024

What does this PR do?

Fixes #29243

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ArthurZucker

@msublee msublee changed the title Fix skip_special_tokens process for Wav2Vec2CTCTokenizer._decode Fix skip_special_tokens for Wav2Vec2CTCTokenizer._decode Feb 28, 2024
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.

Thanks! Do you mind adding a small test to make sure all special tokens are now skipped?

@msublee
Copy link
Contributor Author

msublee commented Mar 1, 2024

I'm unfamiliar with this kind of PR (to big repo). Where and How should I add a small test?

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.

There is a test here:

def test_tokenizer_decode_added_tokens(self):

but it seems to not properly test so let's update it 😉

@msublee msublee force-pushed the fix_wav2vec2ctctokenizer_skip_special_tokens branch from 5b0057e to faa316a Compare March 6, 2024 06:20
@msublee
Copy link
Contributor Author

msublee commented Mar 6, 2024

I updated the test!
Also, I excluded the pad_token filtering in _decode since pad_token is used as CTC-blank token and is filtered in convert_tokens_to_string.

processed_chars = list(filter(lambda char: char != self.pad_token, chars))

Finally, I applied this update to both Wav2Vec2Tokenizer and Wav2Vec2CTCTokenizer.

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.

Overall LGTM, we need to test a bit more, and I'll ask @sanchit-gandhi his expertise on this model and a second look 👀


self.assertEqual(batch_tokens, ["HELLO<unk>!?!?$$$", "BYE BYE<unk>$$$"])
self.assertEqual(batch_tokens_2, ["HELO!?!?", "BYE BYE"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's add a new token, like "<new_tokens>" and test that we can encode decode as we expect for both fast and slow tokenizers! 🤗

Copy link
Contributor Author

@msublee msublee Mar 7, 2024

Choose a reason for hiding this comment

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

Is there a fast Wav2Vec2CTCTokenizer? I can't find it!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry there is no fast tokenizer here! my bad. Let's just use other tokens than <unk>!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the late. I updated it.

@ArthurZucker ArthurZucker removed the request for review from sanchit-gandhi March 25, 2024 09:54
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

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.

Perfect thanks!

@ArthurZucker ArthurZucker merged commit 15cd687 into huggingface:main Apr 2, 2024
18 checks passed
@msublee msublee deleted the fix_wav2vec2ctctokenizer_skip_special_tokens branch April 3, 2024 01:12
ArthurZucker pushed a commit that referenced this pull request Apr 22, 2024
* Fix skip_special_tokens process for Wav2Vec2CTCTokenizer._decode

* Fix skip_special_tokens for Wav2Vec2CTCTokenizer._decode

* Exclude pad_token filtering since it is used as CTC-blank token

* Add small test for skip_special_tokens

* Update decoding test for added new token
itazap pushed a commit that referenced this pull request May 14, 2024
* Fix skip_special_tokens process for Wav2Vec2CTCTokenizer._decode

* Fix skip_special_tokens for Wav2Vec2CTCTokenizer._decode

* Exclude pad_token filtering since it is used as CTC-blank token

* Add small test for skip_special_tokens

* Update decoding test for added new token
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.

skip_special_tokens for Wav2Vec2CTCTokenizer does not work expectedly.
3 participants