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
aa4198a2
Unverified
Commit
aa4198a2
authored
Oct 27, 2023
by
Arthur
Committed by
GitHub
Oct 27, 2023
Browse files
[`T5Tokenizer`] Fix fast and extra tokens (#27085)
* v4.35.dev.0 * nit t5fast match t5 slow
parent
6f316016
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
src/transformers/models/t5/tokenization_t5_fast.py
src/transformers/models/t5/tokenization_t5_fast.py
+8
-6
No files found.
src/transformers/models/t5/tokenization_t5_fast.py
View file @
aa4198a2
...
...
@@ -118,17 +118,19 @@ class T5TokenizerFast(PreTrainedTokenizerFast):
**
kwargs
,
):
# Add extra_ids to the special token list
if
extra_ids
>
0
and
additional_special_tokens
is
None
:
additional_special_tokens
=
[
f
"<extra_id_
{
i
}
>"
for
i
in
range
(
extra_ids
)]
elif
extra_ids
>
0
and
additional_special_tokens
is
not
None
:
# Check that we have the right number of extra special tokens
extra_tokens
=
len
(
set
(
filter
(
lambda
x
:
bool
(
"extra_id_"
in
str
(
x
)),
additional_special_tokens
)))
if
extra_tokens
!=
extra_ids
:
if
additional_special_tokens
is
not
None
:
extra_tokens
=
[
x
for
x
in
additional_special_tokens
if
"<extra_id_"
in
str
(
x
)]
if
len
(
extra_tokens
)
<
1
:
additional_special_tokens
+=
[
f
"<extra_id_
{
i
}
>"
for
i
in
range
(
extra_ids
)]
elif
extra_ids
>
0
and
extra_ids
!=
len
(
extra_tokens
):
raise
ValueError
(
f
"Both extra_ids (
{
extra_ids
}
) and additional_special_tokens (
{
additional_special_tokens
}
) are"
" provided to T5Tokenizer. In this case the additional_special_tokens must include the extra_ids"
" tokens"
)
else
:
extra_tokens
=
[
f
"<extra_id_
{
i
}
>"
for
i
in
range
(
extra_ids
)]
additional_special_tokens
=
extra_tokens
super
().
__init__
(
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