Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why there is KeyError: -1 in prediction #28

Open
tianke0711 opened this issue Nov 18, 2018 · 7 comments
Open

why there is KeyError: -1 in prediction #28

tianke0711 opened this issue Nov 18, 2018 · 7 comments

Comments

@tianke0711
Copy link

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

@dongjun-Lee
Copy link
Owner

Which tensorflow version are you using?

@tianke0711
Copy link
Author

tianke0711 commented Nov 21, 2018

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!

@dongjun-Lee
Copy link
Owner

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 ganji1055@gmail.com.
Thank you.

@tianke0711
Copy link
Author

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 ganji1055@gmail.com.
Thank you.

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

@deepbodra97
Copy link

deepbodra97 commented Feb 13, 2019

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

@yash-1997
Copy link

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 ganji1055@gmail.com.
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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants