Transformers: error when do python3 run_squad.py

Created on 17 Apr 2019  路  13Comments  路  Source: huggingface/transformers

Hello,
I am newbie of pytorch-pretrained-Bert.
After successfully converted from init-checkpoint of tensorflow to pytorch bin,
I found an error when I do run_squad.
Guessing I should've included some configuration ahead, could anyone can help?
See below.

File "run_squad.py", line 37, in <module>
    from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE, WEIGHTS_NAME, CONFIG_NAME
ImportError: No module named pytorch_pretrained_bert.file_utils
Need more information

Most helpful comment

@YanZhangADS

You can install from source with this command below

git clone https://github.com/huggingface/pytorch-pretrained-BERT.git
cd pytorch-pretrained-BERT
python setup.py install

All 13 comments

Did you install pytorch-pretrained-bert as indicated in the README?
pip install pytorch_pretrained_bert

You don't have to convert the checkpoints yourself, there are already converted.

Try reading the installation and usage sections of the README.

Of cause I installed,
More precisely, error code is slightly changed.

Traceback (most recent call last):
  File "run_squad.py", line 37, in <module>
    from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE, WEIGHTS_NAME, CONFIG_NAME
ImportError: cannot import name WEIGHTS_NAME

Hmm you are right, the examples are compatible with master only now that we have a new token serialization. I guess we'll have to do a new release (0.6.2) today so everybody is on the same page.
Let me do that.

Actually, we'll wait for the merge of #506.

In the meantime you can install from source and it should work.

Oh it's done immediately when I installed from source. Thanks.

Ok great.

Just a side note on writing messages in github: you should add triple-quotes like this: ``` before and after the command line, errors and code you are pasting. This way it's easier to read.

Ex:
```
pip install -e .
```

will display like:

pip install -e .

Good point(triple quotes).
I didn't know what to do, but now I have it all.
Thanks.

Actually, we'll wait for the merge of #506.

In the meantime you can install from source and it should work.

how to "install from source"?

@YanZhangADS

You can install from source with this command below

git clone https://github.com/huggingface/pytorch-pretrained-BERT.git
cd pytorch-pretrained-BERT
python setup.py install

Same problem with "ImportError: cannot import name WEIGHTS_NAME". However, after building 0.6.1 from source, I get:

from pytorch_pretrained_bert.optimization import BertAdam, warmup_linear
    ImportError: cannot import name 'warmup_linear'

I don't need the warmup, so I removed the import, but letting you guys know that this is an import error as well. Thanks!

Thanks for that @dumitrescustefan, we're working on it in #518.
I'm closing this issue for now as we start to deviate from the original discussion.

I just built from source. I'm still getting the same error as in original issue.

The version 0.4.0 doesn't give this issue.
pip install pytorch_pretrained_bert==0.4.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

delip picture delip  路  3Comments

siddsach picture siddsach  路  3Comments

iedmrc picture iedmrc  路  3Comments

fyubang picture fyubang  路  3Comments

zhezhaoa picture zhezhaoa  路  3Comments