从simpletransformers导入分类模型时发生错误(无法导入名称“ BertPreTrainedModel”)

时间:2020-09-23 04:23:55

标签: keras pytorch tensorflow2.0 bert-language-model huggingface-transformers

尝试从simpletransformers导入分类模型时遇到以下错误。


ImportError                               Traceback (most recent call last)
<ipython-input-1-29f08e6c2d87> in <module>()
----> 1 from simpletransformers.classification import ClassificationModel, ClassificationArgs

3 frames
/usr/local/lib/python3.6/dist-packages/simpletransformers/classification/transformer_models/roberta_model.py in <module>()
      2 import torch.nn as nn
      3 from torch.nn import CrossEntropyLoss, MSELoss
----> 4 from transformers.modeling_roberta import (
      5     ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
      6     BertPreTrainedModel,

ImportError: cannot import name 'BertPreTrainedModel'

---------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:2)

this github问题中,问题是simpletransformers的旧版本。要获取最新版本,请执行pip install --upgrade simpletransformers。甚至还可以对transformers软件包执行此操作。