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

Fix loading custom vocab in transformers style for LM finetuning #155

Merged
merged 3 commits into from
Nov 20, 2019

Conversation

tholor
Copy link
Member

@tholor tholor commented Nov 20, 2019

LM finetuning with custom vocab was broken after switching to the transformer style of handling custom vocab (adding tokens instead of using "unused tokens").

The complication here is that with a larger vocab we need to adjust both the size of the embedding layer in the LM and the decoder (bias+weights) in the PH. In addition, the decoder shares the weights with the embedding layer.

We therefore need to supply now an extra arg "n_added_tokens" for loading the PH / LM.

Example:

    ...
    tokenizer.add_tokens(["somecustomtoken", "specialrareword"])

    ...
    language_model = LanguageModel.load(lang_model, n_added_tokens=len(tokenizer.added_tokens_decoder))
    lm_prediction_head = BertLMHead.load(lang_model, n_added_tokens=len(tokenizer.added_tokens_decoder))

Copy link
Contributor

@brandenchan brandenchan left a comment

Choose a reason for hiding this comment

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

Looks good, I just think a clearer info message would be good

farm/modeling/language_model.py Outdated Show resolved Hide resolved
@tholor tholor added bug Something isn't working part: model task: LM fine Language model fine-tuning labels Nov 20, 2019
@tholor tholor merged commit 484d26c into master Nov 20, 2019
@tholor tholor deleted the fix_custom_vocab_lm_finetuning branch April 28, 2020 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working part: model task: LM fine Language model fine-tuning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants