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
a9515851
Commit
a9515851
authored
Oct 02, 2019
by
danai-antoniou
Browse files
Moved duplicate token check
parent
d7395789
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
4 deletions
+2
-4
transformers/tokenization_utils.py
transformers/tokenization_utils.py
+2
-4
No files found.
transformers/tokenization_utils.py
View file @
a9515851
...
@@ -508,14 +508,12 @@ class PreTrainedTokenizer(object):
...
@@ -508,14 +508,12 @@ class PreTrainedTokenizer(object):
if
not
new_tokens
:
if
not
new_tokens
:
return
0
return
0
if
len
(
new_tokens
)
!=
len
(
set
(
new_tokens
)):
raise
ValueError
(
"The provided list of tokens contains duplicates."
)
to_add_tokens
=
[]
to_add_tokens
=
[]
for
token
in
new_tokens
:
for
token
in
new_tokens
:
assert
isinstance
(
token
,
str
)
or
(
six
.
PY2
and
isinstance
(
token
,
unicode
))
assert
isinstance
(
token
,
str
)
or
(
six
.
PY2
and
isinstance
(
token
,
unicode
))
if
token
!=
self
.
unk_token
and
\
if
token
!=
self
.
unk_token
and
\
self
.
convert_tokens_to_ids
(
token
)
==
self
.
convert_tokens_to_ids
(
self
.
unk_token
):
self
.
convert_tokens_to_ids
(
token
)
==
self
.
convert_tokens_to_ids
(
self
.
unk_token
)
and
\
token
not
in
to_add_tokens
:
to_add_tokens
.
append
(
token
)
to_add_tokens
.
append
(
token
)
logger
.
info
(
"Adding %s to the vocabulary"
,
token
)
logger
.
info
(
"Adding %s to the vocabulary"
,
token
)
...
...
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