





'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


_SCREAMING_SNAKE_CASE									=				{
    "albert-base-v1": "https://huggingface.co/albert-base-v1/resolve/main/config.json",
    "albert-large-v1": "https://huggingface.co/albert-large-v1/resolve/main/config.json",
    "albert-xlarge-v1": "https://huggingface.co/albert-xlarge-v1/resolve/main/config.json",
    "albert-xxlarge-v1": "https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json",
    "albert-base-v2": "https://huggingface.co/albert-base-v2/resolve/main/config.json",
    "albert-large-v2": "https://huggingface.co/albert-large-v2/resolve/main/config.json",
    "albert-xlarge-v2": "https://huggingface.co/albert-xlarge-v2/resolve/main/config.json",
    "albert-xxlarge-v2": "https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json",
}

class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				Dict								=       "albert"




 def __init__(						self      ,  _lowerCAmelCase=30000      ,  _lowerCAmelCase=128      ,  _lowerCAmelCase=4096      ,  _lowerCAmelCase=12      ,  _lowerCAmelCase=1      ,  _lowerCAmelCase=64      ,  _lowerCAmelCase=16384      ,  _lowerCAmelCase=1      ,  _lowerCAmelCase="gelu_new"      ,  _lowerCAmelCase=0      ,  _lowerCAmelCase=0      ,  _lowerCAmelCase=512      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=0.02      ,  _lowerCAmelCase=1E-12      ,  _lowerCAmelCase=0.1      ,  _lowerCAmelCase="absolute"      ,  _lowerCAmelCase=0      ,  _lowerCAmelCase=2      ,  _lowerCAmelCase=3      ,  **_lowerCAmelCase      ,  )     ->				str:
     super().__init__(pad_token_id=_lowerCAmelCase      ,  bos_token_id=_lowerCAmelCase      ,  eos_token_id=_lowerCAmelCase      ,  **_lowerCAmelCase		)

     _lowerCAmelCase						      =   vocab_size
     _lowerCAmelCase						      =   embedding_size
     _lowerCAmelCase						      =   hidden_size
     _lowerCAmelCase						      =   num_hidden_layers
     _lowerCAmelCase						      =   num_hidden_groups
     _lowerCAmelCase						      =   num_attention_heads
     _lowerCAmelCase						      =   inner_group_num
     _lowerCAmelCase						      =   hidden_act
     _lowerCAmelCase						      =   intermediate_size
     _lowerCAmelCase						      =   hidden_dropout_prob
     _lowerCAmelCase						      =   attention_probs_dropout_prob
     _lowerCAmelCase						      =   max_position_embeddings
     _lowerCAmelCase						      =   type_vocab_size
     _lowerCAmelCase						      =   initializer_range
     _lowerCAmelCase						      =   layer_norm_eps
     _lowerCAmelCase						      =   classifier_dropout_prob
     _lowerCAmelCase						      =   position_embedding_type







class  lowerCAmelCase_		(		__magic_name__		):




 @property
 def 				_snake_case (						self		)     ->				Mapping[str, Mapping[int, str]]:
     if self.task == "multiple-choice":
         _lowerCAmelCase						      =   {0: "batch", 1: "choice", 2: "sequence"}
     else:
         _lowerCAmelCase						      =   {0: "batch", 1: "sequence"}
     return OrderedDict(
         [
             ("input_ids", dynamic_axis),
             ("attention_mask", dynamic_axis),
             ("token_type_ids", dynamic_axis),
         ]		)





'''simple docstring'''



from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
     from PIL import Image

     from ..image_utils import load_image

if is_tf_available():
     import tensorflow as tf

     from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
     from ..tf_utils import stable_softmax

if is_torch_available():
     from ..models.auto.modeling_auto import MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING

_UpperCamelCase						:  Optional[int]							       =				logging.get_logger(__name__)



@add_end_docstrings(a_			)
class 				_snake_case					(   a_			):

  def __init__(				self      , *_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      super().__init__(*_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	)
      requires_backends(self      , 'vision'	)
      self.check_model_type(
          TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
          if self.framework == 'tf'
          else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING	)

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE=None	):





      '''simple docstring'''

      lowerCAmelCase 						=							{}
      if top_k is not None:
          lowerCAmelCase 						=							top_k
      return {}, {}, postprocess_params

  def __call__(				self      , _SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      return super().__call__(_SCREAMING_SNAKE_CASE      , **_SCREAMING_SNAKE_CASE	)

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      lowerCAmelCase 						=							load_image(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							self.image_processor(images=_SCREAMING_SNAKE_CASE      , return_tensors=self.framework	)
      return model_inputs

  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.model(**_SCREAMING_SNAKE_CASE	)
      return model_outputs


  def   _SCREAMING_SNAKE_CASE				(				self      , _SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE=5	):





      '''simple docstring'''

      if top_k > self.model.config.num_labels:
          lowerCAmelCase 						=							self.model.config.num_labels

      if self.framework == "pt":
          lowerCAmelCase 						=							model_outputs.logits.softmax(-1	)[0]
          lowerCAmelCase						,   lowerCAmelCase 						=							probs.topk(_SCREAMING_SNAKE_CASE	)
      elif self.framework == "tf":
          lowerCAmelCase 						=							stable_softmax(model_outputs.logits      , axis=-1	)[0]
          lowerCAmelCase 						=							tf.math.top_k(_SCREAMING_SNAKE_CASE      , k=_SCREAMING_SNAKE_CASE	)
          lowerCAmelCase						,   lowerCAmelCase 						=							topk.values.numpy(), topk.indices.numpy()
      else:
          raise ValueError(F'Unsupported framework: {self.framework}'	)

      lowerCAmelCase 						=							scores.tolist()
      lowerCAmelCase 						=							ids.tolist()
      return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_SCREAMING_SNAKE_CASE      , _SCREAMING_SNAKE_CASE	)]





