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
3c12e3c1
Unverified
Commit
3c12e3c1
authored
Mar 24, 2021
by
Lysandre Debut
Committed by
GitHub
Mar 24, 2021
Browse files
Fix overflowing bad word ids (#10889)
* Removes overflowing bad word IDs * Raise warning
parent
1f5ea9e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
src/transformers/generation_logits_process.py
src/transformers/generation_logits_process.py
+12
-1
No files found.
src/transformers/generation_logits_process.py
View file @
3c12e3c1
...
...
@@ -22,6 +22,10 @@ import numpy as np
import
torch
from
.file_utils
import
add_start_docstrings
from
.utils.logging
import
get_logger
logger
=
get_logger
(
__name__
)
LOGITS_PROCESSOR_INPUTS_DOCSTRING
=
r
"""
...
...
@@ -417,7 +421,14 @@ class NoBadWordsLogitsProcessor(LogitsProcessor):
banned_mask_list
=
[]
for
idx
,
batch_banned_tokens
in
enumerate
(
banned_tokens
):
for
token
in
batch_banned_tokens
:
banned_mask_list
.
append
([
idx
,
token
])
# Eliminates invalid bad word IDs that are over the vocabulary size.
if
token
<=
scores
.
shape
[
1
]:
banned_mask_list
.
append
([
idx
,
token
])
else
:
logger
.
error
(
f
"An invalid bad word ID is defined:
{
token
}
. This ID is not contained in the"
f
"vocabulary, and is therefore ignored."
)
if
not
banned_mask_list
:
return
scores
...
...
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