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
81a1e124
Unverified
Commit
81a1e124
authored
Oct 03, 2019
by
Lysandre Debut
Committed by
GitHub
Oct 03, 2019
Browse files
Merge pull request #1313 from enzoampil/master
Add option to use a 'stop token'
parents
ecc4f1bd
d3f24dfa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
examples/run_generation.py
examples/run_generation.py
+5
-0
No files found.
examples/run_generation.py
View file @
81a1e124
...
...
@@ -152,6 +152,8 @@ def main():
help
=
"Avoid using CUDA when available"
)
parser
.
add_argument
(
'--seed'
,
type
=
int
,
default
=
42
,
help
=
"random seed for initialization"
)
parser
.
add_argument
(
'--stop_token'
,
type
=
str
,
default
=
None
,
help
=
"Token at which text generation is stopped"
)
args
=
parser
.
parse_args
()
args
.
device
=
torch
.
device
(
"cuda"
if
torch
.
cuda
.
is_available
()
and
not
args
.
no_cuda
else
"cpu"
)
...
...
@@ -204,7 +206,10 @@ def main():
device
=
args
.
device
,
)
out
=
out
[
0
,
len
(
context_tokens
):].
tolist
()
text
=
tokenizer
.
decode
(
out
,
clean_up_tokenization_spaces
=
True
,
skip_special_tokens
=
True
)
text
=
text
[:
text
.
find
(
args
.
stop_token
)
if
args
.
stop_token
else
None
]
print
(
text
)
if
args
.
prompt
:
break
...
...
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