BiSET
BiSET copied to clipboard
Error in translation using trained model
I trained the model successfully and ran the command $ python3 translate.py -model model_step_85000.pt -src path_to_data/test.article.txt -template path_to_data/test.template.rerank-5
for translation
but it occurred the following error:
Traceback (most recent call last):
File "translate.py", line 36, in <module>
main(opt)
File "translate.py", line 25, in main
attn_debug=opt.attn_debug)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/translate/translator.py", line 198, in translate
use_filter_pred=self.use_filter_pred)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/inputter.py", line 248, in build_dataset
use_filter_pred=use_filter_pred)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/text_dataset.py", line 66, in __init__
ex, examples_iter = self._peek(examples_iter)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/dataset_base.py", line 107, in _peek
first = next(seq)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/text_dataset.py", line 303, in _dynamic_dict
template = example["template"]
KeyError: 'template'
not sure where does this error come from
I have fixed the errors. You can have a try now.
Thanks to @InitialBug , but it occured a new error
Traceback (most recent call last):
File "translate.py", line 36, in <module>
main(opt)
File "translate.py", line 25, in main
attn_debug=opt.attn_debug)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/translate/translator.py", line 198, in translate
use_filter_pred=self.use_filter_pred)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/inputter.py", line 248, in build_dataset
use_filter_pred=use_filter_pred)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/text_dataset.py", line 67, in __init__
ex, examples_iter = self._peek(examples_iter)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/dataset_base.py", line 107, in _peek
first = next(seq)
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/text_dataset.py", line 305, in _dynamic_dict
example["template_map"]=torch.LongTensor([src_vocab.stoi[w] for w in template])
File "/home/yoshow/Summarization/BiSET/Bi-selective Encoding/onmt/inputters/text_dataset.py", line 305, in <listcomp>
example["template_map"]=torch.LongTensor([src_vocab.stoi[w] for w in template])
KeyError: 'says'
I tried to print the dict example
out
and it seem like the word says
is not in the dictionary of src_vocab.stoi
{'template': ('nec', 'says', '<unk>', 'supercomputers', 'selling', 'well', 'despite', 'trade', 'row'), 'src': ('japan', "'s", 'nec', 'corp.', 'and', 'UNK', 'computer', 'corp.', 'of', 'the', 'united', 'states', 'said', 'wednesday', 'they', 'had', 'agreed', 'to', 'join', 'forces', 'in', 'supercomputer', 'sales', '.'), 'src_map': tensor([12, 3, 14, 2, 7, 5, 8, 2, 15, 20, 23, 18, 16, 24, 21, 10, 6, 22,
13, 9, 11, 19, 17, 4]), 'indices': 0}
If I'm guessing right, src_vocab
should include all the vocabularies for the mapping?
try -dynamic_dict or add the -tgt argument, it decides on whether you want to expose the target vocabulary.
@InitialBug I'm still running into the same error listed above using
python translate.py -model=model_step_100000.pt -src=data/test.article.txt -template=data/test.template.rerank-5 -tgt=data/test.title.txt
any suggestions about what to do?
@InitialBug I'm still running into the same error listed above using
python translate.py -model=model_step_100000.pt -src=data/test.article.txt -template=data/test.template.rerank-5 -tgt=data/test.title.txt
any suggestions about what to do?
Fixed it! Turns out the dynamic_dict
was set to True instead of False when getting passed around.
@InitialBug I'm still running into the same error listed above using
python translate.py -model=model_step_100000.pt -src=data/test.article.txt -template=data/test.template.rerank-5 -tgt=data/test.title.txt
any suggestions about what to do?Fixed it! Turns out the
dynamic_dict
was set to True instead of False when getting passed around.
Hello, How to set dynamic_dict True. It seems that this parameter isn't used when translating.