Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
24b30d4d
Unverified
Commit
24b30d4d
authored
Nov 06, 2021
by
Nicolas Patry
Committed by
GitHub
Nov 06, 2021
Browse files
Handle long answer needs to be updated. (#14279)
`start_` and `end_` tensors now contain a batch_size at this point.
parent
843c326e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
src/transformers/pipelines/question_answering.py
src/transformers/pipelines/question_answering.py
+1
-1
tests/test_pipelines_question_answering.py
tests/test_pipelines_question_answering.py
+6
-0
No files found.
src/transformers/pipelines/question_answering.py
View file @
24b30d4d
...
@@ -412,7 +412,7 @@ class QuestionAnsweringPipeline(Pipeline):
...
@@ -412,7 +412,7 @@ class QuestionAnsweringPipeline(Pipeline):
end_
=
np
.
exp
(
end_
-
np
.
log
(
np
.
sum
(
np
.
exp
(
end_
),
axis
=-
1
,
keepdims
=
True
)))
end_
=
np
.
exp
(
end_
-
np
.
log
(
np
.
sum
(
np
.
exp
(
end_
),
axis
=-
1
,
keepdims
=
True
)))
if
handle_impossible_answer
:
if
handle_impossible_answer
:
min_null_score
=
min
(
min_null_score
,
(
start_
[
0
]
*
end_
[
0
]).
item
())
min_null_score
=
min
(
min_null_score
,
(
start_
[
0
,
0
]
*
end_
[
0
,
0
]).
item
())
# Mask CLS
# Mask CLS
start_
[
0
,
0
]
=
end_
[
0
,
0
]
=
0.0
start_
[
0
,
0
]
=
end_
[
0
,
0
]
=
0.0
...
...
tests/test_pipelines_question_answering.py
View file @
24b30d4d
...
@@ -50,6 +50,12 @@ class QAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
...
@@ -50,6 +50,12 @@ class QAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
question
=
"Where was HuggingFace founded ?"
,
context
=
"HuggingFace was founded in Paris."
question
=
"Where was HuggingFace founded ?"
,
context
=
"HuggingFace was founded in Paris."
)
)
self
.
assertEqual
(
outputs
,
{
"answer"
:
ANY
(
str
),
"start"
:
ANY
(
int
),
"end"
:
ANY
(
int
),
"score"
:
ANY
(
float
)})
self
.
assertEqual
(
outputs
,
{
"answer"
:
ANY
(
str
),
"start"
:
ANY
(
int
),
"end"
:
ANY
(
int
),
"score"
:
ANY
(
float
)})
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
(
outputs
=
question_answerer
(
question
=
[
"In what field is HuggingFace working ?"
,
"In what field is HuggingFace working ?"
],
question
=
[
"In what field is HuggingFace working ?"
,
"In what field is HuggingFace working ?"
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment