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
0d6c17fc
Commit
0d6c17fc
authored
Jan 13, 2020
by
Morgan Funtowicz
Browse files
black formatting
parent
f26a3530
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
13 deletions
+19
-13
src/transformers/pipelines.py
src/transformers/pipelines.py
+19
-13
No files found.
src/transformers/pipelines.py
View file @
0d6c17fc
...
@@ -705,14 +705,17 @@ class QuestionAnsweringPipeline(Pipeline):
...
@@ -705,14 +705,17 @@ class QuestionAnsweringPipeline(Pipeline):
# Convert inputs to features
# Convert inputs to features
examples
=
self
.
_args_parser
(
*
texts
,
**
kwargs
)
examples
=
self
.
_args_parser
(
*
texts
,
**
kwargs
)
features_list
=
[
squad_convert_examples_to_features
(
features_list
=
[
[
example
],
squad_convert_examples_to_features
(
self
.
tokenizer
,
[
example
],
kwargs
[
"max_seq_len"
],
self
.
tokenizer
,
kwargs
[
"doc_stride"
],
kwargs
[
"max_seq_len"
],
kwargs
[
"max_question_len"
],
kwargs
[
"doc_stride"
],
False
kwargs
[
"max_question_len"
],
)
for
example
in
examples
]
False
,
)
for
example
in
examples
]
all_answers
=
[]
all_answers
=
[]
for
features
,
example
in
zip
(
features_list
,
examples
):
for
features
,
example
in
zip
(
features_list
,
examples
):
fw_args
=
self
.
inputs_for_model
([
f
.
__dict__
for
f
in
features
])
fw_args
=
self
.
inputs_for_model
([
f
.
__dict__
for
f
in
features
])
...
@@ -737,7 +740,10 @@ class QuestionAnsweringPipeline(Pipeline):
...
@@ -737,7 +740,10 @@ class QuestionAnsweringPipeline(Pipeline):
end_
=
np
.
exp
(
end_
)
/
np
.
sum
(
np
.
exp
(
end_
))
end_
=
np
.
exp
(
end_
)
/
np
.
sum
(
np
.
exp
(
end_
))
# Mask padding and question
# Mask padding and question
start_
,
end_
=
start_
*
np
.
abs
(
np
.
array
(
feature
.
p_mask
)
-
1
),
end_
*
np
.
abs
(
np
.
array
(
feature
.
p_mask
)
-
1
)
start_
,
end_
=
(
start_
*
np
.
abs
(
np
.
array
(
feature
.
p_mask
)
-
1
),
end_
*
np
.
abs
(
np
.
array
(
feature
.
p_mask
)
-
1
),
)
# TODO : What happens if not possible
# TODO : What happens if not possible
# Mask CLS
# Mask CLS
...
@@ -758,11 +764,11 @@ class QuestionAnsweringPipeline(Pipeline):
...
@@ -758,11 +764,11 @@ class QuestionAnsweringPipeline(Pipeline):
}
}
for
s
,
e
,
score
in
zip
(
starts
,
ends
,
scores
)
for
s
,
e
,
score
in
zip
(
starts
,
ends
,
scores
)
]
]
answers
=
sorted
(
answers
,
key
=
lambda
x
:
x
[
'
score
'
],
reverse
=
True
)[:
kwargs
[
"topk"
]]
answers
=
sorted
(
answers
,
key
=
lambda
x
:
x
[
"
score
"
],
reverse
=
True
)[:
kwargs
[
"topk"
]]
all_answers
+=
answers
all_answers
+=
answers
if
len
(
all_answers
)
==
1
:
if
len
(
all_answers
)
==
1
:
return
all_answers
[
0
]
return
all_answers
[
0
]
return
all_answers
return
all_answers
def
decode
(
self
,
start
:
np
.
ndarray
,
end
:
np
.
ndarray
,
topk
:
int
,
max_answer_len
:
int
)
->
Tuple
:
def
decode
(
self
,
start
:
np
.
ndarray
,
end
:
np
.
ndarray
,
topk
:
int
,
max_answer_len
:
int
)
->
Tuple
:
...
...
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