Module Not Found Error When Importing Pytorch_Transformers

After downloading pytorch_transformers through Anaconda and executing the import command through the Jupyter Notebook, I am facing several errors related to missing modules.

I tried searching sacremoses to import the package via Anaconda, but it is only available for Linux machines. Has anyone else faced similar issues? Thanks in advance!

from pytorch_transformers import BertTokenizer, BertModel, BertForMaskedLM

This is the error:


<ipython-input-5-218d0858d00f> in <module>
----> 1 from pytorch_transformers import BertTokenizer, BertModel, BertForMaskedLM

~\Anaconda3\lib\site-packages\pytorch_transformers\__init__.py in <module>
      1 __version__ = "1.2.0"
----> 2 from .tokenization_auto import AutoTokenizer
      3 from .tokenization_bert import BertTokenizer, BasicTokenizer, WordpieceTokenizer
      4 from .tokenization_openai import OpenAIGPTTokenizer
      5 from .tokenization_transfo_xl import (TransfoXLTokenizer, TransfoXLCorpus)

~\Anaconda3\lib\site-packages\pytorch_transformers\tokenization_auto.py in <module>
     24 from .tokenization_transfo_xl import TransfoXLTokenizer
     25 from .tokenization_xlnet import XLNetTokenizer
---> 26 from .tokenization_xlm import XLMTokenizer
     27 from .tokenization_roberta import RobertaTokenizer
     28 from .tokenization_distilbert import DistilBertTokenizer

~\Anaconda3\lib\site-packages\pytorch_transformers\tokenization_xlm.py in <module>
     25 from io import open
     26 
---> 27 import sacremoses as sm
     28 
     29 from .tokenization_utils import PreTrainedTokenizer

ModuleNotFoundError: No module named 'sacremoses'

3 Answers

Please try to create a conda environment and install the packages in the created environment using the below steps:

conda create -n env_pytorch -c intel python=3.5
source activate env_pytorch
pip install pytorch-transformers
1

You are missing the pytorch-transformers dependency. Try installing it with the following command:

pip install pytorch-transformers

Try using python -m pip install transformers rather than using pip install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest