尝试从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'
---------------------------------------------------------------------------
答案 0 :(得分:2)
在this github问题中,问题是simpletransformers
的旧版本。要获取最新版本,请执行pip install --upgrade simpletransformers
。甚至还可以对transformers
软件包执行此操作。