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

Implement max character check #398

Merged
merged 4 commits into from
Nov 17, 2023
Merged

Conversation

samlhuillier
Copy link
Contributor

Returns unknown token for strings greater than param maxInputCharsPerWord (defaulting to 100). Fixes #397

@samlhuillier samlhuillier changed the title Implement max character check per token Implement max character check Nov 16, 2023
Copy link
Collaborator

@xenova xenova left a comment

Choose a reason for hiding this comment

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

Thanks so much! Just note that the config is instantiated with the tokenizer.json, and as a result, relies on the exact same casing... which in this case, means it has to be max_input_chars_per_word

See https://huggingface.co/Xenova/bert-base-uncased/raw/main/tokenizer.json:
image

I also think it will be useful to add a test case for this here, something like:
https://github.com/xenova/transformers.js/blob/4e4148cb5ce7f4a9265f58b4eeb660c64bed0386/tests/tokenizers.test.js#L42-L50.

src/tokenizers.js Outdated Show resolved Hide resolved
src/tokenizers.js Outdated Show resolved Hide resolved
src/tokenizers.js Outdated Show resolved Hide resolved
@xenova xenova merged commit c8bbdd4 into huggingface:main Nov 17, 2023
@xenova
Copy link
Collaborator

xenova commented Nov 17, 2023

Thanks so much! 🚀 The same output as the python library is obtained now:

It took  1.5605939999222755 ms to tokenize
Encoded:  [101,  100, 1009, 100, 1027, 1027, 102]
Decoded:  [CLS] [UNK] + [UNK] = = [SEP]

(and the time taken is now in the same range as the python library: 1.67ms for python, 1.56ms for JS... not extensive tests, just ran a few times and took the average)

@samlhuillier
Copy link
Contributor Author

Amazing! I shall update my package :)

@xenova
Copy link
Collaborator

xenova commented Nov 18, 2023

A new release (2.8.1) will be out shortly, but in the meantime, you can install from source (GitHub) if this fix is urgent.

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.

[Question] Tokenizing a base64 for string is very slow?
2 participants