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

Notebook: Question Answering on SQUAD: IndexError: list index out of range #141

Open
maggiezha opened this issue Feb 5, 2022 · 2 comments

Comments

@maggiezha
Copy link

maggiezha commented Feb 5, 2022

Hello, I am running this notebook Question Answering on SQUAD using Colab: https://colab.research.google.com/github/huggingface/notebooks/blob/master/examples/question_answering.ipynb

I got the IndexError in this step, could you please have a look how to fix it? Thanks!

final_predictions = postprocess_qa_predictions(datasets["validation"], validation_features, raw_predictions.predictions)

This is the output:

Post-processing 10570 example predictions split into 10784 features.
9%
1000/10570 [00:02<00:22, 420.59it/s]


IndexError Traceback (most recent call last)
in ()
----> 1 final_predictions = postprocess_qa_predictions(datasets["validation"], validation_features, raw_predictions.predictions)

in postprocess_qa_predictions(examples, features, raw_predictions, n_best_size, max_answer_length)
57 continue
58
---> 59 start_char = offset_mapping[start_index][0]
60 end_char = offset_mapping[end_index][1]
61 valid_answers.append(

IndexError: list index out of range

@subhasisj
Copy link

I get the same error. Please share if you were able to get past it.

@dennishnf
Copy link

I experienced the same problem. I solved this issue in the following way:

In the evaluation part, more exactly in function: postprocess_qa_predictions, add the next conditions to the if statement (in order to don't consider out-of-scope answers): offset_mapping[start_index] == [] and offset_mapping[end_index] == []

Check below the before and after of the proposed solution.

Before:

    if (
        start_index >= len(offset_mapping)
        or end_index >= len(offset_mapping)
        or offset_mapping[start_index] is None
        or offset_mapping[end_index] is None
    ):

After:

    if (
        start_index >= len(offset_mapping)
        or end_index >= len(offset_mapping)
        or offset_mapping[start_index] is None
        or offset_mapping[end_index] is None
        or offset_mapping[start_index] == []
        or offset_mapping[end_index] == []
    ):

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

3 participants