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
b3c6ee0a
Commit
b3c6ee0a
authored
Apr 15, 2019
by
thomwolf
Browse files
tokenization updates
parent
20577d8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
pytorch_pretrained_bert/tokenization.py
pytorch_pretrained_bert/tokenization.py
+3
-2
pytorch_pretrained_bert/tokenization_transfo_xl.py
pytorch_pretrained_bert/tokenization_transfo_xl.py
+3
-1
No files found.
pytorch_pretrained_bert/tokenization.py
View file @
b3c6ee0a
...
@@ -135,9 +135,10 @@ class BertTokenizer(object):
...
@@ -135,9 +135,10 @@ class BertTokenizer(object):
return
tokens
return
tokens
def
save_vocabulary
(
self
,
vocab_path
):
def
save_vocabulary
(
self
,
vocab_path
):
"""Save the tokenizer vocabulary to a
path
."""
"""Save the tokenizer vocabulary to a
directory or file
."""
index
=
0
index
=
0
vocab_file
=
os
.
path
.
join
(
vocab_path
,
VOCAB_NAME
)
if
os
.
path
.
isdir
(
vocab_path
):
vocab_file
=
os
.
path
.
join
(
vocab_path
,
VOCAB_NAME
)
with
open
(
vocab_file
,
"w"
,
encoding
=
"utf-8"
)
as
writer
:
with
open
(
vocab_file
,
"w"
,
encoding
=
"utf-8"
)
as
writer
:
for
token
,
token_index
in
sorted
(
self
.
vocab
.
items
(),
key
=
lambda
kv
:
kv
[
1
]):
for
token
,
token_index
in
sorted
(
self
.
vocab
.
items
(),
key
=
lambda
kv
:
kv
[
1
]):
if
index
!=
token_index
:
if
index
!=
token_index
:
...
...
pytorch_pretrained_bert/tokenization_transfo_xl.py
View file @
b3c6ee0a
...
@@ -145,8 +145,10 @@ class TransfoXLTokenizer(object):
...
@@ -145,8 +145,10 @@ class TransfoXLTokenizer(object):
raise
ValueError
(
'No <unkown> token in vocabulary'
)
raise
ValueError
(
'No <unkown> token in vocabulary'
)
def
save_vocabulary
(
self
,
vocab_path
):
def
save_vocabulary
(
self
,
vocab_path
):
"""Save the tokenizer vocabulary to a directory or file."""
index
=
0
index
=
0
vocab_file
=
os
.
path
.
join
(
vocab_path
,
VOCAB_NAME
)
if
os
.
path
.
isdir
(
vocab_path
):
vocab_file
=
os
.
path
.
join
(
vocab_path
,
VOCAB_NAME
)
torch
.
save
(
self
.
__dict__
,
vocab_file
)
torch
.
save
(
self
.
__dict__
,
vocab_file
)
return
vocab_file
return
vocab_file
...
...
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