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

list index out of range when trying to predict #10

Closed
guilhermenoronha opened this issue Oct 8, 2020 · 4 comments
Closed

list index out of range when trying to predict #10

guilhermenoronha opened this issue Oct 8, 2020 · 4 comments

Comments

@guilhermenoronha
Copy link

Hello,

My code is getting the error of 'list index out of range' when I try to predict a sentence from the model. A analyzed your code but couldn't figure out what could it be.

Here is my code:

    model = WordsTagger(model_dir='name_model')
    tags, sequences = model([["meu", "amigo", "e", "senhor", "."]])
    print(tags)  
    print(sequences)

Here is the log:

`Traceback (most recent call last):

  File "C:\Users\guilh\OneDrive\Textos e Documentação\workspace\BI-LSTM-CRF Cartas\bilstmprocessor.py", line 30, in <module>
    predict_text()

  File "C:\Users\guilh\OneDrive\Textos e Documentação\workspace\BI-LSTM-CRF Cartas\bilstmprocessor.py", line 26, in predict_text
    tags, sequences = model([["meu", "amigo", "e", "senhor", "."]])

  File "C:\Users\guilh\anaconda3\envs\bilstm_cartas\lib\site-packages\bi_lstm_crf\app\predict.py", line 40, in __call__
    return tags, self.tokens_from_tags(sentences, tags, begin_tags=begin_tags)

  File "C:\Users\guilh\anaconda3\envs\bilstm_cartas\lib\site-packages\bi_lstm_crf\app\predict.py", line 64, in tokens_from_tags
    tokens_list = [_tokens(sentence, ts) for sentence, ts in zip(sentences, tags_list)]

  File "C:\Users\guilh\anaconda3\envs\bilstm_cartas\lib\site-packages\bi_lstm_crf\app\predict.py", line 64, in <listcomp>
    tokens_list = [_tokens(sentence, ts) for sentence, ts in zip(sentences, tags_list)]

  File "C:\Users\guilh\anaconda3\envs\bilstm_cartas\lib\site-packages\bi_lstm_crf\app\predict.py", line 56, in _tokens
    begins = [b for idx, b in enumerate(begins) if idx == 0 or ts[idx] != "O" or ts[idx - 1] != "O"]

  File "C:\Users\guilh\anaconda3\envs\bilstm_cartas\lib\site-packages\bi_lstm_crf\app\predict.py", line 56, in <listcomp>
    begins = [b for idx, b in enumerate(begins) if idx == 0 or ts[idx] != "O" or ts[idx - 1] != "O"]

IndexError: list index out of range`

I'd appreciate any help. Thanks in advance. Best regards.

guilhermenoronha added a commit to guilhermenoronha/bi-lstm-crf that referenced this issue Oct 22, 2020
@jidasheng
Copy link
Owner

Hello, I can't fix the problem with the information you provide.
You can go inside the code in predict.py and print more info.
More specifically, print all inputs of the function "tokens_from_tags", the value of "begins" before the crash.

@guilhermenoronha
Copy link
Author

Please, check if the prints I've sent to you are enough. If not, let me know it. Best regards.

print 1
print 2
print 3

@jidasheng
Copy link
Owner

The bug is fixed in the new version 0.2.1. You can upgrade and try again.
Thanks for submitting the issue!

@guilhermenoronha
Copy link
Author

Worked! Thx!

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

2 participants