Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fast tokenization problems #13930

Merged
merged 5 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion src/transformers/models/albert/tokenization_albert.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ def __init__(
**kwargs
) -> None:
# Mask token behave like a normal word, i.e. include the space before it
qqaatw marked this conversation as resolved.
Show resolved Hide resolved
mask_token = AddedToken(mask_token, lstrip=True, rstrip=False) if isinstance(mask_token, str) else mask_token
mask_token = (
AddedToken(mask_token, lstrip=True, rstrip=False, normalized=False)
if isinstance(mask_token, str)
else mask_token
)

self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs

Expand Down
3 changes: 0 additions & 3 deletions src/transformers/models/albert/tokenization_albert_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from typing import List, Optional, Tuple

from ...file_utils import is_sentencepiece_available
from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging

Expand Down Expand Up @@ -135,8 +134,6 @@ def __init__(
mask_token="[MASK]",
**kwargs
):
qqaatw marked this conversation as resolved.
Show resolved Hide resolved
# Mask token behave like a normal word, i.e. include the space before it
mask_token = AddedToken(mask_token, lstrip=True, rstrip=False) if isinstance(mask_token, str) else mask_token

super().__init__(
vocab_file,
Expand Down
4 changes: 4 additions & 0 deletions src/transformers/tokenization_utils_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def __init__(self, *args, **kwargs):
# We call this after having initialized the backend tokenizer because we update it.
super().__init__(**kwargs)

# Ensure special tokens directly specified from kwargs (not from pretrained) are sanitized.
if "name_or_path" not in kwargs:
self.sanitize_special_tokens()

@property
def is_fast(self) -> bool:
return True
Expand Down