When trying to create an inference file, I get the following ValueError: hparams.vocab_prefix must be provided.
~/nmt $ python -m nmt.nmt \
> --model_dir=/tmp/nmt_model \
> --inference_input_file=/tmp/my_infer_file.vi \
> --inference_output_file=/tmp/nmt_model/output_infer
# Job id 0
# Loading hparams from /tmp/nmt_model/hparams
# hparams:
src=None
tgt=None
train_prefix=None
dev_prefix=None
test_prefix=None
out_dir=None
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "~/nmt/nmt/nmt.py", line 479, in <module>
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "~/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "~/nmt/nmt/nmt.py", line 267, in main
hparams = ensure_compatible_hparams(hparams)
File "~/nmt/nmt/nmt.py", line 195, in ensure_compatible_hparams
new_hparams = extend_hparams(new_hparams)
File "~/nmt/nmt/nmt.py", line 148, in extend_hparams
raise ValueError("hparams.vocab_prefix must be provided.")
ValueError: hparams.vocab_prefix must be provided.
If I comment hparams = ensure_compatible_hparams(hparams) out, it runs without any trouble.
It seems the saved hparams in your /tmp/nmt_model/hparams isn't right,
Have you followed the beginning of the hands-on section to train the nmt model?
yeah, I ran the following commands:
nmt/scripts/download_iwslt15.sh /tmp/nmt_data
mkdir /tmp/nmt_model
python -m nmt.nmt \
--src=vi --tgt=en \
--vocab_prefix=/tmp/nmt_data/vocab \
--train_prefix=/tmp/nmt_data/train \
--dev_prefix=/tmp/nmt_data/tst2012 \
--test_prefix=/tmp/nmt_data/tst2013 \
--out_dir=/tmp/nmt_model \
--num_train_steps=1000 \
--steps_per_stats=100 \
--num_layers=2 \
--num_units=128 \
--dropout=0.2 \
--metrics=bleu
head /tmp/nmt_data/tst2013.vi > /tmp/my_infer_file.vi
python -m nmt.nmt \
--model_dir=/tmp/nmt_model \
--inference_input_file=/tmp/my_infer_file.vi \
--inference_output_file=/tmp/nmt_model/output_infer
Note: I chose 1000 train steps in contrast to 12000 when trying to recreate this error just now. All other parameters do not differ from the tutorial.
The content of /tmp/nmt_model/hparams is:
{"pass_hidden_state": true, "steps_per_stats": 100, "tgt": "en", "out_dir": "/tmp/nmt_model", "source_reverse": false, "sos": "<s>", "encoder_type": "uni", "best_bleu": 0.7761778789336314, "tgt_vocab_size": 17191, "num_layers": 2, "optimizer": "sgd", "init_weight": 0.1, "tgt_vocab_file": "/tmp/nmt_data/vocab.en", "src_max_len_infer": null, "beam_width": 0, "src_vocab_size": 7709, "decay_factor": 0.98, "src_max_len": 50, "vocab_prefix": "/tmp/nmt_data/vocab", "share_vocab": false, "test_prefix": "/tmp/nmt_data/tst2013", "attention_architecture": "standard", "bpe_delimiter": null, "epoch_step": 1000, "infer_batch_size": 32, "src_vocab_file": "/tmp/nmt_data/vocab.vi", "colocate_gradients_with_ops": true, "learning_rate": 1.0, "start_decay_step": 0, "unit_type": "lstm", "num_train_steps": 1000, "time_major": true, "dropout": 0.2, "attention": "", "tgt_max_len": 50, "batch_size": 128, "residual": false, "metrics": ["bleu"], "length_penalty_weight": 0.0, "train_prefix": "/tmp/nmt_data/train", "forget_bias": 1.0, "max_gradient_norm": 5.0, "num_residual_layers": 0, "log_device_placement": false, "random_seed": null, "src": "vi", "num_gpus": 1, "dev_prefix": "/tmp/nmt_data/tst2012", "max_train": 0, "steps_per_external_eval": null, "eos": "</s>", "decay_steps": 10000, "tgt_max_len_infer": null, "num_units": 128, "num_buckets": 5, "best_bleu_dir": "/tmp/nmt_model/best_bleu"}
Thanks! I can re-generate the issue.
A short term fix is also passing the FLAGS required by ensure_compatible_hparams().
For example, in the tutorial case:
python -m nmt.nmt \
--src=vi --tgt=en \
--vocab_prefix=/tmp/nmt_data/vocab \
--out_dir=/tmp/nmt_model \
--model_dir=/tmp/nmt_model \
--inference_input_file=/tmp/my_infer_file.vi \
--inference_output_file=/tmp/nmt_model/output_infer
@oahziur thanks. The fix worked for me as well.
Yeah, I had the same issue and had to dig into the source code. The cmd line in readme is not sufficient.
Besides the fixed suggested by oahziur, it is better to set beam_width explicitly, which is overwritten by the FLAGs default 0. And set inference_ref_file will trigger bleu calculation.
@skyw This should be fixed by d6582546d1cd6e341aad12c3853d3b1abfbfcaf3
Most helpful comment
Thanks! I can re-generate the issue.
A short term fix is also passing the FLAGS required by
ensure_compatible_hparams().For example, in the tutorial case: