Search code examples
pythonnlppytorchhuggingface-transformersbert-language-model

Cannot import BertModel from transformers


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?


Solution

  • Fixed the error. This is the code

    from transformers.modeling_bert import BertModel, BertForMaskedLM