You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mT5 additional_special_tokens seems not work #9747
I want add some special tokens such as <CON_START> . But T5tokenizer/MT5tokenizer both can't tokenize correctly after using additional_special_tokens parameter. It still split these special tokens to subwords.
It works when using OpenAIGPTTokenizer additional_special_tokens parameter. It's clear that after declare additional_special_tokens parameter, OpenAIGPTTokenizer tokenize as one word rather split it.
The version of transformers is 4.2.2
And I'm not sure this problem is related with issue624 in T5 which talk about SentencePiece extra vocab.
Hi! Could you either post a link to your notebook or your code as actual code? Images makes it impossible to copy/paste or for others to search with similar issues. Thanks.
Hi! Could you either post a link to your notebook or your code as actual code? Images makes it impossible to copy/paste or for others to search with similar issues. Thanks.
Here is colab notebook link. Thanks for your reply.
Hi! Indeed, this is a bit misleading. Special tokens are considered as those that were in the pre-training, that is: unknown tokens, bos tokens, eos tokens, etc.
If you want to use special tokens that you use as special tokens, I would argue it is better to define them as simple tokens. Therefore doing the following:
>>>fromtransformersimportMT5Tokenizer, MT5ForConditionalGeneration
... importtorch
... special_tokens= ['<POS>', '<NEG>','<CON_START>','<START>','<END>'] # Set the special tokens
... mt5_add_tokenizer=MT5Tokenizer.from_pretrained("google/mt5-small")
... mt5_add_tokenizer.add_tokens(special_tokens)
... print(mt5_add_tokenizer.tokenize("<POS> <CON_START> the biscuits and gravy were . <START>"))
Thank you very much, it works well.
I was confused by issue5940 which mentioned "special tokens are carefully handled by the tokenizer (they are never split)". If use add_token() method, the additional simple tokens may still split?
In addition, the code in Colab notebook as above link, OpenaiTokenizer should use add_tokens method rather than add_special_tokens (define them as a simple tokens) ?
Activity
LysandreJik commentedon Jan 25, 2021
Hi! Could you either post a link to your notebook or your code as actual code? Images makes it impossible to copy/paste or for others to search with similar issues. Thanks.
PiggyFan commentedon Jan 28, 2021
Here is colab notebook link. Thanks for your reply.
https://colab.research.google.com/drive/1fbp7VvnUvbf5r8CSitOg2pDZyM47y9xj?usp=sharing
LysandreJik commentedon Jan 28, 2021
Hi! Indeed, this is a bit misleading. Special tokens are considered as those that were in the pre-training, that is: unknown tokens, bos tokens, eos tokens, etc.
If you want to use special tokens that you use as special tokens, I would argue it is better to define them as simple tokens. Therefore doing the following:
You'll get the following output:
Let me know if that makes sense.
PiggyFan commentedon Jan 29, 2021
Thank you very much, it works well.
I was confused by issue5940 which mentioned "special tokens are carefully handled by the tokenizer (they are never split)". If use add_token() method, the additional simple tokens may still split?
In addition, the code in Colab notebook as above link, OpenaiTokenizer should use add_tokens method rather than add_special_tokens (define them as a simple tokens) ?
LysandreJik commentedon Jan 29, 2021
For tokens that cannot be identified as being either:
eos_tokenbos_tokencls_tokenunk_tokenpad_tokensep_tokenmask_tokenThen I would recommend using the
add_tokenmethod. These tokens shouldn't split either:PiggyFan commentedon Feb 1, 2021
Thank for your help and recommend.
Victordongy commentedon Apr 6, 2022
Hi it seems
add_tokensnot working withAutoTokenizer, but work with specific-defined tokenizer likeBertTokenizer,ArthurZucker commentedon Jun 1, 2023
He! Thanks for reporting. This should be fixed by #23909