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
78863f6b
Commit
78863f6b
authored
Sep 25, 2019
by
thomwolf
Browse files
fix tokenizer to tensors
parent
8a618e0a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletion
+7
-1
pytorch_transformers/tokenization_utils.py
pytorch_transformers/tokenization_utils.py
+7
-1
No files found.
pytorch_transformers/tokenization_utils.py
View file @
78863f6b
...
...
@@ -27,6 +27,8 @@ from .file_utils import cached_path, is_tf_available, is_torch_available
if
is_tf_available
():
import
tensorflow
as
tf
if
is_torch_available
()
import
torch
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -849,7 +851,11 @@ class PreTrainedTokenizer(object):
if
return_tensors
==
'tf'
and
is_tf_available
():
sequence
=
tf
.
constant
(
sequence
)
token_type_ids
=
tf
.
constant
(
token_type_ids
)
elif
return_tensors
=
'pt'
and
is
elif
return_tensors
==
'pt'
and
is_torch_available
():
sequence
=
torch
.
tensor
(
sequence
)
token_type_ids
=
torch
.
tensor
(
token_type_ids
)
elif
return_tensors
is
not
None
:
logger
.
warning
(
"Unable to convert output to tensors format {}, PyTorch or TensorFlow is not available."
.
format
(
return_tensors
))
encoded_inputs
[
"input_ids"
]
=
sequence
encoded_inputs
[
"token_type_ids"
]
=
token_type_ids
...
...
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