
"""simple docstring"""




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


A__      :	Tuple          =    logging.get_logger(__name__)

A__      :	List[Any]          =    {
    """facebook/xglm-564M""": """https://huggingface.co/facebook/xglm-564M/resolve/main/config.json""",
    # See all XGLM models at https://huggingface.co/models?filter=xglm
}







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'xglm'
     _A								=							['past_key_values']

     _A								=							{
         'num_attention_heads': 'attention_heads',
         'hidden_size': 'd_model',
         'num_hidden_layers': 'num_layers',
     }



     def __init__(      self ,			__UpperCamelCase=25_60_08 ,			__UpperCamelCase=20_48 ,			__UpperCamelCase=10_24 ,			__UpperCamelCase=40_96 ,			__UpperCamelCase=24 ,			__UpperCamelCase=16 ,			__UpperCamelCase="gelu" ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=0.0 ,			__UpperCamelCase=0.0 ,			__UpperCamelCase=0.02 ,			__UpperCamelCase=True ,			__UpperCamelCase=True ,			__UpperCamelCase=2 ,			__UpperCamelCase=1 ,			__UpperCamelCase=0 ,			__UpperCamelCase=2 ,			**__UpperCamelCase ,			)->					Union[str, Any]:
          UpperCAmelCase__							: Union[str, Any] 							=						vocab_size
          UpperCAmelCase__							: str 							=						max_position_embeddings
          UpperCAmelCase__							: Optional[int] 							=						d_model
          UpperCAmelCase__							: List[str] 							=						ffn_dim
          UpperCAmelCase__							: Union[str, Any] 							=						num_layers
          UpperCAmelCase__							: Union[str, Any] 							=						attention_heads
          UpperCAmelCase__							: Optional[int] 							=						activation_function
          UpperCAmelCase__							: List[Any] 							=						dropout
          UpperCAmelCase__							: List[str] 							=						attention_dropout
          UpperCAmelCase__							: str 							=						activation_dropout
          UpperCAmelCase__							: str 							=						layerdrop
          UpperCAmelCase__							: List[Any] 							=						init_std
          UpperCAmelCase__							: List[str] 							=						scale_embedding  # scale factor will be sqrt(d_model) if True
          UpperCAmelCase__							: Tuple 							=						use_cache

          super().__init__(
              pad_token_id=__UpperCamelCase ,			bos_token_id=__UpperCamelCase ,			eos_token_id=__UpperCamelCase ,			decoder_start_token_id=__UpperCamelCase ,			**__UpperCamelCase ,			)





"""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 							a__ (				lowerCAmelCase	:       str       ,    lowerCAmelCase	:       Optional[Any]       ,    lowerCAmelCase	:       Dict       ,    lowerCAmelCase	:       List[Any]		):






     '''simple docstring'''
     if isinstance(lowerCAmelCase       ,    lowerCAmelCase		):
          UpperCAmelCase__							: Optional[int] 							=						np.full((len(lowerCAmelCase		), sequence_length, 2)       ,    lowerCAmelCase		)
     else:
          UpperCAmelCase__							: Optional[Any] 							=						np.full((len(lowerCAmelCase		), sequence_length)       ,    lowerCAmelCase		)

     for i, tensor in enumerate(lowerCAmelCase		):
          if padding_side == "right":
               if isinstance(lowerCAmelCase       ,    lowerCAmelCase		):
                    UpperCAmelCase__							: Dict 							=						tensor[:sequence_length]
               else:
                    UpperCAmelCase__							: Tuple 							=						tensor[:sequence_length]
          else:
               if isinstance(lowerCAmelCase       ,    lowerCAmelCase		):
                    UpperCAmelCase__							: Optional[Any] 							=						tensor[:sequence_length]
               else:
                    UpperCAmelCase__							: int 							=						tensor[:sequence_length]

     return out_tensor.tolist()



def 							a__ (				lowerCAmelCase	:       Optional[int]		):






     '''simple docstring'''
     UpperCAmelCase__							: Tuple 							=						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
     UpperCAmelCase__							: Optional[Any] 							=						unicodedata.category(lowerCAmelCase		)
     if cat.startswith("P"		):
          return True
     return False







@dataclass
class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							42
     _A								=							True
     _A								=							None
     _A								=							None
     _A								=							-100
     _A								=							"pt"



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					List[str]:
          import torch

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

          UpperCAmelCase__							: Optional[Any] 							=						[feature["ner_tags"] for feature in features]
          UpperCAmelCase__							: int 							=						padding_tensor(__UpperCamelCase ,			-1 ,			__UpperCamelCase ,			__UpperCamelCase  )
          UpperCAmelCase__							: List[Any] 							=						[feature["original_entity_spans"] for feature in features]
          UpperCAmelCase__							: int 							=						padding_tensor(__UpperCamelCase ,			(-1, -1) ,			__UpperCamelCase ,			__UpperCamelCase  )
          UpperCAmelCase__							: Optional[int] 							=						{k: torch.tensor(__UpperCamelCase ,			dtype=torch.intaa  ) for k, v in batch.items()}

          return batch



