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
67403413
Unverified
Commit
67403413
authored
Sep 20, 2022
by
Ankur Goyal
Committed by
GitHub
Sep 20, 2022
Browse files
Change document question answering pipeline to always return an array (#19071)
Co-authored-by:
Ankur Goyal
<
ankur@impira.com
>
parent
cc567e00
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
3 deletions
+1
-3
src/transformers/pipelines/document_question_answering.py
src/transformers/pipelines/document_question_answering.py
+0
-2
tests/pipelines/test_pipelines_document_question_answering.py
...s/pipelines/test_pipelines_document_question_answering.py
+1
-1
No files found.
src/transformers/pipelines/document_question_answering.py
View file @
67403413
...
@@ -383,8 +383,6 @@ class DocumentQuestionAnsweringPipeline(Pipeline):
...
@@ -383,8 +383,6 @@ class DocumentQuestionAnsweringPipeline(Pipeline):
answers
=
self
.
postprocess_extractive_qa
(
model_outputs
,
top_k
=
top_k
,
**
kwargs
)
answers
=
self
.
postprocess_extractive_qa
(
model_outputs
,
top_k
=
top_k
,
**
kwargs
)
answers
=
sorted
(
answers
,
key
=
lambda
x
:
x
.
get
(
"score"
,
0
),
reverse
=
True
)[:
top_k
]
answers
=
sorted
(
answers
,
key
=
lambda
x
:
x
.
get
(
"score"
,
0
),
reverse
=
True
)[:
top_k
]
if
len
(
answers
)
==
1
:
return
answers
[
0
]
return
answers
return
answers
def
postprocess_donut
(
self
,
model_outputs
,
**
kwargs
):
def
postprocess_donut
(
self
,
model_outputs
,
**
kwargs
):
...
...
tests/pipelines/test_pipelines_document_question_answering.py
View file @
67403413
...
@@ -267,7 +267,7 @@ class DocumentQuestionAnsweringPipelineTests(unittest.TestCase, metaclass=Pipeli
...
@@ -267,7 +267,7 @@ class DocumentQuestionAnsweringPipelineTests(unittest.TestCase, metaclass=Pipeli
image
=
INVOICE_URL
image
=
INVOICE_URL
question
=
"What is the invoice number?"
question
=
"What is the invoice number?"
outputs
=
dqa_pipeline
(
image
=
image
,
question
=
question
,
top_k
=
2
)
outputs
=
dqa_pipeline
(
image
=
image
,
question
=
question
,
top_k
=
2
)
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
{
"answer"
:
"us-001"
})
self
.
assertEqual
(
nested_simplify
(
outputs
,
decimals
=
4
),
[
{
"answer"
:
"us-001"
}
]
)
@
require_tf
@
require_tf
@
unittest
.
skip
(
"Document question answering not implemented in TF"
)
@
unittest
.
skip
(
"Document question answering not implemented in TF"
)
...
...
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