Loading fine tuned BertForMaskedLM
See original GitHub issueHi,
I tried to fine tune BertForMaskedLM and it works. But i’m facing issues when I try to load the fine tuned model. Here is the code I used to load the model :
model_state_dict = torch.load("./finetunedmodel/pytorch_model.bin", map_location='cpu')
model_fine = BertForMaskedLM.from_pretrained(pretrained_model_name='bert-base-multilingual-cased', state_dict=model_state_dict, cache_dir='./data')
The error I’m facing is : init() got an unexpected keyword argument ‘state_dict’
Does someone already faced this issue ?
Thanks
Edit : I trained my model on gpu and try to use it on cpu. When I use it on gpu it works !
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Fine-tuning a masked language model - Hugging Face Course
This process of fine-tuning a pretrained language model on in-domain data is usually called domain adaptation. It was popularized in 2018 by ULMFiT,...
Read more >Loading fine tuned BertForMaskedLM · Issue #215 - GitHub
Hi, I tried to fine tune BertForMaskedLM and it works. But i'm facing issues when I try to load the fine tuned model....
Read more >BERT Fine-Tuning Tutorial with PyTorch - Chris McCormick
In order for torch to use the GPU, we need to identify and specify the GPU as the device. Later, in our training...
Read more >pytorch-pretrained-bert - PyPI
This section explain how you can save and re-load a fine-tuned model (BERT, GPT, GPT-2 and Transformer-XL). There are three types of files...
Read more >How to use fine-tuned model in huggingface for actual ...
Remember that you also need to tokenize the input to your model, just like in the training phase. Merely feeding a sentence to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

yeah yes. if you trained model in GPU, can’t be loaded. we will change map_location=“CPU” in modeling.py line 511. https://github.com/huggingface/pytorch-pretrained-BERT/blob/0a9d7c7edb20a3e82cfbb4b72515575543784823/pytorch_pretrained_bert/modeling.py#L511
state_dict = torch.load(weights_path, map_location="CPU" )now it will load our finetuned model. this is only for inference running on CPU.
@tgriseau - I want to fine-tune bert on MaskedLM using domain-specific text. could you please provide an example of how you fine-tuned or provide some details about what kind of inputs need to be passed? will I be using the true sentence as the output for fine-tuning?