No module named 'transformers.models' while trying to import BertTokenizer

13,575

you can change your code from

transformers.modeling_bert import BertModel, BertForMaskedLM

to

from transformers.models.bert.modeling_bert import BertModel,BertForMaskedLM
Share:
13,575

Related videos on Youtube

Icaru5
Author by

Icaru5

Updated on June 04, 2022

Comments

  • Icaru5
    Icaru5 almost 2 years

    I am trying to import BertTokenizer from the transformers library as follows:

    import transformers
    from transformers import BertTokenizer
    from transformers.modeling_bert import BertModel, BertForMaskedLM
    

    However, I get the following error:

    enter image description here

    enter image description here

    I am using transformers version 3.5.1 because I had a problem with the updated version which can be found here.

    Does anyone know how to fix this? Apart from updating the transformers library to its latest version (that will unfortunately cause more errors).

    Any help is appreciated!

    • cronoik
      cronoik about 3 years
      I can not reproduce this with transformers 3.5.1. Have you maybe created a package called transformers by yourself?