Opennmt-py: Copy-enabled model crashes `translate.py` if `-tgt` provided

Created on 8 Dec 2017  路  6Comments  路  Source: OpenNMT/OpenNMT-py

First off, thank you for developing and maintaining this great library!

I'm very new to this codebase, so my apologies if this is user error instead of a bug.

It appears that a model with copying enabled crashes running translate.py if -tgt is provided. It is able to generate text fine, but it crashes because it tries to compute perplexity on the gold data.

The error message I get is:

Traceback (most recent call last):
  File "translate.py", line 129, in <module>
    main()
  File "translate.py", line 70, in main
    = translator.translate(batch, data)
  File "/home/max/repos/OpenNMT-py/onmt/Translator.py", line 206, in translate
    pred, predScore, attn, goldScore = self.translateBatch(batch, data)
  File "/home/max/repos/OpenNMT-py/onmt/Translator.py", line 181, in translateBatch
    allGold = self._runTarget(batch, dataset)
  File "/home/max/repos/OpenNMT-py/onmt/Translator.py", line 87, in _runTarget
    out = self.model.generator.forward(dec)
TypeError: forward() missing 2 required positional arguments: 'attn' and 'src_map'

In Translator.py, translateBatch(...) correctly checks for self.copy_attn, and calls self.model.generator.forward(...) with three arguments if so. But if -tgt is provided, then _runTarget(...) is called, which omits this check and always calls self.model.generator.forward(...) with only one argument, causing the crash.

bug

Most helpful comment

Just to avoid a crash, you could comment out these two lines. Note that this wouldn't report the gold scores.

https://github.com/OpenNMT/OpenNMT-py/blob/0ecec8b4c16fdec7d8ce2646a0ea47ab6535d308/onmt/translate/Translator.py#L338-L339

All 6 comments

Thanks. Will look at it.

I had this issue too. We don't have good semantics for what tgt means with copy. Need to figure out what it should do.

Any update on this. I was just hoping to do the Bleu score evaluation on the target as part of the translation step when I came across the error. Does _run_target just need some extra checks added to it for when self.copy_attn is present?

Just to avoid a crash, you could comment out these two lines. Note that this wouldn't report the gold scores.

https://github.com/OpenNMT/OpenNMT-py/blob/0ecec8b4c16fdec7d8ce2646a0ea47ab6535d308/onmt/translate/Translator.py#L338-L339

Started running into this again, I'm going to see if I can get gold score working for copy attention. It would be super useful for my current task

closing, discussion continued in #777 and #862

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andreaferretti picture andreaferretti  路  5Comments

mataney picture mataney  路  4Comments

mrpega picture mrpega  路  3Comments

Bachstelze picture Bachstelze  路  3Comments

paulkp picture paulkp  路  6Comments