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
ba286fe7
Unverified
Commit
ba286fe7
authored
May 31, 2022
by
Patrick von Platen
Committed by
GitHub
May 31, 2022
Browse files
[GPT2Tokenizer] Fix GPT2 with bos token (#17498)
parent
7822a9b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
0 deletions
+11
-0
src/transformers/models/gpt2/tokenization_gpt2_fast.py
src/transformers/models/gpt2/tokenization_gpt2_fast.py
+11
-0
No files found.
src/transformers/models/gpt2/tokenization_gpt2_fast.py
View file @
ba286fe7
...
...
@@ -146,6 +146,17 @@ class GPT2TokenizerFast(PreTrainedTokenizerFast):
**
kwargs
,
)
if
kwargs
.
pop
(
"add_bos_token"
,
False
):
model_id
=
kwargs
.
pop
(
"name_or_path"
,
""
)
raise
ValueError
(
"Currenty GPT2's fast tokenizer does NOT support adding a BOS token."
"Instead you should use GPT2's slow tokenizer class `GPT2Tokenizer` as follows:
\n
"
f
"`GPT2Tokenizer.from_pretrained('
{
model_id
}
')`
\n
or
\n
"
f
"`AutoTokenizer.from_pretrained('
{
model_id
}
', use_fast=False)`
\n
"
"This issue will be fixed soon, see: https://github.com/huggingface/tokenizers/pull/1005."
" so that the fast tokenizer works correctly."
)
pre_tok_state
=
json
.
loads
(
self
.
backend_tokenizer
.
pre_tokenizer
.
__getstate__
())
if
pre_tok_state
.
get
(
"add_prefix_space"
,
add_prefix_space
)
!=
add_prefix_space
:
pre_tok_class
=
getattr
(
pre_tokenizers
,
pre_tok_state
.
pop
(
"type"
))
...
...
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