


'''simple docstring'''





from ...configuration_utils import PretrainedConfig
from ...utils import logging


__UpperCamelCase       :       int						       =				logging.get_logger(__name__)

__UpperCamelCase       :       Any						       =				{
    "funnel-transformer/small": "https://huggingface.co/funnel-transformer/small/resolve/main/config.json",
    "funnel-transformer/small-base": "https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json",
    "funnel-transformer/medium": "https://huggingface.co/funnel-transformer/medium/resolve/main/config.json",
    "funnel-transformer/medium-base": "https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json",
    "funnel-transformer/intermediate": (
        "https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json"
    ),
    "funnel-transformer/intermediate-base": (
        "https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json"
    ),
    "funnel-transformer/large": "https://huggingface.co/funnel-transformer/large/resolve/main/config.json",
    "funnel-transformer/large-base": "https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json",
    "funnel-transformer/xlarge": "https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json",
    "funnel-transformer/xlarge-base": "https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json",
}

class       __magic_name__	(     __lowerCAmelCase):
     A:		List[Any]			=      "funnel"
     A:		str			=      {
         "hidden_size": "d_model",
         "num_attention_heads": "n_head",
     }


     def __init__(      self							:     Optional[int]							,	lowerCamelCase__							:     Optional[int]=30522							,	lowerCamelCase__							:     List[Any]=[4, 4, 4]							,	lowerCamelCase__							:     Tuple=None							,	lowerCamelCase__							:     Union[str, Any]=2							,	lowerCamelCase__							:     Dict=768							,	lowerCamelCase__							:     List[str]=12							,	lowerCamelCase__							:     Tuple=64							,	lowerCamelCase__							:     Optional[Any]=3072							,	lowerCamelCase__							:     Optional[int]="gelu_new"							,	lowerCamelCase__							:     Optional[Any]=0.1							,	lowerCamelCase__							:     Union[str, Any]=0.1							,	lowerCamelCase__							:     Union[str, Any]=0.0							,	lowerCamelCase__							:     Optional[int]=0.1							,	lowerCamelCase__							:     List[Any]=None							,	lowerCamelCase__							:     List[Any]=1E-9							,	lowerCamelCase__							:     Optional[int]="mean"							,	lowerCamelCase__							:     List[str]="relative_shift"							,	lowerCamelCase__							:     Tuple=True							,	lowerCamelCase__							:     str=True							,	lowerCamelCase__							:     Dict=True							,	**lowerCamelCase__							:     Dict							,	)  ->      int:





      '''simple docstring'''






      UpperCamelCase__					:    Optional[Any]          =   vocab_size
      UpperCamelCase__					:    int          =   block_sizes
      UpperCamelCase__					:    Tuple          =   [1] * len(lowerCamelCase__			) if block_repeats is None else block_repeats
      assert len(lowerCamelCase__			) == len(
          self.block_repeats			), "`block_sizes` and `block_repeats` should have the same length."
      UpperCamelCase__					:    str          =   num_decoder_layers
      UpperCamelCase__					:    Any          =   d_model
      UpperCamelCase__					:    Union[str, Any]          =   n_head
      UpperCamelCase__					:    Dict          =   d_head
      UpperCamelCase__					:    int          =   d_inner
      UpperCamelCase__					:    Union[str, Any]          =   hidden_act
      UpperCamelCase__					:    Any          =   hidden_dropout
      UpperCamelCase__					:    Any          =   attention_dropout
      UpperCamelCase__					:    str          =   activation_dropout
      UpperCamelCase__					:    int          =   initializer_range
      UpperCamelCase__					:    Optional[Any]          =   initializer_std
      UpperCamelCase__					:    Union[str, Any]          =   layer_norm_eps
      assert pooling_type in [
          "mean",
          "max",
      ], F"Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."
      UpperCamelCase__					:    Tuple          =   pooling_type
      assert attention_type in [
          "relative_shift",
          "factorized",
      ], F"Got {attention_type} for `attention_type` but only 'relative_shift' and 'factorized' are supported."
      UpperCamelCase__					:    Union[str, Any]          =   attention_type
      UpperCamelCase__					:    List[str]          =   separate_cls
      UpperCamelCase__					:    Any          =   truncate_seq
      UpperCamelCase__					:    int          =   pool_q_only

      super().__init__(**lowerCamelCase__			)


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





      '''simple docstring'''






      return sum(self.block_sizes			)


     @num_hidden_layers.setter
     def      UpperCAmelCase__	(      self							:     Union[str, Any]							,	lowerCamelCase__							:     Union[str, Any]			)  ->      Optional[Any]:





      '''simple docstring'''






      raise NotImplementedError(
          '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.'''			)


     @property
     def      UpperCAmelCase__	(      self							:     Union[str, Any]			)  ->      Union[str, Any]:





      '''simple docstring'''






      return len(self.block_sizes			)


     @num_blocks.setter
     def      UpperCAmelCase__	(      self							:     Tuple							,	lowerCamelCase__							:     List[Any]			)  ->      Optional[int]:





      '''simple docstring'''






      raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.'''			)






import unicodedata
from dataclasses import dataclass
from typing import Optional, Union

import numpy as np

from transformers.data.data_collator import DataCollatorMixin
from transformers.file_utils import PaddingStrategy
from transformers.tokenization_utils_base import PreTrainedTokenizerBase

def 			_a  (				SCREAMING_SNAKE_CASE	:				Optional[Any]    , SCREAMING_SNAKE_CASE	:				Any    , SCREAMING_SNAKE_CASE	:				List[str]    , SCREAMING_SNAKE_CASE	:				int     ):







 """simple docstring"""



 if isinstance(SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE     ):
  UpperCamelCase__					:    Dict          =   np.full((len(SCREAMING_SNAKE_CASE     ), sequence_length, 2)    , SCREAMING_SNAKE_CASE     )
 else:
  UpperCamelCase__					:    Dict          =   np.full((len(SCREAMING_SNAKE_CASE     ), sequence_length)    , SCREAMING_SNAKE_CASE     )

 for i, tensor in enumerate(SCREAMING_SNAKE_CASE     ):
  if padding_side == "right":
   if isinstance(SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE     ):
    UpperCamelCase__					:    str          =   tensor[:sequence_length]
   else:
    UpperCamelCase__					:    Union[str, Any]          =   tensor[:sequence_length]
  else:
   if isinstance(SCREAMING_SNAKE_CASE    , SCREAMING_SNAKE_CASE     ):
    UpperCamelCase__					:    str          =   tensor[:sequence_length]
   else:
    UpperCamelCase__					:    str          =   tensor[:sequence_length]

 return out_tensor.tolist()

def 			_a  (				SCREAMING_SNAKE_CASE	:				List[Any]     ):







 """simple docstring"""



 UpperCamelCase__					:    Union[str, Any]          =   ord(SCREAMING_SNAKE_CASE     )
 if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126):
  return True
 UpperCamelCase__					:    Any          =   unicodedata.category(SCREAMING_SNAKE_CASE     )
 if cat.startswith('''P'''     ):
  return True
 return False






@dataclass
class       __magic_name__	(     __lowerCAmelCase):
     A:		PreTrainedTokenizerBase
     A:		Union[bool, str, PaddingStrategy]			=      True
     A:		Optional[int]			=      None
     A:		Optional[int]			=      None
     A:		int			=      -1_0_0
     A:		str			=      "pt"


     def      UpperCAmelCase__	(      self							:     int							,	lowerCamelCase__							:     List[Any]			)  ->      Any:





      '''simple docstring'''






      import torch

      UpperCamelCase__					:    Tuple          =   '''label''' if '''label''' in features[0].keys() else '''labels'''
      UpperCamelCase__					:    Optional[Any]          =   [feature[label_name] for feature in features] if label_name in features[0].keys() else None
      UpperCamelCase__					:    Optional[int]          =   self.tokenizer.pad(
          lowerCamelCase__							,	padding=self.padding							,	max_length=self.max_length							,	pad_to_multiple_of=self.pad_to_multiple_of							,	return_tensors='''pt''' if labels is None else None							,	)

      if labels is None:
       return batch

      UpperCamelCase__					:    Dict          =   torch.tensor(batch['''entity_ids''']			).shape[1]
      UpperCamelCase__					:    Union[str, Any]          =   self.tokenizer.padding_side
      if padding_side == "right":
       UpperCamelCase__					:    Optional[int]          =   [
           list(lowerCamelCase__			) + [self.label_pad_token_id] * (sequence_length - len(lowerCamelCase__			)) for label in labels
       ]
      else:
       UpperCamelCase__					:    int          =   [
           [self.label_pad_token_id] * (sequence_length - len(lowerCamelCase__			)) + list(lowerCamelCase__			) for label in labels
       ]

      UpperCamelCase__					:    Union[str, Any]          =   [feature['''ner_tags'''] for feature in features]
      UpperCamelCase__					:    List[str]          =   padding_tensor(lowerCamelCase__							,	-1							,	lowerCamelCase__							,	lowerCamelCase__			)
      UpperCamelCase__					:    Union[str, Any]          =   [feature['''original_entity_spans'''] for feature in features]
      UpperCamelCase__					:    Any          =   padding_tensor(lowerCamelCase__							,	(-1, -1)							,	lowerCamelCase__							,	lowerCamelCase__			)
      UpperCamelCase__					:    str          =   {k: torch.tensor(lowerCamelCase__							,	dtype=torch.intaa			) for k, v in batch.items()}

      return batch


