processing_bros.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # coding=utf-8
  2. # Copyright 2023 The HuggingFace Inc. team.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """
  16. Processor class for Bros.
  17. """
  18. from ...processing_utils import ProcessingKwargs, ProcessorMixin
  19. class BrosProcessorKwargs(ProcessingKwargs, total=False):
  20. _defaults = {
  21. "text_kwargs": {
  22. "add_special_tokens": True,
  23. "padding": False,
  24. "stride": 0,
  25. "return_overflowing_tokens": False,
  26. "return_special_tokens_mask": False,
  27. "return_offsets_mapping": False,
  28. "return_length": False,
  29. "verbose": True,
  30. },
  31. }
  32. class BrosProcessor(ProcessorMixin):
  33. r"""
  34. Constructs a Bros processor which wraps a BERT tokenizer.
  35. [`BrosProcessor`] offers all the functionalities of [`BertTokenizerFast`]. See the docstring of
  36. [`~BrosProcessor.__call__`] and [`~BrosProcessor.decode`] for more information.
  37. Args:
  38. tokenizer (`BertTokenizerFast`, *optional*):
  39. An instance of ['BertTokenizerFast`]. The tokenizer is a required input.
  40. """
  41. attributes = ["tokenizer"]
  42. tokenizer_class = ("BertTokenizer", "BertTokenizerFast")
  43. valid_processor_kwargs = BrosProcessorKwargs
  44. def __init__(self, tokenizer=None, **kwargs):
  45. if tokenizer is None:
  46. raise ValueError("You need to specify a `tokenizer`.")
  47. super().__init__(tokenizer)
  48. __all__ = ["BrosProcessor"]