





"""simple docstring"""




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       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       Tuple:
  if isinstance(lowerCamelCase__		,						lowerCamelCase__		):
    lowercase__           =  np.full((len(lowerCamelCase__		), sequence_length, 2)		,						lowerCamelCase__		)
  else:
    lowercase__           =  np.full((len(lowerCamelCase__		), sequence_length)		,						lowerCamelCase__		)

  for i, tensor in enumerate(lowerCamelCase__		):
    if padding_side == "right":
      if isinstance(lowerCamelCase__		,						lowerCamelCase__		):
        lowercase__           =  tensor[:sequence_length]
      else:
        lowercase__           =  tensor[:sequence_length]
    else:
      if isinstance(lowerCamelCase__		,						lowerCamelCase__		):
        lowercase__           =  tensor[:sequence_length]
      else:
        lowercase__           =  tensor[:sequence_length]

  return out_tensor.tolist()




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       Any:
  lowercase__           =  ord(lowerCamelCase__		)
  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
  lowercase__           =  unicodedata.category(lowerCamelCase__		)
  if cat.startswith('P'		):
    return True
  return False


@dataclass
class     SCREAMING_SNAKE_CASE       (a__				):
   _UpperCamelCase   :		Optional[int]			 =	42
   _UpperCamelCase   :		Optional[Any]			 =	True
   _UpperCamelCase   :		str			 =	None
   _UpperCamelCase   :		int			 =	None
   _UpperCamelCase   :		Tuple			 =	-1_00
   _UpperCamelCase   :		Dict			 =	'pt'


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    List[Any]	)->       Tuple:





     """simple docstring"""







     import torch

     lowercase__           =  '''label''' if '''label''' in features[0].keys() else '''labels'''
     lowercase__           =  [feature[label_name] for feature in features] if label_name in features[0].keys() else None
     lowercase__           =  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

     lowercase__           =  torch.tensor(batch['entity_ids']	).shape[1]
     lowercase__           =  self.tokenizer.padding_side
     if padding_side == "right":
       lowercase__           =  [
           list(_lowerCamelCase	) + [self.label_pad_token_id] * (sequence_length - len(_lowerCamelCase	)) for label in labels
       ]
     else:
       lowercase__           =  [
           [self.label_pad_token_id] * (sequence_length - len(_lowerCamelCase	)) + list(_lowerCamelCase	) for label in labels
       ]

     lowercase__           =  [feature['''ner_tags'''] for feature in features]
     lowercase__           =  padding_tensor(_lowerCamelCase      ,					-1      ,					_lowerCamelCase      ,					_lowerCamelCase	)
     lowercase__           =  [feature['''original_entity_spans'''] for feature in features]
     lowercase__           =  padding_tensor(_lowerCamelCase      ,					(-1, -1)      ,					_lowerCamelCase      ,					_lowerCamelCase	)
     lowercase__           =  {k: torch.tensor(_lowerCamelCase      ,					dtype=torch.intaa	) for k, v in batch.items()}

     return batch









import warnings

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


lowercase_          =		logging.get_logger(__name__)

lowercase_          =		{
    """xlnet-base-cased""": """https://huggingface.co/xlnet-base-cased/resolve/main/config.json""",
    """xlnet-large-cased""": """https://huggingface.co/xlnet-large-cased/resolve/main/config.json""",
}
class     SCREAMING_SNAKE_CASE       (UpperCAmelCase				):
   _UpperCamelCase   :		str			 =	'xlnet'
   _UpperCamelCase   :		Optional[Any]			 =	['mems']
   _UpperCamelCase   :		Union[str, Any]			 =	{
       'n_token': 'vocab_size',  # Backward compatibility
       'hidden_size': 'd_model',
       'num_attention_heads': 'n_head',
       'num_hidden_layers': 'n_layer',
   }


   def __init__(   self      :    str      ,					a      :    int=32_000      ,					a      :    Any=1_024      ,					a      :    Optional[Any]=24      ,					a      :    str=16      ,					a      :    int=4_096      ,					a      :    List[str]="gelu"      ,					a      :    Any=True      ,					a      :    Dict="bi"      ,					a      :    str=0.02      ,					a      :    List[str]=1E-1_2      ,					a      :    Tuple=0.1      ,					a      :    Optional[Any]=512      ,					a      :    Tuple=None      ,					a      :    Union[str, Any]=True      ,					a      :    int=False      ,					a      :    int=False      ,					a      :    Tuple=-1      ,					a      :    Any=False      ,					a      :    Tuple="last"      ,					a      :    List[str]=True      ,					a      :    Optional[Any]="tanh"      ,					a      :    List[Any]=0.1      ,					a      :    int=5      ,					a      :    List[Any]=5      ,					a      :    Optional[int]=5      ,					a      :    Dict=1      ,					a      :    Optional[Any]=2      ,					**a      :    List[Any]      ,					)->       List[str]:





     """simple docstring"""







     lowercase__           =  vocab_size
     lowercase__           =  d_model
     lowercase__           =  n_layer
     lowercase__           =  n_head
     if d_model % n_head != 0:
       raise ValueError(f"""'d_model % n_head' ({d_model % n_head}) should be equal to 0"""	)
     if "d_head" in kwargs:
       if kwargs["d_head"] != d_model // n_head:
         raise ValueError(
             f"""`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})"""	)
     lowercase__           =  d_model // n_head
     lowercase__           =  ff_activation
     lowercase__           =  d_inner
     lowercase__           =  untie_r
     lowercase__           =  attn_type

     lowercase__           =  initializer_range
     lowercase__           =  layer_norm_eps

     lowercase__           =  dropout
     lowercase__           =  mem_len
     lowercase__           =  reuse_len
     lowercase__           =  bi_data
     lowercase__           =  clamp_len
     lowercase__           =  same_length

     lowercase__           =  summary_type
     lowercase__           =  summary_use_proj
     lowercase__           =  summary_activation
     lowercase__           =  summary_last_dropout
     lowercase__           =  start_n_top
     lowercase__           =  end_n_top

     lowercase__           =  bos_token_id
     lowercase__           =  pad_token_id
     lowercase__           =  eos_token_id

     if "use_cache" in kwargs:
       warnings.warn(
           'The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`'
           ' instead.'      ,					a      ,					)
       lowercase__           =  kwargs['use_cache']

     lowercase__           =  use_mems_eval
     lowercase__           =  use_mems_train
     super().__init__(pad_token_id=a      ,					bos_token_id=a      ,					eos_token_id=a      ,					**a	)


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





     """simple docstring"""







     logger.info(f"""The model {self.model_type} is one of the few models that has no sequence length limit."""	)
     return -1


   @max_position_embeddings.setter
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    Union[str, Any]	)->       List[Any]:





     """simple docstring"""







     raise NotImplementedError(
         f"""The model {self.model_type} is one of the few models that has no sequence length limit."""	)


