



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



    """simple docstring"""





    if isinstance(__lowerCAmelCase							,   __lowerCAmelCase      ):
        lowerCAmelCase__			:  Any											= np.full((len(__lowerCAmelCase      ), sequence_length, 2)							,   __lowerCAmelCase      )
    else:
        lowerCAmelCase__			:  Optional[int]											= np.full((len(__lowerCAmelCase      ), sequence_length)							,   __lowerCAmelCase      )

    for i, tensor in enumerate(__lowerCAmelCase      ):
        if padding_side == "right":
            if isinstance(__lowerCAmelCase							,   __lowerCAmelCase      ):
                lowerCAmelCase__			:  Tuple											= tensor[:sequence_length]
            else:
                lowerCAmelCase__			:  Any											= tensor[:sequence_length]
        else:
            if isinstance(__lowerCAmelCase							,   __lowerCAmelCase      ):
                lowerCAmelCase__			:  List[Any]											= tensor[:sequence_length]
            else:
                lowerCAmelCase__			:  List[Any]											= tensor[:sequence_length]

    return out_tensor.tolist()
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    lowerCAmelCase__			:  Any											= 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
    lowerCAmelCase__			:  List[Any]											= unicodedata.category(__lowerCAmelCase      )
    if cat.startswith("""P"""      ):
        return True
    return False






@dataclass
class 	lowerCAmelCase_(    UpperCamelCase_					):
  '''simple docstring'''




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




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase				)   ->		int:
      import torch

      lowerCAmelCase__			:  Tuple											= """label""" if """label""" in features[0].keys() else """labels"""
      lowerCAmelCase__			:  int											= [feature[label_name] for feature in features] if label_name in features[0].keys() else None
      lowerCAmelCase__			:  List[str]											= 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

      lowerCAmelCase__			:  List[Any]											= torch.tensor(batch["""entity_ids"""]				).shape[1]
      lowerCAmelCase__			:  Dict											= self.tokenizer.padding_side
      if padding_side == "right":
          lowerCAmelCase__			:  Any											= [
              list(_a				) + [self.label_pad_token_id] * (sequence_length - len(_a				)) for label in labels
          ]
      else:
          lowerCAmelCase__			:  List[str]											= [
              [self.label_pad_token_id] * (sequence_length - len(_a				)) + list(_a				) for label in labels
          ]

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

      return batch







'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_lowerCAmelCase										=     {
    '''configuration_blip_2''': [
        '''BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''Blip2Config''',
        '''Blip2QFormerConfig''',
        '''Blip2VisionConfig''',
    ],
    '''processing_blip_2''': ['''Blip2Processor'''],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _lowerCAmelCase										=     [
     '''BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''Blip2Model''',
     '''Blip2QFormerModel''',
     '''Blip2PreTrainedModel''',
     '''Blip2ForConditionalGeneration''',
     '''Blip2VisionModel''',
 ]

if TYPE_CHECKING:
 from .configuration_blip_a import (
     BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     BlipaConfig,
     BlipaQFormerConfig,
     BlipaVisionConfig,
 )
 from .processing_blip_a import BlipaProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_blip_a import (
      BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST,
      BlipaForConditionalGeneration,
      BlipaModel,
      BlipaPreTrainedModel,
      BlipaQFormerModel,
      BlipaVisionModel,
  )

else:
 import sys

 _lowerCAmelCase										=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


