Skip to content

Fix #35447 Tokenizer does not split text according to newly added input tokens - #35455

Closed
jiongjiongli wants to merge 1 commit into
huggingface:mainfrom
jiongjiongli:fix-tokenizer-text-split
Closed

jiongjiongli wants to merge 1 commit into
huggingface:mainfrom
jiongjiongli:fix-tokenizer-text-split

Conversation

@jiongjiongli

Copy link
Copy Markdown

Fix Bug

#35447 : Tokenizer does not split text according to newly added input tokens

Resolution

Method Trie.split: Add steps to ignore partial match that should be removed

@ArthurZucker and @itazap

@jiongjiongli
jiongjiongli force-pushed the fix-tokenizer-text-split branch 2 times, most recently from cf128ad to fbd9036 Compare January 1, 2025 00:19

@ArthurZucker ArthurZucker left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey ! Sorry but I cannot seem to reproduce!
image

@jiongjiongli

Copy link
Copy Markdown
Author

Hey ! Sorry but I cannot seem to reproduce! image

Hello @ArthurZucker , this issue repos using tokenizer.add_tokens(["red", "e"]) rather than tokenizer.add_tokens(["e"]) .

Below is repro code and actual result:

# Code:
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-cased", use_fast=False)
tokenizer.add_tokens(["red", "e"])
output_tokens = tokenizer.tokenize("read")
print(f"Output tokens: {output_tokens}")

# Actual Output:
Output tokens: ['read']

@jiongjiongli
jiongjiongli force-pushed the fix-tokenizer-text-split branch from 12b6aa8 to 70d51bf Compare January 12, 2025 22:19
@ArthurZucker
ArthurZucker removed the request for review from Rocketknight1 January 13, 2025 10:28
…newly added input tokens

The root reason is Trie.split method didn't ignore partial match that should be removed

Add test case to token split
@jiongjiongli
jiongjiongli force-pushed the fix-tokenizer-text-split branch from 70d51bf to 56c52db Compare January 20, 2025 04:37

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Right, sorry!
Could you add another test with another model for example? 🤗
Seems to not work for ? for example or for emojis

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Thanks for digging into the Trie.split behaviour! Since then src/transformers/tokenization_utils.py was removed in #40936 (the Trie now lives in src/transformers/tokenization_python.py), and #35447 has been closed, so this branch can't be merged anymore. If you can still reproduce the issue on main, please open a fresh PR there with the extra test cases (e.g. ? / emojis) mentioned in the review. Closing for now.

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.

2 participants