





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a_    :				Optional[int]					=			{
    'configuration_big_bird': ['BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP', 'BigBirdConfig', 'BigBirdOnnxConfig'],
}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a_    :				List[str]					=			['BigBirdTokenizer']

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a_    :				Optional[int]					=			['BigBirdTokenizerFast']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a_    :				Optional[Any]					=			[
        'BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST',
        'BigBirdForCausalLM',
        'BigBirdForMaskedLM',
        'BigBirdForMultipleChoice',
        'BigBirdForPreTraining',
        'BigBirdForQuestionAnswering',
        'BigBirdForSequenceClassification',
        'BigBirdForTokenClassification',
        'BigBirdLayer',
        'BigBirdModel',
        'BigBirdPreTrainedModel',
        'load_tf_weights_in_big_bird',
    ]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    a_    :				str					=			[
        'FlaxBigBirdForCausalLM',
        'FlaxBigBirdForMaskedLM',
        'FlaxBigBirdForMultipleChoice',
        'FlaxBigBirdForPreTraining',
        'FlaxBigBirdForQuestionAnswering',
        'FlaxBigBirdForSequenceClassification',
        'FlaxBigBirdForTokenClassification',
        'FlaxBigBirdModel',
        'FlaxBigBirdPreTrainedModel',
    ]

if TYPE_CHECKING:
    from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_big_bird import BigBirdTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_big_bird_fast import BigBirdTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_big_bird import (
            BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST,
            BigBirdForCausalLM,
            BigBirdForMaskedLM,
            BigBirdForMultipleChoice,
            BigBirdForPreTraining,
            BigBirdForQuestionAnswering,
            BigBirdForSequenceClassification,
            BigBirdForTokenClassification,
            BigBirdLayer,
            BigBirdModel,
            BigBirdPreTrainedModel,
            load_tf_weights_in_big_bird,
        )

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_big_bird import (
            FlaxBigBirdForCausalLM,
            FlaxBigBirdForMaskedLM,
            FlaxBigBirdForMultipleChoice,
            FlaxBigBirdForPreTraining,
            FlaxBigBirdForQuestionAnswering,
            FlaxBigBirdForSequenceClassification,
            FlaxBigBirdForTokenClassification,
            FlaxBigBirdModel,
            FlaxBigBirdPreTrainedModel,
        )

else:
    import sys

    a_    :				int					=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
"""simple docstring"""
from typing import Dict, List, Optional, Tuple

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


lowercase__   			=      logging.get_logger(__name__)




class   __snake_case			(	__lowerCAmelCase							):
      a__								=						["""input_ids""", """attention_mask"""]



      def __init__(		self       ,     lowercase="[PAD]"       ,     lowercase="[BOS]"       ,     lowercase="[EOS]"       ,     lowercase="[MASK]"       ,     lowercase="[CLS]"       ,     lowercase="[SEP]"       ,     lowercase=20_48       ,     **lowercase       ,     )      ->     None:





        '''simple docstring'''





        a__:	Any     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else pad_token
        a__:	Tuple     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else bos_token
        a__:	Union[str, Any]     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else eos_token
        a__:	Tuple     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else mask_token
        a__:	int     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else cls_token
        a__:	Any     				=      AddedToken(lowercase       ,     lstrip=lowercase       ,     rstrip=lowercase) if isinstance(lowercase       ,     lowercase) else sep_token

        super().__init__(
            pad_token=lowercase       ,     bos_token=lowercase       ,     eos_token=lowercase       ,     mask_token=lowercase       ,     cls_token=lowercase       ,     sep_token=lowercase       ,     model_max_length=lowercase       ,     **lowercase       ,     )

        a__:	Optional[Any]     				=      2**8  # utf is 8 bits

        # define special tokens dict
        a__:	Dict[str, int]     				=      {
            self.pad_token: 0,
            self.bos_token: 1,
            self.eos_token: 2,
            self.mask_token: 3,
            self.cls_token: 4,
            self.sep_token: 5,
        }
        a__:	Union[str, Any]     				=      len(self.special_tokens_encoder)
        a__:	Dict[int, str]     				=      {v: k for k, v in self.special_tokens_encoder.items()}



      def     lowerCamelCase_  (		self)      ->     Dict[str, int]:





        '''simple docstring'''





        a__:	Optional[int]     				=      self.special_tokens_encoder.copy()
        vocab.update(self.added_tokens_encoder)
        for i in range(self._utf_vocab_size):
          a__:	Optional[int]     				=      chr(lowercase)
          a__:	str     				=      i + len(self.special_tokens_encoder)
        return vocab



      @property
      def     lowerCamelCase_  (		self)      ->     List[Any]:





        '''simple docstring'''





        return self._utf_vocab_size + self._num_special_tokens



      def     lowerCamelCase_  (		self       ,     lowercase       ,     lowercase = None       ,     lowercase = False)      ->     List[int]:





        '''simple docstring'''





        if already_has_special_tokens:
          return super().get_special_tokens_mask(
              token_ids_a=lowercase       ,     token_ids_a=lowercase       ,     already_has_special_tokens=lowercase)

        # normal case: some special tokens
        if token_ids_a is None:
          return [1] + [0] * len(lowercase) + [1]
        return [1] + ([0] * len(lowercase)) + [1] + ([0] * len(lowercase)) + [1]



      def     lowerCamelCase_  (		self       ,     lowercase       ,     lowercase = None)      ->     List[int]:





        '''simple docstring'''





        if token_ids_a is None:
          return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
        else:
          return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     List[str]:





        '''simple docstring'''





        a__:	Any     				=      [chr(lowercase) for i in text.encode('utf-8')]
        return tokens



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     Union[str, Any]:





        '''simple docstring'''





        if token in self.special_tokens_encoder:
          a__:	Optional[int]     				=      self.special_tokens_encoder[token]
        elif token in self.added_tokens_encoder:
          a__:	Optional[int]     				=      self.added_tokens_encoder[token]
        elif len(lowercase) != 1:
          a__:	Dict     				=      self.unk_token_id
        else:
          a__:	Optional[Any]     				=      ord(lowercase) + self._num_special_tokens
        return token_id



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     Tuple:





        '''simple docstring'''





        if index in self.special_tokens_decoder:
          a__:	List[Any]     				=      self.special_tokens_decoder[index]
        elif index in self.added_tokens_decoder:
          a__:	Tuple     				=      self.added_tokens_decoder[index]
        else:
          a__:	List[str]     				=      chr(index - self._num_special_tokens)
        return token



      def     lowerCamelCase_  (		self       ,     lowercase)      ->     Optional[int]:





        '''simple docstring'''





        a__:	Any     				=      B''
        for token in tokens:
          if token in self.special_tokens_decoder:
            a__:	str     				=      self.special_tokens_decoder[token].encode('utf-8')
          elif token in self.added_tokens_decoder:
            a__:	Optional[Any]     				=      self.special_tokens_decoder[token].encode('utf-8')
          elif token in self.special_tokens_encoder:
            a__:	Optional[Any]     				=      token.encode('utf-8')
          elif token in self.added_tokens_encoder:
            a__:	str     				=      token.encode('utf-8')
          else:
            a__:	Tuple     				=      bytes([ord(lowercase)])
          bstring += tok_string
        a__:	List[str]     				=      bstring.decode('utf-8'       ,     errors='replace')
        return string



      def     lowerCamelCase_  (		self       ,     lowercase       ,     lowercase = None)      ->     Tuple[str]:





        '''simple docstring'''





        return ()


