lizekang / ITDD

The source code of our ACL2019 paper "Incremental Transformer with Deliberation Decoder for Document Grounded Conversations "
MIT License
86 stars 17 forks source link

RuntimeError: cannot reshape tensor of 0 elements into shape [1, 0, -1] #17

Open bakszero opened 3 years ago

bakszero commented 3 years ago

Hi, I'm trying to run the translate script for own specified knowledge and a user utterance after training the models. I noticed that I'm able to run the translate script with the given test data successfully.

However, when specifying my own input in the files, I get a runtime error as below. My input was of the form:

  1. For --src src.txt: Heyy hows it going?

  2. For --knl knl.txt: Today is a rainy day. There are clouds all over the sky.

And I get the following runtime error with a batch-size of 1:

  File "translate.py", line 36, in <module>
    main(opt)
  File "translate.py", line 21, in main
    attn_debug=opt.attn_debug
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/translate/translator.py", line 205, in translate
    batch, data, attn_debug, fast=self.fast
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/translate/translator.py", line 309, in translate_batch
    return self._translate_batch(batch, data)
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/translate/translator.py", line 634, in _translate_batch
    batch, data_type)
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/translate/translator.py", line 322, in _run_encoder
    src, knl, src_lengths, knl_lengths)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/encoders/mtransformer.py", line 258, in forward
    emb, knl_bank_tgt, knl_mask = self.knltransformer(tgt_knl, None)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/encoders/mtransformer.py", line 170, in forward
    out = self.transformer[i](out, mask)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/mnt/disks/disk-huge/bakhtiyar/ITDD/onmt/encoders/mtransformer.py", line 48, in forward
    input_norm = self.layer_norm(inputs)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/modules/normalization.py", line 158, in forward
    input, self.normalized_shape, self.weight, self.bias, self.eps)
  File "/home/bakhtiyar/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 1651, in layer_norm
    torch.backends.cudnn.enabled)
RuntimeError: cannot reshape tensor of 0 elements into shape [1, 0, -1]

On some investigation, I did find that if one includes &lt; SEP &gt; 2 times in the source file sentence and atleast 3 times in the knowledge file sentence, then the scripts work successfully. I could not find in the code something where this is documented.

Please could you help me to understand the correct data format required for running for my own knowledge and given utterance in an interactive fashion - it'd be super nice! Thanks!

lizekang commented 3 years ago

Sorry for the late response. We use the tokenizer.perl in https://github.com/OpenNMT/OpenNMT-py/tree/master/tools to pre-process the data. &lt; SEP &gt; is original [SEP], which represents the separator between utterances or knowledge paragraphs. But I never try interactive fashion. So I'm not sure if the code is ok for interactive fashion.

bakszero commented 3 years ago

Alright, thanks for pointing it out. Ah no, that's a bummer :( Would have loved to try an interactive fashion