ImportError: cannot import name 'warmup_linear'

ImportError: cannot import name 'warmup_linear'

在尝试导入 warmup_linear 时,出现此错误

ImportError: cannot import name 'warmup_linear'

导入 -

from pytorch_pretrained_bert.optimization import BertAdam, warmup_linear

需求文件

boto3==1.9.198
botocore==1.12.198
certifi==2019.6.16
chardet==3.0.4
docutils==0.14
h5py==2.9.0
idna==2.8
jmespath==0.9.4
Keras==2.2.4
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.0
numpy==1.17.0
Pillow==6.1.0
python-dateutil==2.8.0
pytorch-pretrained-bert==0.6.2
PyYAML==5.1.1
regex==2019.6.8
requests==2.22.0
s3transfer==0.2.1
scipy==1.3.0
seqeval==0.0.12
six==1.12.0
torch==1.1.0
torchvision==0.3.0
tqdm==4.32.2
urllib3==1.25.3

导入'warmup_linear'需要做什么?

将导入行更改为:

from pytorch_pretrained_bert.optimization import BertAdam, WarmupLinearSchedule

因为 optimization.py 脚本中没有名为 warmup_linear 的 class。

0.4.0版本没有这个问题。 pip install pytorch_pretrained_bert==0.4.0 或降级到 0.6.1 解决了它。