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

Assign <unusedXX> tokens with special_tokens without growing vocab size #1473

Closed
jacobwjs opened this issue Mar 17, 2024 · 6 comments · May be fixed by #1570
Closed

Assign <unusedXX> tokens with special_tokens without growing vocab size #1473

jacobwjs opened this issue Mar 17, 2024 · 6 comments · May be fixed by #1570

Comments

@jacobwjs
Copy link

``
I'm trying to modify google/gemma-7b tokenizer for instruction tuning purposes. My goal is to replace some of the "unused" tokens that were specifically added to the tokenizer for my own defined "custom" tokens. I want these custom tokens to be treated as "special" (i.e. not normalized, stripped, etc.), however this seems like an impossible task.

What I would like to do is some version of the following,

tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b")

custom_tokens = ['<|im_start|>', '<|im_end|>']
unused_tokens = ['<unused1>', '<unused2>']

tokenizer.add_special_tokens({'additional_special_tokens': custom_tokens, 'tokens_to_replace': unused_tokens})

Given that many models/tokenizers being open-sourced specifically reserve some set of unused tokens for this purpose, I would like to make use of them without growing the vocabulary, and subsequently not having to adjust the model's embedding dimensions.

I've tried manually manipulating the vocab, and assigning appropriate dicts on the forward and reverse pass (encoder, decoder), but nothing seems to work.

How can I achieve my goals of making use of unused tokens, ensuring they are treated as "special", and not growing the vocabulary of the tokenizer and model embedding?

@ArthurZucker
Copy link
Collaborator

That is something we should do indeed

@jacobwjs
Copy link
Author

Beautiful. That would mostly resolve another issue as well huggingface/trl#1412 (comment)

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Apr 22, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2024
@ArthurZucker ArthurZucker reopened this Jun 11, 2024
@ArthurZucker
Copy link
Collaborator

I'll take this one on in a bit!

@ArthurZucker
Copy link
Collaborator

opened a PR !

@github-actions github-actions bot removed the Stale label Jul 14, 2024
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Aug 14, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants