tokenization_distilbert.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2018 The HuggingFace Inc. team.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Tokenization classes for DistilBERT."""
  15. from ...models.bert.tokenization_bert import BertTokenizer
  16. VOCAB_FILES_NAMES = {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}
  17. class DistilBertTokenizer(BertTokenizer):
  18. model_input_names = ["input_ids", "attention_mask"]
  19. def __init__(self, *args, do_lower_case: bool = True, **kwargs):
  20. """
  21. Construct a DistilBERT tokenizer (backed by HuggingFace's tokenizers library). Based on WordPiece.
  22. This tokenizer inherits from [`BertTokenizer`] which contains most of the main methods. Users should refer to
  23. this superclass for more information regarding those methods.
  24. Args:
  25. do_lower_case (`bool`, *optional*, defaults to `True`):
  26. Whether or not to lowercase the input when tokenizing.
  27. """
  28. super().__init__(*args, do_lower_case=do_lower_case, **kwargs)
  29. # DistilBertTokenizerFast is an alias for DistilBertTokenizer (since BertTokenizer is already a fast tokenizer)
  30. DistilBertTokenizerFast = DistilBertTokenizer
  31. __all__ = ["DistilBertTokenizer", "DistilBertTokenizerFast"]