text-summarization-tensorflow icon indicating copy to clipboard operation
text-summarization-tensorflow copied to clipboard

why there is KeyError: -1 in prediction

Open tianke0711 opened this issue 5 years ago • 7 comments

when code run here::

prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]

    with open("result.txt", "a") as f:
        for line in prediction_output:
            summary = list()
            for word in line:
                if word == "</s>":
                    break
                if word not in summary:
                    summary.append(word)
            print(" ".join(summary), file=f)

print('Summaries are saved to "result.txt"...')

there is error:


KeyError Traceback (most recent call last) in 27 print('prediction:', prediction.shape) 28 ---> 29 prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]] 30 31

in (.0) 27 print('prediction:', prediction.shape) 28 ---> 29 prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]] 30 31

in (.0) 27 print('prediction:', prediction.shape) 28 ---> 29 prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]] 30 31

KeyError: -1

tianke0711 avatar Nov 18 '18 02:11 tianke0711

Which tensorflow version are you using?

dongjun-Lee avatar Nov 19 '18 05:11 dongjun-Lee

hi @dongjun-Lee thanks for your response, I am using tensorflow==1.4.1. Could you left you email that so I can contact you to ask question, please!

tianke0711 avatar Nov 21 '18 06:11 tianke0711

Hi @tianke0711 , it seems the error occurs because of your tensorflow version. Could you please try after upgrading tensorflow to >=1.8? My e-mail is [email protected]. Thank you.

dongjun-Lee avatar Nov 21 '18 06:11 dongjun-Lee

Hi @tianke0711 , it seems the error occurs because of your tensorflow version. Could you please try after upgrading tensorflow to >=1.8? My e-mail is [email protected]. Thank you.

thanks for your kind comments. If I have issues, I will contact you.

tianke0711 avatar Jan 15 '19 01:01 tianke0711

I am also getting a similar error

Traceback (most recent call last):
  File "test.py", line 36, in <module>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
  File "test.py", line 36, in <listcomp>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
  File "test.py", line 36, in <listcomp>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
KeyError: -1

deepbodra97 avatar Feb 13 '19 14:02 deepbodra97

Hi @tianke0711 , it seems the error occurs because of your tensorflow version. Could you please try after upgrading tensorflow to >=1.8? My e-mail is [email protected]. Thank you.

thanks for your kind comments. If I have issues, I will contact you.

Has upgrading to a higher version of tensorflow worked?

yash-1997 avatar Apr 16 '19 18:04 yash-1997

I am also getting a similar error

Traceback (most recent call last):
  File "test.py", line 36, in <module>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
  File "test.py", line 36, in <listcomp>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
  File "test.py", line 36, in <listcomp>
    prediction_output = [[reversed_dict[y] for y in x] for x in prediction[:, 0, :]]
KeyError: -1

Were you able to resolve the issue? If so, how?

yash-1997 avatar Apr 16 '19 18:04 yash-1997