OpenNMT / OpenNMT-py

Open Source Neural Machine Translation and (Large) Language Models in PyTorch
https://opennmt.net/
MIT License
6.78k stars 2.25k forks source link

[Help Wanted] Reimplement Dump_beam for beam visualization #719

Open ziorufus opened 6 years ago

ziorufus commented 6 years ago

Hello! I'm trying to use the dump_beam parameter in the translate.py file, but I get this error:

Traceback (most recent call last):
  File "translate.py", line 29, in <module>
    main(opt)
  File "translate.py", line 18, in main
    opt.batch_size, opt.attn_debug)
  File "/kore-ns-groups/dh/aprosio/simp/OpenNMT-py-master/onmt/translate/Translator.py", line 210, in translate
    json.dump(self.translator.beam_accum,
AttributeError: 'Translator' object has no attribute 'translator'

By looking at the code, it seems that line 210 of Translator.py should be modified from json.dump(self.translator.beam_accum to json.dump(self.beam_accum, but it still does not work. No error is thrown now, but the beam file only contains: {"predicted_ids": [], "beam_parent_ids": [], "log_probs": [], "scores": []}. How can I get the correct output? Note that the output file is correct.

Thank you!

BeckyMarvin commented 6 years ago

It looks like beam dumping hasn't been implemented yet. self.beam_accum is initialized but never updated in either Translator.py or Beam.py, which are the two places I was looking for it.

vince62s commented 6 years ago

okay. It seems that it used to be implemented and then removed by this commit:

https://github.com/OpenNMT/OpenNMT-py/commit/3052e3890fdb0249a1f37e7b40f8e36a1dabf3a4#diff-bb5f81e1cd6e5e13578730e07d26f151L182

Anyway, it needs to be reimplemented and if possible with the same output as the Torch version:

https://github.com/OpenNMT/OpenNMT/blob/e7aded4edf5c7acd50e672f8c12f2b8e0b684242/onmt/translate/Translator.lua#L558-L561

So that the existing visualization tool can be used.

I don't have time to take care of this, if anyone is interested, these pointers should be enough.

bpopeters commented 6 years ago

I'll give it a look.

vince62s commented 6 years ago

@bpopeters di you have time to work on this ?

vince62s commented 5 years ago

kind reminder if you have time.

vince62s commented 5 years ago

@ziorufus do you have time to test #1240 ?

William-N-Havard commented 4 years ago

Kind reminder if you have time.