"""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 	_lowerCamelCase			(			UpperCAmelCase__,UpperCAmelCase__,UpperCAmelCase__,UpperCAmelCase__       )				->  List[Any]:


   '''simple docstring'''


   if isinstance(UpperCamelCase_,UpperCamelCase_       ):
      a__  					=		np.full((len(UpperCamelCase_       ), sequence_length, 2),UpperCamelCase_       )
   else:
      a__  					=		np.full((len(UpperCamelCase_       ), sequence_length),UpperCamelCase_       )

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

   return out_tensor.tolist()





def 	_lowerCamelCase			(			UpperCAmelCase__       )				->  Optional[Any]:


   '''simple docstring'''


   a__  					=		ord(UpperCamelCase_       )
   if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 1_23 and cp <= 1_26):
      return True
   a__  					=		unicodedata.category(UpperCamelCase_       )
   if cat.startswith('P'       ):
      return True
   return False




@dataclass
class SCREAMING_SNAKE_CASE  (     snake_case__						):







 """simple docstring"""


 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 							_lowerCAmelCase					( self		:   Union[str, Any]       , _snake_case		:   Tuple					)					->      Optional[Any]:




    '''simple docstring'''






    import torch

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

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

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

    return batch







'''simple docstring'''

from timeit import timeit






def 				a  (     UpperCamelCase_    :    int			)       ->	int:
		if number < 0:
				raise ValueError('the value of input must not be negative'			)
		snake_case__	     =0
		while number:
				number &= number - 1
				result += 1
		return result






def 				a  (     UpperCamelCase_    :    int			)       ->	int:
		if number < 0:
				raise ValueError('the value of input must not be negative'			)
		snake_case__	     =0
		while number:
				if number % 2 == 1:
						result += 1
				number >>= 1
		return result






def 				a  (     )       ->	None:

		def do_benchmark(UpperCamelCase_    :    int			) -> None:
				snake_case__	     ='import __main__ as z'
				print(f"""Benchmark when {number = }:"""			)
				print(f"""{get_set_bits_count_using_modulo_operator(UpperCamelCase_			) = }"""			)
				snake_case__	     =timeit('z.get_set_bits_count_using_modulo_operator(25)'      ,					setup=UpperCamelCase_			)
				print(f"""timeit() runs in {timing} seconds"""			)
				print(f"""{get_set_bits_count_using_brian_kernighans_algorithm(UpperCamelCase_			) = }"""			)
				snake_case__	     =timeit(
				    'z.get_set_bits_count_using_brian_kernighans_algorithm(25)'      ,					setup=UpperCamelCase_      ,					)
				print(f"""timeit() runs in {timing} seconds"""			)

		for number in (25, 37, 58, 0):
				do_benchmark(UpperCamelCase_			)
				print()


if __name__ == "__main__":
			import doctest

			doctest.testmod()
			benchmark()




