VILAN-Lab / MLGCN-DP

Code for paper "2021-AAAI-Story Ending Generation with Multi-Level Graph Convolutional Networks over Dependency Parsing"
14 stars 1 forks source link

"python generate_story.py": IndexError: tensors used as indices must be long, byte or bool tensors #3

Open caoyuanbao opened 3 years ago

caoyuanbao commented 3 years ago

When I run "python generate_story.py", error occurs as following. It seems related to your "PS: When calculate the BLEU, please uniform case of ref and hyp", but I don't understand it. Could you explained more?

Traceback (most recent call last):
  File "generate_story.py", line 154, in <module>
    main()
  File "generate_story.py", line 135, in main
    all_hyp, all_scores = q_gen.generate_question_batch(*batch)
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Story_Generator.py", line 174, in generate_question_batch
    src_seq, src_enc, inst_idx_to_position_map, n_bm)
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Story_Generator.py", line 127, in beam_decode_step
    dec_seq = prepare_beam_dec_seq(inst_dec_beams, len_dec_seq)
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Story_Generator.py", line 95, in prepare_beam_dec_seq
    dec_partial_seq = [b.get_current_state() for b in inst_dec_beams if not b.done]
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Story_Generator.py", line 95, in <listcomp>
    dec_partial_seq = [b.get_current_state() for b in inst_dec_beams if not b.done]
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Beam.py", line 33, in get_current_state
    return self.get_tentative_hypothesis()
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Beam.py", line 90, in get_tentative_hypothesis
    hyps = [self.get_hypothesis(k) for k in keys]
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Beam.py", line 90, in <listcomp>
    hyps = [self.get_hypothesis(k) for k in keys]
  File "/home/caidesheng/caojie/workspace2/MLGCN-DP/transformer/Beam.py", line 100, in get_hypothesis
    hyp.append(self.next_ys[j+1][k])
IndexError: tensors used as indices must be long, byte or bool tensors
VILAN-Lab commented 2 years ago

Hi :) “When calculate the BLEU, please uniform case of ref and hyp“, which means you should uniform the capitals and lower case letters of the reference an hypothesis file. For example, when calculate the BLEU, it maybe make "You" and "you" as defferent word.

And about the error, you can try to observe what is the dtype of the var k and var j.

VILAN-Lab commented 2 years ago

Regarding the issue “IndexError: tensors used as indices must be long, byte or bool tensors” mentioned above , there is a problem in this file ./transformer/Beam.py. I have uploaded the correct one. In detail, "prev_k = best_scores_id / num_words" should be modified as "prev_k = best_scores_id // num_words" in ./transformer/Beam.py line 63.

caoyuanbao commented 2 years ago

自动回复:你好,我已经收到你的邮件,待我细看后联系曹洁