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

Camenbert length Tokenizer not equal config vocab_size #2020

Closed
Keisn1 opened this issue Dec 2, 2019 · 2 comments
Closed

Camenbert length Tokenizer not equal config vocab_size #2020

Keisn1 opened this issue Dec 2, 2019 · 2 comments
Labels

Comments

@Keisn1
Copy link

Keisn1 commented Dec 2, 2019

❓ Questions & Help

Hi there,
when I load the pretrained Camenbert model and tokenizer via

model = CamembertForMaskedLM.from_pretrained('camembert-base') tokenizer = CamembertTokenizer.from_pretrained('camembert-base')

the length of the tokenizer is 32004 but the vocab_size of the model is 32005.
print(len(tokenizer))
'print(model.config.vocab_size'

This throws me an error

Index out of range

when I try to adapt the lm_finetuning example because of
model.resize_token_embeddings(len(tokenizer))

It runs when I comment out this line. So my question is, is this the intended behaviour resp. what's the reason for the unevenness between the tokenizer and the model vocab_size?

@thomwolf
Copy link
Member

thomwolf commented Dec 5, 2019

Indeed, upon deeper investigation, it appears that the original fairseq model has a bunch of duplicate tokens in the dictionary:

import torch
camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
list(camembert.task.source_dictionary[i] for i in range(10))
>>> ['<s>', '<pad>', '</s>', '<unk>', '<unk>', '<s>', '</s>', ',', '▁de', '.']

I'm cleaning and updating for this in #2065

@stale
Copy link

stale bot commented Feb 3, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants