Skip to content
Merged
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
13 changes: 5 additions & 8 deletions src/transformers/tokenization_utils_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def flatten(arr: list):
return res


if is_tokenizers_available() or TYPE_CHECKING:
from tokenizers import Encoding as EncodingFast

if is_tokenizers_available():
from tokenizers import AddedToken
from tokenizers import Encoding as EncodingFast
else:

@dataclass(frozen=False, eq=True)
Expand Down Expand Up @@ -129,12 +131,6 @@ def __getstate__(self):
def __str__(self):
return self.content

@dataclass
class EncodingFast:
"""This is dummy class because without the `tokenizers` library we don't have these objects anyway"""

pass


logger = logging.get_logger(__name__)

Expand Down Expand Up @@ -238,7 +234,8 @@ def __init__(
):
super().__init__(data)

if isinstance(encoding, EncodingFast):
# If encoding is not None, the fast tokenization is used
if encoding is not None and isinstance(encoding, EncodingFast):
encoding = [encoding]

self._encodings = encoding
Expand Down