question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

QuestionAnsweringPipeline cannot handle impossible answer

See original GitHub issue

Environment info

  • transformers version: latest master. I think the bug was introduced by this PR: #13873 so it’s part of transformers since the 4.11.3 release and I can confirm that I didn’t see this bug with the 4.11.2 release.
  • Platform: linux
  • Python version: 3.8
  • PyTorch version (GPU?): 1.9 (same with 1.10)
  • Using GPU in script?: yes
  • Using distributed or parallel set-up in script?:

Who can help

Hi @Narsil I hope you could look again at #13873 and check the changes it makes for the case when handle_impossible_answer is True. Thanks a lot!

To reproduce

Steps to reproduce the behavior:

  1. Find the run_pipeline_test test in test_pipelines_question_answering.py
  2. Set handle_impossible_answer to Truein the question_answerer so that the code is the following:
    def run_pipeline_test(self, question_answerer, _):
        outputs = question_answerer(
            question="Where was HuggingFace founded ?", context="HuggingFace was founded in Paris.", handle_impossible_answer=True
        )
        self.assertEqual(outputs, {"answer": ANY(str), "start": ANY(int), "end": ANY(int), "score": ANY(float)})

        outputs = question_answerer(
            question=["In what field is HuggingFace working ?", "In what field is HuggingFace working ?"],
            context="HuggingFace was founded in Paris.",
        )
  1. When running this modified test, it fails with a ValueError:
            # Normalize logits and spans to retrieve the answer
            start_ = np.exp(start_ - np.log(np.sum(np.exp(start_), axis=-1, keepdims=True)))
            end_ = np.exp(end_ - np.log(np.sum(np.exp(end_), axis=-1, keepdims=True)))

            if handle_impossible_answer:
>               min_null_score = min(min_null_score, (start_[0] * end_[0]).item())
E               ValueError: can only convert an array of size 1 to a Python scalar

../src/transformers/pipelines/question_answering.py:415: ValueError

Expected behavior

Test should run through.

Additional Info

I came across this problem when upgrading the transformers dependency of haystack and ran our tests with different versions of transformers to find the last working release/first failing release: https://github.com/deepset-ai/haystack/pull/1659

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
shaked571commented, Dec 13, 2021

Perfect, just found the bug myself and saw this fix. Super cool! thanks!

2reactions
Narsilcommented, Nov 4, 2021

Thanks for the detail issue, very easy to reproduce, and everything is correct.

I am creating a PR to fix this, however do you have an example where this argument is needed in an obvious way ? I would love to add a meaningful test for this option (already added unit test for it)

Read more comments on GitHub >

github_iconTop Results From Across the Web

transformers.pipelines.question_answering - Hugging Face
[docs]class QuestionAnsweringArgumentHandler(ArgumentHandler): """ QuestionAnsweringPipeline requires the user to provide multiple arguments (i.e. question ...
Read more >
How can I get the score from Question-Answer Pipeline? Is ...
This is my attempt to get the score. It appears that I cannot figure out what feature.p_mask . So I could not remove...
Read more >
Inside the Question answering pipeline (TensorFlow) - YouTube
How does the question answering pipeline actually work? In this video we explore how we go from ... Your browser can't play this...
Read more >
Inside the Question answering pipeline (PyTorch) - YouTube
How does the question answering pipeline actually work? In this video we explore how we go from model predictions to finding the answer...
Read more >
Question Answering with Hugging Face Transformers - Keras
Let's take a look at what a single training example looks like. print(datasets["train"][0]).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found