After training, I would like to get multiple translations for a sentence.
I am using opennmt-tf, and the config file is given at the end of this post.
The command I used to get translation is:
onmt-main infer --config config.yml data.yml --features_file test.txt --predictions_file translations.out
In the documentation : http://opennmt.net/OpenNMT/translation/beam_search/,
-beam_size and -n_best are mentioned, but I am confused where to put these two arguments in the config file. There is already beam_width: 5 in the section params.
Default OpenNMT parameters from the Lua version.
Consider setting this to -1 to match the number of training examples.
eval_delay: 3600 # Every 1 hours.
You can add the
n_best option under the
infer section. See:
Thank you. By the way, does beam_width: 5 under the param section has relation with n_best under infer section? For example, if beam_width = 1, does n_best = 10 is meaningful?
An error is thown if
n_best is greater than
I set beam_width: 50 under section params
During training, everything is fine.
However, during inference, I got error as shown at the end.
I then make the file in test.txt in --features_file test.txt to contain one line.
The error is still there. Then I change beam_width to 13 and it works.
But for different sentences, the maximal values for beam_width to work during inference are different. This cause me problems because I want test.txt to contain several sentences and just launch the inference once.
What is the right way to get several (a fixed number) translations for each sentence in one inference command. (If it can only find fewer translations than specified for a particular sentence, just output something like None).
INFO:tensorflow:Done running local_init_op.
2018-06-08 05:00:49.064659: W tensorflow/core/framework/op_kernel.cc:1318] OP_REQUIRES failed at gather_nd_op.cc:50 : Invalid argument: flat indices[233, :] = [12, 0, 19] does not index into param (shape: [14,1,18,7]).
Traceback (most recent call last):
File “/home/shieh/Applications/miniconda3/envs/deep-learning-base/lib/python3.6/site-packages/tensorflow/python/client/session.py”, line 1322, in _do_call
File “/home/shieh/Applications/miniconda3/envs/deep-learning-base/lib/python3.6/site-packages/tensorflow/python/client/session.py”, line 1307, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File “/home/shieh/Applications/miniconda3/envs/deep-learning-base/lib/python3.6/site-packages/tensorflow/python/client/session.py”, line 1409, in _call_tf_sessionrun
tensorflow.python.framework.errors_impl.InvalidArgumentError: flat indices[233, :] = [12, 0, 19] does not index into param (shape: [14,1,18,7]).
[[Node: seq2seq/decoder_1/decoder_1/GatherNd = GatherNd[Tindices=DT_INT32, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](seq2seq/decoder_1/decoder_1/Reshape_2, seq2seq/decoder_1/decoder_1/stack)]]
During handling of the above exception, another exception occurred: