
'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

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







class  __A				( __lowerCAmelCase			):
 lowerCamelCase				       ='''roc_bert'''
 def __init__(   self			:    Optional[int]				,   lowerCamelCase			:    Union[str, Any]=3_05_22				,   lowerCamelCase			:    int=7_68				,   lowerCamelCase			:    Any=12				,   lowerCamelCase			:    List[str]=12				,   lowerCamelCase			:    Tuple=30_72				,   lowerCamelCase			:    int="gelu"				,   lowerCamelCase			:    Any=0.1				,   lowerCamelCase			:    List[str]=0.1				,   lowerCamelCase			:    List[Any]=5_12				,   lowerCamelCase			:    Union[str, Any]=2				,   lowerCamelCase			:    Tuple=0.02				,   lowerCamelCase			:    List[Any]=1e-1_2				,   lowerCamelCase			:    Optional[int]=True				,   lowerCamelCase			:    List[Any]=0				,   lowerCamelCase			:    int="absolute"				,   lowerCamelCase			:    Optional[Any]=None				,   lowerCamelCase			:    List[str]=True				,   lowerCamelCase			:    Any=True				,   lowerCamelCase			:    Tuple=7_68				,   lowerCamelCase			:    int=9_10				,   lowerCamelCase			:    Optional[Any]=5_12				,   lowerCamelCase			:    List[str]=2_48_58				,   lowerCamelCase			:    Tuple=True				,   **lowerCamelCase			:    Optional[Any]				,   ):



   """simple docstring"""





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





'''simple docstring'''
from typing import Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
     from PIL import Image

     from ..image_utils import load_image

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

A__   :		Any 		=logging.get_logger(__name__)







@add_end_docstrings(_SCREAMING_SNAKE_CASE			)
class  __A				( _SCREAMING_SNAKE_CASE			):
 def __init__(   self			:    Union[str, Any]				,   *lowerCamelCase			:    int				,   **lowerCamelCase			:    Optional[int]       ):



   """simple docstring"""





   super().__init__(*lowerCamelCase				,   **lowerCamelCase       )
   self.check_model_type(lowerCamelCase       )
 def 		lowercase_(   self			:    Any				,   lowerCamelCase			:    Dict=None				,   lowerCamelCase			:    Union[str, Any]=None				,   lowerCamelCase			:    int=None				,   **lowerCamelCase			:    int       ):



   """simple docstring"""





   __A							,					__A		:     Tuple												=		{}, {}
   if padding is not None:
     __A		:     Any												=		padding
   if truncation is not None:
     __A		:     Optional[Any]												=		truncation
   if top_k is not None:
     __A		:     List[str]												=		top_k
   return preprocess_params, {}, postprocess_params
 def __call__(   self			:    Any				,   lowerCamelCase			:    Union["Image.Image", str]				,   lowerCamelCase			:    str = None				,   **lowerCamelCase			:    Tuple       ):



   """simple docstring"""





   if isinstance(lowerCamelCase				,   (Image.Image, str)       ) and isinstance(lowerCamelCase				,   lowerCamelCase       ):
     __A		:     Tuple												=		{"""image""": image, """question""": question}
   else:
     __A		:     List[Any]												=		image
   __A		:     Any												=		super().__call__(lowerCamelCase				,   **lowerCamelCase       )
   return results
 def 		lowercase_(   self			:    int				,   lowerCamelCase			:    Optional[int]				,   lowerCamelCase			:    Dict=False				,   lowerCamelCase			:    str=False       ):



   """simple docstring"""





   __A		:     List[str]												=		load_image(inputs["""image"""]       )
   __A		:     Optional[Any]												=		self.tokenizer(
       inputs["""question"""]				,   return_tensors=self.framework				,   padding=lowerCamelCase				,   truncation=lowerCamelCase       )
   __A		:     Union[str, Any]												=		self.image_processor(images=lowerCamelCase				,   return_tensors=self.framework       )
   model_inputs.update(lowerCamelCase       )
   return model_inputs
 def 		lowercase_(   self			:    List[str]				,   lowerCamelCase			:    Tuple       ):



   """simple docstring"""





   __A		:     List[str]												=		self.model(**lowerCamelCase       )
   return model_outputs






 def 		lowercase_(   self			:    str				,   lowerCamelCase			:    Optional[Any]				,   lowerCamelCase			:    List[Any]=5       ):



   """simple docstring"""





   if top_k > self.model.config.num_labels:
     __A		:     str												=		self.model.config.num_labels

   if self.framework == "pt":
     __A		:     Optional[Any]												=		model_outputs.logits.sigmoid()[0]
     __A							,					__A		:     int												=		probs.topk(lowerCamelCase       )
   else:
     raise ValueError(f"Unsupported framework: {self.framework}"       )

   __A		:     Optional[Any]												=		scores.tolist()
   __A		:     Dict												=		ids.tolist()
   return [{"score": score, "answer": self.model.config.idalabel[_id]} for score, _id in zip(lowerCamelCase				,   lowerCamelCase       )]



