


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case    :   List[str]	    =					logging.get_logger(__name__)

snake_case    :   int	    =					{
    '''YituTech/conv-bert-base''': '''https://huggingface.co/YituTech/conv-bert-base/resolve/main/config.json''',
    '''YituTech/conv-bert-medium-small''': (
        '''https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/config.json'''
    ),
    '''YituTech/conv-bert-small''': '''https://huggingface.co/YituTech/conv-bert-small/resolve/main/config.json''',
    # See all ConvBERT models at https://huggingface.co/models?filter=convbert
}







class 		_snake_case  (				_snake_case							):
 SCREAMING_SNAKE_CASE__				=	'convbert'




 def __init__(		self ,  _lowerCamelCase=3_0522 ,  _lowerCamelCase=768 ,  _lowerCamelCase=12 ,  _lowerCamelCase=12 ,  _lowerCamelCase=3072 ,  _lowerCamelCase="gelu" ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=512 ,  _lowerCamelCase=2 ,  _lowerCamelCase=0.02 ,  _lowerCamelCase=1e-12 ,  _lowerCamelCase=1 ,  _lowerCamelCase=0 ,  _lowerCamelCase=2 ,  _lowerCamelCase=768 ,  _lowerCamelCase=2 ,  _lowerCamelCase=9 ,  _lowerCamelCase=1 ,  _lowerCamelCase=None ,  **_lowerCamelCase ,  ):
       super().__init__(
           pad_token_id=_lowerCamelCase ,  bos_token_id=_lowerCamelCase ,  eos_token_id=_lowerCamelCase ,  **_lowerCamelCase ,  )

       a						:Union[str, Any]										=	vocab_size
       a						:List[str]										=	hidden_size
       a						:Union[str, Any]										=	num_hidden_layers
       a						:Optional[Any]										=	num_attention_heads
       a						:str										=	intermediate_size
       a						:Any										=	hidden_act
       a						:Dict										=	hidden_dropout_prob
       a						:str										=	attention_probs_dropout_prob
       a						:Union[str, Any]										=	max_position_embeddings
       a						:int										=	type_vocab_size
       a						:Dict										=	initializer_range
       a						:List[str]										=	layer_norm_eps
       a						:int										=	embedding_size
       a						:List[str]										=	head_ratio
       a						:Optional[int]										=	conv_kernel_size
       a						:Union[str, Any]										=	num_groups
       a						:Union[str, Any]										=	classifier_dropout







class 		_snake_case  (				_snake_case							):




 @property
 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       if self.task == "multiple-choice":
             a						:List[str]										=	{0: '''batch''', 1: '''choice''', 2: '''sequence'''}
       else:
             a						:List[str]										=	{0: '''batch''', 1: '''sequence'''}
       return OrderedDict(
           [
               ('''input_ids''', dynamic_axis),
               ('''attention_mask''', dynamic_axis),
               ('''token_type_ids''', dynamic_axis),
           ]   )









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

snake_case    :   str	    =					logging.get_logger(__name__)







@add_end_docstrings(_snake_case							)
class 		_snake_case  (				_snake_case							):




 def __init__(		self ,  *_lowerCamelCase ,  **_lowerCamelCase   ):
       super().__init__(*_lowerCamelCase ,  **_lowerCamelCase   )
       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 ,  _lowerCamelCase=None   ):
       a						:Tuple										=	{}
       if top_k is not None:
             a						:int										=	top_k
       return {}, {}, postprocess_params




 def __call__(		self ,  _lowerCamelCase ,  **_lowerCamelCase   ):
       return super().__call__(_lowerCamelCase ,  **_lowerCamelCase   )




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase   ):
       a						:str										=	load_image(_lowerCamelCase   )
       a						:Any										=	self.image_processor(images=_lowerCamelCase ,  return_tensors=self.framework   )
       return model_inputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase   ):
       a						:List[str]										=	self.model(**_lowerCamelCase   )
       return model_outputs




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase ,  _lowerCamelCase=5   ):
       if top_k > self.model.config.num_labels:
             a						:List[Any]										=	self.model.config.num_labels

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

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





