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
ab984a8b
"tests/pipelines/vscode:/vscode.git/clone" did not exist on "53377ef83c6446033f3ee506e3ef718db817b293"
Commit
ab984a8b
authored
Sep 19, 2019
by
LysandreJik
Browse files
Python 2 compatibility
parent
3df208c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
pytorch_transformers/tokenization_utils.py
pytorch_transformers/tokenization_utils.py
+7
-7
No files found.
pytorch_transformers/tokenization_utils.py
View file @
ab984a8b
...
@@ -707,14 +707,14 @@ class PreTrainedTokenizer(object):
...
@@ -707,14 +707,14 @@ class PreTrainedTokenizer(object):
"""
"""
if
text_pair
is
None
:
if
text_pair
is
None
:
if
add_special_tokens
:
if
add_special_tokens
:
sequence_tokens
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
tr
)
else
text
sequence_tokens
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
ix
.
string_types
)
else
text
return
self
.
add_special_tokens_single_sequence
(
sequence_tokens
)
return
self
.
add_special_tokens_single_sequence
(
sequence_tokens
)
else
:
else
:
ids
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
tr
)
else
text
ids
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
ix
.
string_types
)
else
text
return
ids
return
ids
first_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text
,
**
kwargs
)]
if
isinstance
(
text
,
s
tr
)
else
text
first_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text
,
**
kwargs
)]
if
isinstance
(
text
,
s
ix
.
string_types
)
else
text
second_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text_pair
,
**
kwargs
)]
if
isinstance
(
text_pair
,
s
tr
)
else
text_pair
second_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text_pair
,
**
kwargs
)]
if
isinstance
(
text_pair
,
s
ix
.
string_types
)
else
text_pair
if
add_special_tokens
:
if
add_special_tokens
:
return
self
.
add_special_tokens_sequence_pair
(
first_sentence_tokens
,
second_sentence_tokens
)
return
self
.
add_special_tokens_sequence_pair
(
first_sentence_tokens
,
second_sentence_tokens
)
...
@@ -754,7 +754,7 @@ class PreTrainedTokenizer(object):
...
@@ -754,7 +754,7 @@ class PreTrainedTokenizer(object):
information
=
{}
information
=
{}
if
text_pair
is
None
:
if
text_pair
is
None
:
sequence_tokens
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
tr
)
else
text
sequence_tokens
=
self
.
convert_tokens_to_ids
(
self
.
tokenize
(
text
,
**
kwargs
))
if
isinstance
(
text
,
s
ix
.
string_types
)
else
text
if
add_special_tokens
:
if
add_special_tokens
:
information
=
self
.
prepare_for_model
(
sequence_tokens
,
max_length
,
stride
)
information
=
self
.
prepare_for_model
(
sequence_tokens
,
max_length
,
stride
)
else
:
else
:
...
@@ -766,8 +766,8 @@ class PreTrainedTokenizer(object):
...
@@ -766,8 +766,8 @@ class PreTrainedTokenizer(object):
if
output_mask
:
if
output_mask
:
information
[
"mask"
]
=
[
0
]
*
len
(
information
[
"sequence"
])
information
[
"mask"
]
=
[
0
]
*
len
(
information
[
"sequence"
])
else
:
else
:
first_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text
,
**
kwargs
)]
if
isinstance
(
text
,
s
tr
)
else
text
first_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text
,
**
kwargs
)]
if
isinstance
(
text
,
s
ix
.
string_types
)
else
text
second_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text_pair
,
**
kwargs
)]
if
isinstance
(
text_pair
,
s
tr
)
else
text_pair
second_sentence_tokens
=
[
self
.
_convert_token_to_id
(
token
)
for
token
in
self
.
tokenize
(
text_pair
,
**
kwargs
)]
if
isinstance
(
text_pair
,
s
ix
.
string_types
)
else
text_pair
if
add_special_tokens
:
if
add_special_tokens
:
information
=
self
.
prepare_pair_for_model
(
information
=
self
.
prepare_pair_for_model
(
...
...
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