






'''simple docstring'''





import numpy as np

from transformers import Pipeline






def    lowerCamelCase_     (    lowercase__):
 lowerCamelCase__  =     np.max(lowercase__				,     axis=-1				,     keepdims=lowercase__)
 lowerCamelCase__  =     np.exp(outputs - maxes)
 return shifted_exp / shifted_exp.sum(axis=-1				,     keepdims=lowercase__)
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    def    a__				(					self     :     List[Any]				,     **__lowerCamelCase     :     Dict     )							->							int:

     '''simple docstring'''




     lowerCamelCase__  =     {}
     if "second_text" in kwargs:
      lowerCamelCase__  =     kwargs["second_text"]
     return preprocess_kwargs, {}, {}

    def    a__				(					self     :     List[Any]				,     __lowerCamelCase     :     str				,     __lowerCamelCase     :     List[Any]=None     )							->							Any:

     '''simple docstring'''




     return self.tokenizer(__lowerCamelCase				,     text_pair=__lowerCamelCase				,     return_tensors=self.framework     )

    def    a__				(					self     :     List[Any]				,     __lowerCamelCase     :     int     )							->							Union[str, Any]:

     '''simple docstring'''




     return self.model(**__lowerCamelCase     )




    def    a__				(					self     :     Optional[Any]				,     __lowerCamelCase     :     Any     )							->							Tuple:

     '''simple docstring'''




     lowerCamelCase__  =     model_outputs.logits[0].numpy()
     lowerCamelCase__  =     softmax(__lowerCamelCase     )

     lowerCamelCase__  =     np.argmax(__lowerCamelCase     )
     lowerCamelCase__  =     self.model.config.idalabel[best_class]
     lowerCamelCase__  =     probabilities[best_class].item()
     lowerCamelCase__  =     logits.tolist()
     return {"label": label, "score": score, "logits": logits}









'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__A							:							Union[str, Any]  							=		{
    """configuration_layoutlmv2""": ["""LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LayoutLMv2Config"""],
    """processing_layoutlmv2""": ["""LayoutLMv2Processor"""],
    """tokenization_layoutlmv2""": ["""LayoutLMv2Tokenizer"""],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A							:							Optional[Any]  							=		["""LayoutLMv2TokenizerFast"""]

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A							:							List[Any]  							=		["""LayoutLMv2FeatureExtractor"""]
 __A							:							List[Any]  							=		["""LayoutLMv2ImageProcessor"""]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A							:							Any  							=		[
     """LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
     """LayoutLMv2ForQuestionAnswering""",
     """LayoutLMv2ForSequenceClassification""",
     """LayoutLMv2ForTokenClassification""",
     """LayoutLMv2Layer""",
     """LayoutLMv2Model""",
     """LayoutLMv2PreTrainedModel""",
 ]

if TYPE_CHECKING:
 from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
 from .processing_layoutlmva import LayoutLMvaProcessor
 from .tokenization_layoutlmva import LayoutLMvaTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_layoutlmva import (
      LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
      LayoutLMvaForQuestionAnswering,
      LayoutLMvaForSequenceClassification,
      LayoutLMvaForTokenClassification,
      LayoutLMvaLayer,
      LayoutLMvaModel,
      LayoutLMvaPreTrainedModel,
  )
else:
 import sys

 __A							:							Tuple  							=		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

