




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__     (   lowerCamelCase,	lowerCamelCase,	lowerCamelCase,	lowerCamelCase      ):
  if isinstance(lowerCamelCase,	lowerCamelCase      ):
    lowercase			:str							=  np.full((len(lowerCamelCase      ), sequence_length, 2),	lowerCamelCase      )
  else:
    lowercase			:Union[str, Any]							=  np.full((len(lowerCamelCase      ), sequence_length),	lowerCamelCase      )

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

  return out_tensor.tolist()



def 					UpperCAmelCase__     (   lowerCamelCase      ):
  lowercase			:str							=  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			:List[str]							=  unicodedata.category(lowerCamelCase      )
  if cat.startswith("P"      ):
    return True
  return False







@dataclass
class       __lowerCAmelCase				(							lowerCAmelCase):
       _a           =  42
       _a           =  True
       _a           =  None
       _a           =  None
       _a           =  -100
       _a           =  "pt"






       def     SCREAMING_SNAKE_CASE			(      self:    Union[str, Any]				,    _lowerCAmelCase:    Union[str, Any] ):
         import torch

         lowercase			:str							=  "label" if "label" in features[0].keys() else "labels"
         lowercase			:List[str]							=  [feature[label_name] for feature in features] if label_name in features[0].keys() else None
         lowercase			:Tuple							=  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			:Tuple							=  torch.tensor(batch["entity_ids"] ).shape[1]
         lowercase			:Optional[Any]							=  self.tokenizer.padding_side
         if padding_side == "right":
           lowercase			:Optional[int]							=  [
               list(_lowerCAmelCase ) + [self.label_pad_token_id] * (sequence_length - len(_lowerCAmelCase )) for label in labels
           ]
         else:
           lowercase			:Dict							=  [
               [self.label_pad_token_id] * (sequence_length - len(_lowerCAmelCase )) + list(_lowerCAmelCase ) for label in labels
           ]

         lowercase			:Tuple							=  [feature["ner_tags"] for feature in features]
         lowercase			:Union[str, Any]							=  padding_tensor(_lowerCAmelCase				,    -1				,    _lowerCAmelCase				,    _lowerCAmelCase )
         lowercase			:Optional[Any]							=  [feature["original_entity_spans"] for feature in features]
         lowercase			:Tuple							=  padding_tensor(_lowerCAmelCase				,    (-1, -1)				,    _lowerCAmelCase				,    _lowerCAmelCase )
         lowercase			:Dict							=  {k: torch.tensor(_lowerCAmelCase				,    dtype=torch.intaa ) for k, v in batch.items()}

         return batch









from __future__ import annotations

from typing import Dict

from ...configuration_utils import PretrainedConfig


_UpperCAmelCase		:  Tuple	=   {
    "susnato/ernie-m-base_pytorch": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/config.json",
    "susnato/ernie-m-large_pytorch": "https://huggingface.co/susnato/ernie-m-large_pytorch/blob/main/config.json",
}




class       __lowerCAmelCase				(							lowerCAmelCase):
       _a           =  '''ernie_m'''
       _a           =  {"dropout": "classifier_dropout", "num_classes": "num_labels"}






       def __init__(      self:    List[Any]				,    _lowerCAmelCase:    int = 25_00_02				,    _lowerCAmelCase:    int = 7_68				,    _lowerCAmelCase:    int = 12				,    _lowerCAmelCase:    int = 12				,    _lowerCAmelCase:    int = 30_72				,    _lowerCAmelCase:    str = "gelu"				,    _lowerCAmelCase:    float = 0.1				,    _lowerCAmelCase:    float = 0.1				,    _lowerCAmelCase:    int = 5_14				,    _lowerCAmelCase:    float = 0.02				,    _lowerCAmelCase:    int = 1				,    _lowerCAmelCase:    float = 1e-0_5				,    _lowerCAmelCase:    Dict=None				,    _lowerCAmelCase:    Optional[int]=False				,    _lowerCAmelCase:    List[str]=0.0				,    **_lowerCAmelCase:    Tuple				,    ):
         super().__init__(pad_token_id=_lowerCAmelCase				,    **_lowerCAmelCase )
         lowercase			:Tuple							=  vocab_size
         lowercase			:List[str]							=  hidden_size
         lowercase			:Optional[int]							=  num_hidden_layers
         lowercase			:Optional[Any]							=  num_attention_heads
         lowercase			:Optional[Any]							=  intermediate_size
         lowercase			:Optional[Any]							=  hidden_act
         lowercase			:Any							=  hidden_dropout_prob
         lowercase			:int							=  attention_probs_dropout_prob
         lowercase			:Dict							=  max_position_embeddings
         lowercase			:Optional[Any]							=  initializer_range
         lowercase			:Any							=  layer_norm_eps
         lowercase			:Union[str, Any]							=  classifier_dropout
         lowercase			:int							=  is_decoder
         lowercase			:List[str]							=  act_dropout



