Reputation: 115
I am trying to import BertModel from transformers, but it fails. This is code I am using
from transformers import BertModel, BertForMaskedLM
This is the error I get
ImportError: cannot import name 'BertModel' from 'transformers'
Can anyone help me fix this?
Upvotes: 4
Views: 22458
Reputation: 658
lastest version of transformers have fix this issue. you can use the below command
pip install --upgrade transformers
Upvotes: 3
Reputation: 11
It's very simple, Uninstall transformer and reinstall it along with spacy. It worked for me.
Upvotes: 1
Reputation: 278
You can use your code too from transformers import BertModel, BertForMaskedLM
; just make sure your transformers
is updated.
Upvotes: 0
Reputation: 115
Fixed the error. This is the code
from transformers.modeling_bert import BertModel, BertForMaskedLM
Upvotes: 6