Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c3df2136
Commit
c3df2136
authored
Sep 02, 2019
by
LysandreJik
Browse files
Added binary masking tests
parent
e391d473
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
0 deletions
+14
-0
pytorch_transformers/tests/tokenization_tests_commons.py
pytorch_transformers/tests/tokenization_tests_commons.py
+12
-0
pytorch_transformers/tokenization_utils.py
pytorch_transformers/tokenization_utils.py
+2
-0
No files found.
pytorch_transformers/tests/tokenization_tests_commons.py
View file @
c3df2136
...
@@ -186,3 +186,15 @@ class CommonTestCases:
...
@@ -186,3 +186,15 @@ class CommonTestCases:
for
weights_list_2
in
weights_lists_2
:
for
weights_list_2
in
weights_lists_2
:
self
.
assertListEqual
(
weights_list
,
weights_list_2
)
self
.
assertListEqual
(
weights_list
,
weights_list_2
)
def
test_mask_output
(
self
):
if
sys
.
version_info
<=
(
3
,
0
):
return
tokenizer
=
self
.
get_tokenizer
()
if
tokenizer
.
add_special_tokens_sentences_pair
.
__qualname__
.
split
(
'.'
)[
0
]
!=
"PreTrainedTokenizer"
:
seq_0
=
"Test this method."
seq_1
=
"With these inputs."
sequences
,
mask
=
tokenizer
.
encode
(
seq_0
,
seq_1
,
add_special_tokens
=
True
,
output_mask
=
True
)
assert
len
(
sequences
)
==
len
(
mask
)
pytorch_transformers/tokenization_utils.py
View file @
c3df2136
...
@@ -690,6 +690,8 @@ class PreTrainedTokenizer(object):
...
@@ -690,6 +690,8 @@ class PreTrainedTokenizer(object):
if
add_special_tokens
:
if
add_special_tokens
:
return
self
.
add_special_tokens_sentences_pair
(
first_sentence_tokens
,
second_sentence_tokens
,
output_mask
)
return
self
.
add_special_tokens_sentences_pair
(
first_sentence_tokens
,
second_sentence_tokens
,
output_mask
)
else
:
else
:
if
output_mask
:
logger
.
warning
(
"Can't output mask if no special tokens are involved. Please call the method with add_special_tokens set to True."
)
return
first_sentence_tokens
,
second_sentence_tokens
return
first_sentence_tokens
,
second_sentence_tokens
def
add_special_tokens_single_sentence
(
self
,
token_ids
):
def
add_special_tokens_single_sentence
(
self
,
token_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