Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
18e5bdbe
Commit
18e5bdbe
authored
Dec 24, 2019
by
patrickvonplaten
Browse files
fix repetition penalty error in modeling_utils.py
parent
81db12c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+10
-2
No files found.
src/transformers/modeling_utils.py
View file @
18e5bdbe
...
...
@@ -728,7 +728,11 @@ class PreTrainedModel(nn.Module):
if
repetition_penalty
!=
1.0
:
for
i
in
range
(
batch_size
):
for
previous_tokens
in
set
(
input_ids
[
i
].
tolist
()):
next_token_logits
[
i
,
previous_tokens
]
/=
repetition_penalty
# if score < 0 then repetition penalty has to multiplied to reduce the previous token probability
if
next_token_logits
[
i
,
previous_tokens
]
<
0
:
next_token_logits
[
i
,
previous_tokens
]
*=
repetition_penalty
else
:
next_token_logits
[
i
,
previous_tokens
]
/=
repetition_penalty
if
do_sample
:
# Temperature (higher temperature => more likely to sample low probability tokens)
...
...
@@ -807,7 +811,11 @@ class PreTrainedModel(nn.Module):
if
repetition_penalty
!=
1.0
:
for
i
in
range
(
batch_size
*
num_beams
):
for
previous_tokens
in
set
(
input_ids
[
i
].
tolist
()):
scores
[
i
,
previous_tokens
]
/=
repetition_penalty
# if score < 0 then repetition penalty has to multiplied to reduce the previous token probability
if
scores
[
i
,
previous_tokens
]
<
0
:
scores
[
i
,
previous_tokens
]
*=
repetition_penalty
else
:
scores
[
i
,
previous_tokens
]
/=
repetition_penalty
if
do_sample
:
# Temperature (higher temperature => more likely to sample low probability tokens)
...
...
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