Error when running translate.py

pytorch

(Justin Grace) #1

Hello,

I am getting an error when running the translate script on a trained model.

I run the following command:
python OpenNMT-py/translate.py -model opennmt_models/brnn_acc_40.74_ppl_37.57_e3.pt -src gu_codebase/data/src-val.txt -output opennmt_models/pred.txt -replace_unk -verbose

and receive the error message:
> xxx$ python OpenNMT-py/translate.py -model opennmt_models/brnn_acc_40.74_ppl_37.57_e3.pt -src gu_codebase/data/src-val.txt -output opennmt_models/pred.txt -replace_unk -verbose

Could not find setup.py for directory /Users/jusjosgra/mlpractical (tried all parent directories)
Could not find setup.py for directory /Users/jusjosgra/mlpractical (tried all parent directories)
Traceback (most recent call last):
  File "OpenNMT-py/translate.py", line 33, in <module>
    main(opt)
  File "OpenNMT-py/translate.py", line 19, in main
    translator = make_translator(opt, report_score=True, logger=logger)
  File "/Users/jusjosgra/uni/dissertation/OpenNMT-py/onmt/translate/Translator.py", line 27, in make_translator
    onmt.ModelConstructor.load_test_model(opt, dummy_opt.__dict__)
  File "xxx/OpenNMT-py/onmt/ModelConstructor.py", line 119, in load_test_model
    map_location=lambda storage, loc: storage)
  File "xxx/anaconda/lib/python3.5/site-packages/torch/serialization.py", line 303, in load
    return _load(f, map_location, pickle_module)
  File "xxx/anaconda/lib/python3.5/site-packages/torch/serialization.py", line 469, in _load
    result = unpickler.load()
ImportError: No module named 'onmt.utils'

Any advice would be greatly appreciated.

Thanks,
Justin


(Vincent Nguyen) #2

You seem not to be on master.
can you try to update and run again ?


(Justin Grace) #3

Hi Vince,

Thanks for your suggestion. I have updated and now get a new error:

xxx python OpenNMT-py/translate.py -model opennmt_models/brnn_acc_40.74_ppl_37.57_e3.pt -src gu_codebase/data/src-val.txt -output opennmt_models/pred.txt -verbose -replace_unk

Traceback (most recent call last):
  File "OpenNMT-py/translate.py", line 36, in <module>
    main(opt)
  File "OpenNMT-py/translate.py", line 19, in main
    translator = build_translator(opt, report_score=True, logger=logger)
  File "xxx/OpenNMT-py/onmt/translate/translator.py", line 31, in build_translator
    onmt.model_builder.load_test_model(opt, dummy_opt.__dict__)
  File "xxx/OpenNMT-py/onmt/model_builder.py", line 130, in load_test_model
    checkpoint['vocab'], data_type=opt.data_type)
  File "xxx/OpenNMT-py/onmt/inputters/inputter.py", line 63, in load_fields_from_vocab
    fields = get_fields(data_type, n_src_features, n_tgt_features)
  File "xxx/OpenNMT-py/onmt/inputters/inputter.py", line 47, in get_fields
    return TextDataset.get_fields(n_src_features, n_tgt_features)
  File "xxx/OpenNMT-py/onmt/inputters/text_dataset.py", line 244, in get_fields
    postprocessing=make_src, sequential=False)
TypeError: __init__() got an unexpected keyword argument 'dtype'

(Justin Grace) #4

Apologies, this seems to have been a silly error by me.

I had not run the requirements installs in the current environment and was using torchtext 0.2.3 instead of 0.3.0.

Thanks for your swift response though!