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
64743d0a
"vscode:/vscode.git/clone" did not exist on "218d552f306fefc34b60fee8135b976c3ab5807f"
Unverified
Commit
64743d0a
authored
Oct 11, 2021
by
Lukas Weiner
Committed by
GitHub
Oct 11, 2021
Browse files
Raise exceptions instead of asserts (#13938)
parent
32634bce
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
src/transformers/data/processors/utils.py
src/transformers/data/processors/utils.py
+10
-10
No files found.
src/transformers/data/processors/utils.py
View file @
64743d0a
...
...
@@ -196,12 +196,12 @@ class SingleSentenceClassificationProcessor(DataProcessor):
def
add_examples
(
self
,
texts_or_text_and_labels
,
labels
=
None
,
ids
=
None
,
overwrite_labels
=
False
,
overwrite_examples
=
False
):
assert
labels
is
None
or
len
(
texts_or_text_and_labels
)
=
=
len
(
labels
),
f
"Text and labels have mismatched lengths
{
len
(
texts_or_text_and_labels
)
}
and
{
len
(
labels
)
}
"
assert
ids
is
None
or
len
(
texts_or_text_and_labels
)
==
len
(
ids
),
f
"Text and ids have mismatched lengths
{
len
(
texts_or_text_and_labels
)
}
and
{
len
(
ids
)
}
"
if
labels
is
not
None
and
len
(
texts_or_text_and_labels
)
!
=
len
(
labels
):
raise
ValueError
(
f
"Text and labels have mismatched lengths
{
len
(
texts_or_text_and_labels
)
}
and
{
len
(
labels
)
}
"
)
if
ids
is
not
None
and
len
(
texts_or_text_and_labels
)
!=
len
(
ids
):
raise
ValueError
(
f
"Text and ids have mismatched lengths
{
len
(
texts_or_text_and_labels
)
}
and
{
len
(
ids
)
}
"
)
if
ids
is
None
:
ids
=
[
None
]
*
len
(
texts_or_text_and_labels
)
if
labels
is
None
:
...
...
@@ -293,10 +293,10 @@ class SingleSentenceClassificationProcessor(DataProcessor):
input_ids
=
input_ids
+
([
pad_token
]
*
padding_length
)
attention_mask
=
attention_mask
+
([
0
if
mask_padding_with_zero
else
1
]
*
padding_length
)
assert
len
(
input_ids
)
==
batch_length
,
f
"Error with input length
{
len
(
input_ids
)
}
vs
{
batch_length
}
"
assert
(
len
(
attention_mask
)
=
=
batch_length
),
f
"Error with input length
{
len
(
attention_mask
)
}
vs
{
batch_length
}
"
if
len
(
input_ids
)
!=
batch_length
:
raise
ValueError
(
f
"Error with input length
{
len
(
input_ids
)
}
vs
{
batch_length
}
"
)
if
len
(
attention_mask
)
!
=
batch_length
:
raise
ValueError
(
f
"Error with input length
{
len
(
attention_mask
)
}
vs
{
batch_length
}
"
)
if
self
.
mode
==
"classification"
:
label
=
label_map
[
example
.
label
]
...
...
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