QuestionAnsweringPipeline cannot handle impossible answer
See original GitHub issueEnvironment 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:
- Find the
run_pipeline_test
test intest_pipelines_question_answering.py
- Set
handle_impossible_answer
toTrue
in thequestion_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.",
)
- 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:
- Created 2 years ago
- Reactions:1
- Comments:18 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perfect, just found the bug myself and saw this fix. Super cool! thanks!
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)