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
7a99e4b1
Commit
7a99e4b1
authored
Sep 26, 2019
by
thomwolf
Browse files
fix #1196 and fix #1285
parent
7c9f8f93
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
pytorch_transformers/tokenization_gpt2.py
pytorch_transformers/tokenization_gpt2.py
+9
-3
No files found.
pytorch_transformers/tokenization_gpt2.py
View file @
7a99e4b1
...
@@ -173,9 +173,15 @@ class GPT2Tokenizer(PreTrainedTokenizer):
...
@@ -173,9 +173,15 @@ class GPT2Tokenizer(PreTrainedTokenizer):
self
.
cache
[
token
]
=
word
self
.
cache
[
token
]
=
word
return
word
return
word
def
_tokenize
(
self
,
text
):
def
_tokenize
(
self
,
text
,
add_prefix_space
=
False
):
""" Tokenize a string. """
""" Tokenize a string.
text
=
' '
+
text
# GPT-2 (and RoBERTa) tokenizers need at least one space to begin the sentence with.
Args:
- add_prefix_space (boolean, default False):
Begin the sentence with at least one space toto get invariance to word order in GPT-2 (and RoBERTa) tokenizers.
"""
if
add_prefix_space
:
text
=
' '
+
text
bpe_tokens
=
[]
bpe_tokens
=
[]
for
token
in
re
.
findall
(
self
.
pat
,
text
):
for
token
in
re
.
findall
(
self
.
pat
,
text
):
if
sys
.
version_info
[
0
]
==
2
:
if
sys
.
version_info
[
0
]
==
2
:
...
...
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