transformers: `add_prefix_space` won't be respected by Llama tokenizer
System Info
transformersversion: 4.38.2- Platform: Linux-6.5.0-14-generic-x86_64-with-glibc2.35
- Python version: 3.10.13
- Huggingface_hub version: 0.21.3
- Safetensors version: 0.4.2
- Accelerate version: 0.27.2
- Accelerate config: not found
- PyTorch version (GPU?): 2.0.1+cu117 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
With sentencepiece==0.2.0 and protobuf==4.25.3 installed
Who can help?
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
>>> from transformers import AutoTokenizer
>>> tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf", local_files_only=True, add_prefix_space=False)
>>> tokenizer.tokenize("overheard")
['▁over', 'he', 'ard']
Also tried add_dummy_prefix_space=False, the output is still the same.
Expected behavior
The tokenize result should not add prefix space (SPIECE_UNDERLINE)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 19 (1 by maintainers)
Commits related to this issue
- add_prefix_space param added to llamatokenizerfast #29625 — committed to huggingface/transformers by deleted user 2 years ago
- add prefix space ignored in llama #29625 — committed to huggingface/transformers by deleted user 2 years ago
- add prefix space ignored in llama #29625 (#30964) * add prefix space ignored in llama #29625 * adding test with add_prefix_space=False * ruff --------- Co-authored-by: Ita Zaporozhets <it... — committed to huggingface/transformers by itazap 2 years ago
Looking forward to it 😃 @itazap Actually, would be great if one could pass
add_prefix_spaceto the tokenize function itself, instead of needing to pass it when creating the tokenizer. Currently it is really unflexible if one wants to tokenize separate parts and then concatenate them afterwards without such a functionality.Please tag me on any prs, happy to give feedback on this in general.
This will be supported very soon, @itazap is working on making all of this a lot simpler and clearer! And yes, that is what’s happening but shoul;d not, we should not need sentencepiece dependency to update prefix space. That’s a mistake on my par sorry about it 😢
But it does not seem to be taken into account. @itazap would be nice if you can investigate and open a PR to make sure it forces from flow:
I kinda agree with you and will see what I can do on the
tokenizersside, but this might need a lot of changes (supporting a new argument) and can already be done but with the attribute that needs to be set at each call, not super optimalclosing as #28881 fixed it!