harvardnlp / encoder-agnostic-adaptation

Encoder-Agnostic Adaptation for Conditional Language Generation
https://arxiv.org/abs/1908.06938
MIT License
79 stars 13 forks source link

`fields` type mismatch resulting in decoding time error #2

Closed XinyuHua closed 4 years ago

XinyuHua commented 4 years ago

Hi!

I was able to train the model on cnndm, but during decoding time the following error occurs:

[2019-09-16 10:54:58,479 INFO] Translating shard 0.
/data/user/anaconda3/envs/encoder-agnostic/lib/python3.5/site-packages/torchtext/data/field.py:359: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  var = torch.tensor(arr, dtype=self.dtype, device=device)
Traceback (most recent call last):
  File "translate.py", line 93, in <module>
    main(opt)
  File "translate.py", line 64, in main
    tag_shard=tag_shard
  File "/home/user/workspace/encoder-agnostic-adaptation/onmt/translate/translator.py", line 366, in translate
    translations = xlation_builder.from_batch(batch_data)
  File "/home/user/workspace/encoder-agnostic-adaptation/onmt/translate/translation.py", line 93, in from_batch
    for n in range(self.n_best)]
  File "/home/user/workspace/encoder-agnostic-adaptation/onmt/translate/translation.py", line 93, in <listcomp>
    for n in range(self.n_best)]
  File "/home/user/workspace/encoder-agnostic-adaptation/onmt/translate/translation.py", line 42, in _build_target_tokens
    tokens.append(src_vocab.itos[tok - len(vocab)])
AttributeError: 'NoneType' object has no attribute 'itos'

This is my decoding command:

python translate.py -beam_size 1 -model output/cnndm_CNNDM_BPE/transformer_cnndm_psa_psa_full/checkpoints/model_step_7000.pt -src /data/user/encoder-agnostic/data/cnndm/test.txt.src.bpe -min_length 60

It appears that in the constructor of TranslationBuilder, self._has_text_src is set to False because self.fields is actually a dict, so hasattr(self.fields, 'src') returns False. It should probably be "src" in self.fields?

zackziegler95 commented 4 years ago

Yes, that is correct, I pushed an update. Thanks!