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
aeef4823
Unverified
Commit
aeef4823
authored
Dec 25, 2019
by
Thomas Wolf
Committed by
GitHub
Dec 25, 2019
Browse files
Merge pull request #2303 from patrickvonplaten/fix_error_with_repetition_penalty
fix repetition penalty error in modeling_utils.py
parents
0412f3d9
18e5bdbe
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 @
aeef4823
...
...
@@ -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