from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

lowerCAmelCase			:							int     ={
    "weiweishi/roc-bert-base-zh": "https://huggingface.co/weiweishi/roc-bert-base-zh/resolve/main/config.json",
}




class 	__snake_case	( __lowerCAmelCase		):





      '''simple docstring'''






      _snake_case    		=       'roc_bert'



      def __init__(					self     :				Optional[int]    ,  _UpperCamelCase     :				Union[str, Any]=3_0522    ,  _UpperCamelCase     :				int=768    ,  _UpperCamelCase     :				Any=12    ,  _UpperCamelCase     :				List[str]=12    ,  _UpperCamelCase     :				Tuple=3072    ,  _UpperCamelCase     :				int="gelu"    ,  _UpperCamelCase     :				Any=0.1    ,  _UpperCamelCase     :				List[str]=0.1    ,  _UpperCamelCase     :				List[Any]=512    ,  _UpperCamelCase     :				Union[str, Any]=2    ,  _UpperCamelCase     :				Tuple=0.0_2    ,  _UpperCamelCase     :				List[Any]=1E-1_2    ,  _UpperCamelCase     :				Optional[int]=True    ,  _UpperCamelCase     :				List[Any]=0    ,  _UpperCamelCase     :				int="absolute"    ,  _UpperCamelCase     :				Optional[Any]=None    ,  _UpperCamelCase     :				List[str]=True    ,  _UpperCamelCase     :				Any=True    ,  _UpperCamelCase     :				Tuple=768    ,  _UpperCamelCase     :				int=910    ,  _UpperCamelCase     :				Optional[Any]=512    ,  _UpperCamelCase     :				List[str]=2_4858    ,  _UpperCamelCase     :				Tuple=True    ,  **_UpperCamelCase     :				Optional[Any]    ,  )				->List[str]:


          """simple docstring"""


          _lowerCamelCase     :		int 						=						vocab_size
          _lowerCamelCase     :		int 						=						max_position_embeddings
          _lowerCamelCase     :		int 						=						hidden_size
          _lowerCamelCase     :		Optional[int] 						=						num_hidden_layers
          _lowerCamelCase     :		Dict 						=						num_attention_heads
          _lowerCamelCase     :		List[Any] 						=						intermediate_size
          _lowerCamelCase     :		str 						=						hidden_act
          _lowerCamelCase     :		Tuple 						=						hidden_dropout_prob
          _lowerCamelCase     :		Union[str, Any] 						=						attention_probs_dropout_prob
          _lowerCamelCase     :		List[Any] 						=						initializer_range
          _lowerCamelCase     :		Tuple 						=						type_vocab_size
          _lowerCamelCase     :		Optional[Any] 						=						layer_norm_eps
          _lowerCamelCase     :		List[str] 						=						use_cache
          _lowerCamelCase     :		List[Any] 						=						enable_pronunciation
          _lowerCamelCase     :		List[str] 						=						enable_shape
          _lowerCamelCase     :		Dict 						=						pronunciation_embed_dim
          _lowerCamelCase     :		Optional[Any] 						=						pronunciation_vocab_size
          _lowerCamelCase     :		str 						=						shape_embed_dim
          _lowerCamelCase     :		List[Any] 						=						shape_vocab_size
          _lowerCamelCase     :		int 						=						concat_input
          _lowerCamelCase     :		Optional[int] 						=						position_embedding_type
          _lowerCamelCase     :		Tuple 						=						classifier_dropout
          super().__init__(pad_token_id=_UpperCamelCase    ,  **_UpperCamelCase)





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

lowerCAmelCase			:							Optional[Any]     =logging.get_logger(__name__)




@add_end_docstrings(__lowerCAmelCase		)
class 	__snake_case	( __lowerCAmelCase		):





      '''simple docstring'''






      def __init__(					self     :				str    ,  *_UpperCamelCase     :				int    ,  **_UpperCamelCase     :				List[str])				->Tuple:


          """simple docstring"""


          super().__init__(*_UpperCamelCase    ,  **_UpperCamelCase)
          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     :				Dict    ,  _UpperCamelCase     :				List[str]=None)				->Optional[int]:


          """simple docstring"""


          _lowerCamelCase     :		Optional[int] 						=						{}
          if top_k is not None:
              _lowerCamelCase     :		str 						=						top_k
          return {}, {}, postprocess_params



      def __call__(					self     :				Optional[int]    ,  _UpperCamelCase     :				Union[str, List[str], "Image.Image", List["Image.Image"]]    ,  **_UpperCamelCase     :				Optional[int])				->Dict:


          """simple docstring"""


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



      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[int]    ,  _UpperCamelCase     :				Optional[int])				->str:


          """simple docstring"""


          _lowerCamelCase     :		Tuple 						=						load_image(_UpperCamelCase)
          _lowerCamelCase     :		Any 						=						self.image_processor(images=_UpperCamelCase    ,  return_tensors=self.framework)
          return model_inputs



      def 	_SCREAMING_SNAKE_CASE    (					self     :				str    ,  _UpperCamelCase     :				Union[str, Any])				->List[str]:


          """simple docstring"""


          _lowerCamelCase     :		Any 						=						self.model(**_UpperCamelCase)
          return model_outputs




      def 	_SCREAMING_SNAKE_CASE    (					self     :				Optional[Any]    ,  _UpperCamelCase     :				List[str]    ,  _UpperCamelCase     :				List[str]=5)				->str:


          """simple docstring"""


          if top_k > self.model.config.num_labels:
              _lowerCamelCase     :		Union[str, Any] 						=						self.model.config.num_labels

          if self.framework == "pt":
              _lowerCamelCase     :		Optional[Any] 						=						model_outputs.logits.softmax(-1)[0]
              _lowerCamelCase						,							_lowerCamelCase     :		Dict 						=						probs.topk(_UpperCamelCase)
          elif self.framework == "tf":
              _lowerCamelCase     :		List[Any] 						=						stable_softmax(model_outputs.logits    ,  axis=-1)[0]
              _lowerCamelCase     :		List[Any] 						=						tf.math.top_k(_UpperCamelCase    ,  k=_UpperCamelCase)
              _lowerCamelCase						,							_lowerCamelCase     :		str 						=						topk.values.numpy(), topk.indices.numpy()
          else:
              raise ValueError(F"""Unsupported framework: {self.framework}""")

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




