



import argparse
import os
import re

import packaging.version


a_			=					"""examples/"""
a_			=					{
    """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_			=					{
    """init""": """src/transformers/__init__.py""",
    """setup""": """setup.py""",
}
a_			=					"""README.md"""





def 		a__			(		_UpperCamelCase			: Optional[Any] ,_UpperCamelCase			: Tuple ,_UpperCamelCase			: Any							):
   with open(_UpperCamelCase ,'''r''' ,encoding='''utf-8''' ,newline='''\n'''							) as f:
      __lowerCamelCase													=    f.read()
   __lowerCamelCase							,__lowerCamelCase													=    REPLACE_PATTERNS[pattern]
   __lowerCamelCase													=    replace.replace('''VERSION''' ,_UpperCamelCase							)
   __lowerCamelCase													=    re_pattern.sub(_UpperCamelCase ,_UpperCamelCase							)
   with open(_UpperCamelCase ,'''w''' ,encoding='''utf-8''' ,newline='''\n'''							) as f:
      f.write(_UpperCamelCase							)





def 		a__			(		_UpperCamelCase			: Union[str, Any]							):
   for folder, directories, fnames in os.walk(_UpperCamelCase							):
      # 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(_UpperCamelCase ,_UpperCamelCase							) ,_UpperCamelCase ,pattern='''examples'''							)





def 		a__			(		_UpperCamelCase			: Union[str, Any] ,_UpperCamelCase			: List[Any]=False							):
   for pattern, fname in REPLACE_FILES.items():
      update_version_in_file(_UpperCamelCase ,_UpperCamelCase ,_UpperCamelCase							)
   if not patch:
      update_version_in_examples(_UpperCamelCase							)





def 		a__			(		):
   __lowerCamelCase													=    '''🤗 Transformers currently provides the following architectures'''
   __lowerCamelCase													=    '''1. Want to contribute a new model?'''
   with open(_UpperCamelCase ,'''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(_UpperCamelCase ,'''w''' ,encoding='''utf-8''' ,newline='''\n'''							) as f:
      f.writelines(_UpperCamelCase							)





def 		a__			(		):
   with open(REPLACE_FILES['''init'''] ,'''r'''							) as f:
      __lowerCamelCase													=    f.read()
   __lowerCamelCase													=    REPLACE_PATTERNS['''init'''][0].search(_UpperCamelCase							).groups()[0]
   return packaging.version.parse(_UpperCamelCase							)





def 		a__			(		_UpperCamelCase			: Optional[Any]=False							):
   __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(_UpperCamelCase							) == 0:
      __lowerCamelCase													=    default_version

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





def 		a__			(		):
   __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(_UpperCamelCase							) == 0:
      __lowerCamelCase													=    dev_version

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


if __name__ == "__main__":
  a_			=					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_			=					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()











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

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

   return out_tensor.tolist()





def 		a__			(		_UpperCamelCase			: Dict							):
   __lowerCamelCase													=    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
   __lowerCamelCase													=    unicodedata.category(_UpperCamelCase							)
   if cat.startswith('''P'''							):
      return True
   return False





@dataclass
class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  42
 lowerCAmelCase__       					=  True
 lowerCAmelCase__       					=  None
 lowerCAmelCase__       					=  None
 lowerCAmelCase__       					=  -1_0_0
 lowerCAmelCase__       					=  "pt"




 def        lowerCamelCase      (						self	,				__UpperCAmelCase				):



    '''simple docstring'''
    import torch

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

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

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

    return batch






