Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/transformers/models/gpt_sw3/tokenization_gpt_sw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,19 @@ def __init__(
self.keep_accents = keep_accents

# Used for whitespace normalization in input texts
# fmt : off
self.whitespaces = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "", ""}
# fmt : on
self.whitespaces = {
"\u0020", # space
"\u2002", # en space
"\u2003", # em space
"\u2005", # four-per-em space
"\u2008", # punctuation space
"\u2009", # thin space
"\u200a", # hair space
"\u202f", # narrow no-break space
"\u3000", # ideographic space
"\ufffc", # object replacement character
"\u0084", # control character, also removed by non_printing_characters_re
}

# Regular expression to remove non-printing characters (e.g. some unicode control chars) in preprocessing
self.non_printing_characters_re = re.compile(
Expand Down
6 changes: 6 additions & 0 deletions tests/models/gpt_sw3/test_tokenization_gpt_sw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def test_full_tokenizer(self):
)
# fmt: on

def test_preprocess_text_normalizes_unicode_whitespace(self):
tokenizer = GPTSw3Tokenizer(SAMPLE_VOCAB, name_or_path="test")

for whitespace in ["\u2002", "\u2003", "\u2005", "\u2008", "\u2009", "\u200a", "\u202f", "\u3000"]:
self.assertEqual(tokenizer.preprocess_text(f"en{whitespace}text"), "en text")

def test_fast_encode_decode(self):
tokenizer = GPTSw3Tokenizer(SAMPLE_VOCAB, name_or_path="test")
texts = ["This is a test", "I was born in 92000, and this is falsé."]
Expand Down
Loading