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
0eabe492
"git@developer.sourcefind.cn:xdb4_94051/vllm.git" did not exist on "80a2f812f17add5838f84288054fbe0b915622cc"
Unverified
Commit
0eabe492
authored
Sep 24, 2021
by
Nicolas Patry
Committed by
GitHub
Sep 24, 2021
Browse files
Fixing zero-shot backward compatiblity (#13725)
Fixes #13697
parent
a2ef9c54
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
src/transformers/pipelines/zero_shot_classification.py
src/transformers/pipelines/zero_shot_classification.py
+8
-0
tests/test_pipelines_zero_shot.py
tests/test_pipelines_zero_shot.py
+4
-0
No files found.
src/transformers/pipelines/zero_shot_classification.py
View file @
0eabe492
...
...
@@ -150,6 +150,7 @@ class ZeroShotClassificationPipeline(Pipeline):
def
__call__
(
self
,
sequences
:
Union
[
str
,
List
[
str
]],
*
args
,
**
kwargs
,
):
"""
...
...
@@ -183,6 +184,13 @@ class ZeroShotClassificationPipeline(Pipeline):
- **scores** (:obj:`List[float]`) -- The probabilities for each of the labels.
"""
if
len
(
args
)
==
0
:
pass
elif
len
(
args
)
==
1
and
"candidate_labels"
not
in
kwargs
:
kwargs
[
"candidate_labels"
]
=
args
[
0
]
else
:
raise
ValueError
(
f
"Unable to understand extra arguments
{
args
}
"
)
result
=
super
().
__call__
(
sequences
,
**
kwargs
)
if
len
(
result
)
==
1
:
return
result
[
0
]
...
...
tests/test_pipelines_zero_shot.py
View file @
0eabe492
...
...
@@ -37,6 +37,10 @@ class ZeroShotClassificationPipelineTests(unittest.TestCase, metaclass=PipelineT
outputs
=
classifier
(
"Who are you voting for in 2020?"
,
candidate_labels
=
"politics"
)
self
.
assertEqual
(
outputs
,
{
"sequence"
:
ANY
(
str
),
"labels"
:
[
ANY
(
str
)],
"scores"
:
[
ANY
(
float
)]})
# No kwarg
outputs
=
classifier
(
"Who are you voting for in 2020?"
,
[
"politics"
])
self
.
assertEqual
(
outputs
,
{
"sequence"
:
ANY
(
str
),
"labels"
:
[
ANY
(
str
)],
"scores"
:
[
ANY
(
float
)]})
outputs
=
classifier
(
"Who are you voting for in 2020?"
,
candidate_labels
=
[
"politics"
])
self
.
assertEqual
(
outputs
,
{
"sequence"
:
ANY
(
str
),
"labels"
:
[
ANY
(
str
)],
"scores"
:
[
ANY
(
float
)]})
...
...
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