





"""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_  )						->Dict:





  """simple docstring"""


  if isinstance(UpperCAmelCase_  ,			UpperCAmelCase_  ):
    __UpperCAmelCase    :						Optional[Any]       =						np.full((len(UpperCAmelCase_  ), sequence_length, 2)  ,			UpperCAmelCase_  )
  else:
    __UpperCAmelCase    :						str       =						np.full((len(UpperCAmelCase_  ), sequence_length)  ,			UpperCAmelCase_  )

  for i, tensor in enumerate(UpperCAmelCase_  ):
    if padding_side == "right":
      if isinstance(UpperCAmelCase_  ,			UpperCAmelCase_  ):
        __UpperCAmelCase    :						List[str]       =						tensor[:sequence_length]
      else:
        __UpperCAmelCase    :						List[str]       =						tensor[:sequence_length]
    else:
      if isinstance(UpperCAmelCase_  ,			UpperCAmelCase_  ):
        __UpperCAmelCase    :						Tuple       =						tensor[:sequence_length]
      else:
        __UpperCAmelCase    :						Union[str, Any]       =						tensor[:sequence_length]

  return out_tensor.tolist()


def       lowerCamelCase_       (   UpperCAmelCase_  )						->str:





  """simple docstring"""


  __UpperCAmelCase    :						Dict       =						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
  __UpperCAmelCase    :						List[str]       =						unicodedata.category(UpperCAmelCase_  )
  if cat.startswith('''P'''  ):
    return True
  return False







@dataclass
class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      _A     :       PreTrainedTokenizerBase
      _A     :       Union[bool, str, PaddingStrategy]         =       True
      _A     :       Optional[int]         =       None
      _A     :       Optional[int]         =       None
      _A     :       int         =       -1_00
      _A     :       str         =       "pt"

      def       A_					(							self       :      Optional[Any]						,				__lowercase       :      int ):


        '''simple docstring'''




        import torch

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

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

        return batch






"""simple docstring"""





# coding=utf-8
# Copyright 2020 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# this script dumps information about the environment

import os
import sys

import transformers


lowercase__				:int				   =       '3'

print('Python version:', sys.version)
print('transformers version:', transformers.__version__)

try:
  import torch

  print('Torch version:', torch.__version__)
  print('Cuda available:', torch.cuda.is_available())
  print('Cuda version:', torch.version.cuda)
  print('CuDNN version:', torch.backends.cudnn.version())
  print('Number of GPUs available:', torch.cuda.device_count())
  print('NCCL version:', torch.cuda.nccl.version())
except ImportError:
  print('Torch version:', None)

try:
  import deepspeed

  print('DeepSpeed version:', deepspeed.__version__)
except ImportError:
  print('DeepSpeed version:', None)

try:
  import tensorflow as tf

  print('TensorFlow version:', tf.__version__)
  print('TF GPUs available:', bool(tf.config.list_physical_devices('GPU')))
  print('Number of TF GPUs available:', len(tf.config.list_physical_devices('GPU')))
except ImportError:
  print('TensorFlow version:', None)