导入Pytorch_Transformers时找不到模块错误

时间:2019-09-19 12:58:36

标签: nlp anaconda pytorch

通过Anaconda下载pytorch_transformers并通过Jupyter Notebook执行import命令后,我遇到了一些与缺少模块有关的错误。

我尝试搜索sacremoses,以通过Anaconda导入软件包,但是它仅适用于Linux计算机。还有其他人遇到过类似的问题吗?预先感谢!

from pytorch_transformers import BertTokenizer, BertModel, BertForMaskedLM

这是错误:


<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'```

2 个答案:

答案 0 :(得分:0)

请尝试创建一个conda环境,并使用以下步骤在所创建的环境中安装软件包:

  1. conda create -n env_pytorch -c intel python = 3.5
  2. 源激活env_pytorch
  3. pip安装pytorch-transformers

希望这会有所帮助。

enter image description here

答案 1 :(得分:0)

您缺少pytorch-transformers依赖项。尝试使用以下命令安装它:

pip install pytorch-transformers