

import argparse
import os
import re

import packaging.version


__A     :					str     = 'examples/'
__A     :					Optional[Any]     = {
    'examples': (re.compile(R'^check_min_version\(\"[^\"]+\"\)\s*$', re.MULTILINE), 'check_min_version(\"VERSION\")\n'),
    'init': (re.compile(R'^__version__\s+=\s+\"([^\"]+)\"\s*$', re.MULTILINE), '__version__ = \"VERSION\"\n'),
    'setup': (re.compile(R'^(\s*)version\s*=\s*\"[^\"]+\",', re.MULTILINE), R'\1version=\"VERSION\",'),
    'doc': (re.compile(R'^(\s*)release\s*=\s*\"[^\"]+\"$', re.MULTILINE), 'release = \"VERSION\"\n'),
}
__A     :					Union[str, Any]     = {
    'init': 'src/transformers/__init__.py',
    'setup': 'setup.py',
}
__A     :					List[str]     = 'README.md'




def     __UpperCamelCase			(	_A :				List[Any]	,   _A :				List[Any]	,   _A :				Dict						)							->Union[str, Any]:



							"""simple docstring"""



							with open(__A	,   """r"""	,   encoding="""utf-8"""	,   newline="""\n"""						) as f:
														lowerCamelCase_				     =f.read()
							lowerCamelCase_     ,					lowerCamelCase_				     =REPLACE_PATTERNS[pattern]
							lowerCamelCase_				     =replace.replace("""VERSION"""	,   __A						)
							lowerCamelCase_				     =re_pattern.sub(__A	,   __A						)
							with open(__A	,   """w"""	,   encoding="""utf-8"""	,   newline="""\n"""						) as f:
														f.write(__A						)




def     __UpperCamelCase			(	_A :				Union[str, Any]						)							->int:



							"""simple docstring"""



							for folder, directories, fnames in os.walk(__A						):
														# Removing some of the folders with non-actively maintained examples from the walk
														if "research_projects" in directories:
																					directories.remove("""research_projects"""						)
														if "legacy" in directories:
																					directories.remove("""legacy"""						)
														for fname in fnames:
																					if fname.endswith(""".py"""						):
																												update_version_in_file(os.path.join(__A	,   __A						)	,   __A	,   pattern="""examples"""						)




def     __UpperCamelCase			(	_A :				Dict	,   _A :				int=False						)							->Any:



							"""simple docstring"""



							for pattern, fname in REPLACE_FILES.items():
														update_version_in_file(__A	,   __A	,   __A						)
							if not patch:
														update_version_in_examples(__A						)




def     __UpperCamelCase			(	)							->str:



							"""simple docstring"""
							lowerCamelCase_				     ="""🤗 Transformers currently provides the following architectures"""
							lowerCamelCase_				     ="""1. Want to contribute a new model?"""
							with open(__A	,   """r"""	,   encoding="""utf-8"""	,   newline="""\n"""						) as f:
														lowerCamelCase_				     =f.readlines()

							# Find the start of the list.
							lowerCamelCase_				     =0
							while not lines[start_index].startswith(_start_prompt						):
														start_index += 1
							start_index += 1

							lowerCamelCase_				     =start_index
							# Update the lines in the model list.
							while not lines[index].startswith(_end_prompt						):
														if lines[index].startswith("""1."""						):
																					lowerCamelCase_				     =lines[index].replace(
																					    """https://huggingface.co/docs/transformers/main/model_doc"""	,   """https://huggingface.co/docs/transformers/model_doc"""	,   )
														index += 1

							with open(__A	,   """w"""	,   encoding="""utf-8"""	,   newline="""\n"""						) as f:
														f.writelines(__A						)




def     __UpperCamelCase			(	)							->List[Any]:



							"""simple docstring"""



							with open(REPLACE_FILES["""init"""]	,   """r"""						) as f:
														lowerCamelCase_				     =f.read()
							lowerCamelCase_				     =REPLACE_PATTERNS["""init"""][0].search(__A						).groups()[0]
							return packaging.version.parse(__A						)




def     __UpperCamelCase			(	_A :				Optional[int]=False						)							->Tuple:



							"""simple docstring"""
							lowerCamelCase_				     =get_version()
							if patch and default_version.is_devrelease:
														raise ValueError("""Can\'t create a patch version from the dev branch, checkout a released version!"""						)
							if default_version.is_devrelease:
														lowerCamelCase_				     =default_version.base_version
							elif patch:
														lowerCamelCase_				     =f'{default_version.major}.{default_version.minor}.{default_version.micro + 1}'
							else:
														lowerCamelCase_				     =f'{default_version.major}.{default_version.minor + 1}.0'

							# Now let's ask nicely if that's the right one.
							lowerCamelCase_				     =input(f'Which version are you releasing? [{default_version}]'						)
							if len(__A						) == 0:
														lowerCamelCase_				     =default_version

							print(f'Updating version to {version}.'						)
							global_version_update(__A	,   patch=__A						)
							if not patch:
														print("""Cleaning main README, don\'t forget to run `make fix-copies`."""						)
														clean_main_ref_in_model_list()




def     __UpperCamelCase			(	)							->Dict:



							"""simple docstring"""
							lowerCamelCase_				     =get_version()
							lowerCamelCase_				     =f'{current_version.major}.{current_version.minor + 1}.0.dev0'
							lowerCamelCase_				     =current_version.base_version

							# Check with the user we got that right.
							lowerCamelCase_				     =input(f'Which version are we developing now? [{dev_version}]'						)
							if len(__A						) == 0:
														lowerCamelCase_				     =dev_version

							print(f'Updating version to {version}.'						)
							global_version_update(__A						)
							print("""Cleaning main README, don\'t forget to run `make fix-copies`."""						)
							clean_main_ref_in_model_list()


if __name__ == "__main__":
	__A     :					Optional[Any]     = argparse.ArgumentParser()
	parser.add_argument('--post_release', action='store_true', help='Whether this is pre or post release.')
	parser.add_argument('--patch', action='store_true', help='Whether or not this is a patch release.')
	__A     :					List[str]     = parser.parse_args()
	if not args.post_release:
		pre_release_work(patch=args.patch)
	elif args.patch:
		print('Nothing to do after a patch :-)')
	else:
		post_release_work()





'''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  (__A  ,	__A  ,	__A  ,	__A):



     """simple docstring"""



     if isinstance(__A  ,	__A):
          _a      =  np.full((len(__A), sequence_length, 2)  ,	__A)
     else:
          _a      =  np.full((len(__A), sequence_length)  ,	__A)

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

     return out_tensor.tolist()




def lowerCAmelCase  (__A):



     """simple docstring"""



     _a      =  ord(__A)
     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
     _a      =  unicodedata.category(__A)
     if cat.startswith('''P'''):
          return True
     return False






@dataclass
class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       PreTrainedTokenizerBase
 __lowerCamelCase    :       Union[bool, str, PaddingStrategy]          =       True
 __lowerCamelCase    :       Optional[int]          =       None
 __lowerCamelCase    :       Optional[int]          =       None
 __lowerCamelCase    :       int          =       -100
 __lowerCamelCase    :       str          =       "pt"



 def 					a__  (self ,   A       )    ->     List[str]:


      """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(
          A ,   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(A       ) + [self.label_pad_token_id] * (sequence_length - len(A       )) for label in labels
           ]
      else:
           _a      =  [
               [self.label_pad_token_id] * (sequence_length - len(A       )) + list(A       ) for label in labels
           ]

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

      return batch



