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
f39217a5
Commit
f39217a5
authored
Apr 23, 2020
by
Julien Chaumond
Browse files
[tests] Light cleanup of tempfile in tests/
parent
f54dc3f4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
tests/test_tokenization_common.py
tests/test_tokenization_common.py
+12
-15
No files found.
tests/test_tokenization_common.py
View file @
f39217a5
...
...
@@ -107,15 +107,14 @@ class TokenizerTesterMixin:
before_tokens
=
tokenizer
.
encode
(
"He is very happy, UNwant
\u00E9
d,running"
,
add_special_tokens
=
False
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
tokenizer
.
save_pretrained
(
tmpdirname
)
tokenizer
=
self
.
tokenizer_class
.
from_pretrained
(
tmpdirname
)
tokenizer
.
save_pretrained
(
self
.
tmpdirname
)
tokenizer
=
self
.
tokenizer_class
.
from_pretrained
(
self
.
tmpdirname
)
after_tokens
=
tokenizer
.
encode
(
"He is very happy, UNwant
\u00E9
d,running"
,
add_special_tokens
=
False
)
self
.
assertListEqual
(
before_tokens
,
after_tokens
)
self
.
assertEqual
(
tokenizer
.
max_len
,
42
)
tokenizer
=
self
.
tokenizer_class
.
from_pretrained
(
tmpdirname
,
max_len
=
43
)
tokenizer
=
self
.
tokenizer_class
.
from_pretrained
(
self
.
tmpdirname
,
max_len
=
43
)
self
.
assertEqual
(
tokenizer
.
max_len
,
43
)
def
test_pickle_tokenizer
(
self
):
...
...
@@ -125,9 +124,7 @@ class TokenizerTesterMixin:
text
=
"Munich and Berlin are nice cities"
subwords
=
tokenizer
.
tokenize
(
text
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
filename
=
os
.
path
.
join
(
tmpdirname
,
"tokenizer.bin"
)
filename
=
os
.
path
.
join
(
self
.
tmpdirname
,
"tokenizer.bin"
)
with
open
(
filename
,
"wb"
)
as
handle
:
pickle
.
dump
(
tokenizer
,
handle
)
...
...
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