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
c8d719ff
Unverified
Commit
c8d719ff
authored
Jan 23, 2023
by
Joao Gante
Committed by
GitHub
Jan 23, 2023
Browse files
Generate: precision fix in compute_transition_scores doctests (#21251)
parent
e1cd7863
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
src/transformers/generation/utils.py
src/transformers/generation/utils.py
+6
-6
No files found.
src/transformers/generation/utils.py
View file @
c8d719ff
...
@@ -975,12 +975,12 @@ class GenerationMixin:
...
@@ -975,12 +975,12 @@ class GenerationMixin:
>>> generated_tokens = outputs.sequences[:, input_length:]
>>> generated_tokens = outputs.sequences[:, input_length:]
>>> for tok, score in zip(generated_tokens[0], transition_scores[0]):
>>> for tok, score in zip(generated_tokens[0], transition_scores[0]):
... # | token | token string | logits | probability
... # | token | token string | logits | probability
... print(f"| {tok:5d} | {tokenizer.decode(tok):8s} | {score.numpy():.
4
f} | {np.exp(score.numpy()):.2%}")
... print(f"| {tok:5d} | {tokenizer.decode(tok):8s} | {score.numpy():.
3
f} | {np.exp(score.numpy()):.2%}")
| 262 | the | -1.41
36
| 24.33%
| 262 | the | -1.41
4
| 24.33%
| 1110 | day | -2.60
8
9 | 7.36%
| 1110 | day | -2.609 | 7.36%
| 618 | when | -2.00
96
| 13.40%
| 618 | when | -2.0
1
0 | 13.40%
| 356 | we | -1.859
3
| 15.58%
| 356 | we | -1.859 | 15.58%
| 460 | can | -2.508
3
| 8.14%
| 460 | can | -2.508 | 8.14%
>>> # Example 2: Reconstruct the sequence scores from Beam Search
>>> # Example 2: Reconstruct the sequence scores from Beam Search
>>> outputs = model.generate(
>>> outputs = model.generate(
...
...
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