



'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

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


_lowerCamelCase	:       int      	=	logging.get_logger(__name__)

_lowerCamelCase	:       List[Any]      	=	{
    "andreasmadsen/efficient_mlm_m0.40": (
        "https://huggingface.co/andreasmadsen/efficient_mlm_m0.40/resolve/main/config.json"
    ),
}

class  SCREAMING_SNAKE_CASE (  _a		):






    """simple docstring"""





    _SCREAMING_SNAKE_CASE	  =  """roberta-prelayernorm"""






    def __init__(  self      :					Tuple  ,						UpperCamelCase__      :					Dict=5_0_2_6_5  ,						UpperCamelCase__      :					Optional[int]=7_6_8  ,						UpperCamelCase__      :					Any=1_2  ,						UpperCamelCase__      :					Optional[Any]=1_2  ,						UpperCamelCase__      :					Union[str, Any]=3_0_7_2  ,						UpperCamelCase__      :					List[Any]="gelu"  ,						UpperCamelCase__      :					List[Any]=0.1  ,						UpperCamelCase__      :					Dict=0.1  ,						UpperCamelCase__      :					Tuple=5_1_2  ,						UpperCamelCase__      :					Optional[int]=2  ,						UpperCamelCase__      :					List[str]=0.0_2  ,						UpperCamelCase__      :					List[str]=1E-1_2  ,						UpperCamelCase__      :					Optional[int]=1  ,						UpperCamelCase__      :					Union[str, Any]=0  ,						UpperCamelCase__      :					str=2  ,						UpperCamelCase__      :					Optional[int]="absolute"  ,						UpperCamelCase__      :					List[str]=True  ,						UpperCamelCase__      :					Optional[int]=None  ,						**UpperCamelCase__      :					List[Any]  ,						):


       """simple docstring"""







       super().__init__(pad_token_id=UpperCamelCase__  ,						bos_token_id=UpperCamelCase__  ,						eos_token_id=UpperCamelCase__  ,						**UpperCamelCase__ )

       UpperCamelCase					=  vocab_size
       UpperCamelCase					=  hidden_size
       UpperCamelCase					=  num_hidden_layers
       UpperCamelCase					=  num_attention_heads
       UpperCamelCase					=  hidden_act
       UpperCamelCase					=  intermediate_size
       UpperCamelCase					=  hidden_dropout_prob
       UpperCamelCase					=  attention_probs_dropout_prob
       UpperCamelCase					=  max_position_embeddings
       UpperCamelCase					=  type_vocab_size
       UpperCamelCase					=  initializer_range
       UpperCamelCase					=  layer_norm_eps
       UpperCamelCase					=  position_embedding_type
       UpperCamelCase					=  use_cache
       UpperCamelCase					=  classifier_dropout

class  SCREAMING_SNAKE_CASE (  _a		):






    """simple docstring"""





    @property
    def  A       (  self      :					int ):


       """simple docstring"""







       if self.task == "multiple-choice":
          UpperCamelCase					=  {0: 'batch', 1: 'choice', 2: 'sequence'}
       else:
          UpperCamelCase					=  {0: 'batch', 1: 'sequence'}
       return OrderedDict(
           [
               ('input_ids', dynamic_axis),
               ('attention_mask', dynamic_axis),
           ] )






'''simple docstring'''


from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
   import numpy as np
   from decord import VideoReader


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

_lowerCamelCase	:       Any      	=	logging.get_logger(__name__)

@add_end_docstrings(_a		)
class  SCREAMING_SNAKE_CASE (  _a		):






    """simple docstring"""





    def __init__(  self      :					Any  ,						*UpperCamelCase__      :					Dict  ,						**UpperCamelCase__      :					Union[str, Any] ):


       """simple docstring"""







       super().__init__(*UpperCamelCase__  ,						**UpperCamelCase__ )
       requires_backends(self  ,						'decord' )
       self.check_model_type(UpperCamelCase__ )






    def  A       (  self      :					Optional[int]  ,						UpperCamelCase__      :					Optional[int]=None  ,						UpperCamelCase__      :					Optional[Any]=None  ,						UpperCamelCase__      :					Optional[Any]=None ):


       """simple docstring"""







       UpperCamelCase					=  {}
       if frame_sampling_rate is not None:
          UpperCamelCase					=  frame_sampling_rate
       if num_frames is not None:
          UpperCamelCase					=  num_frames

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






    def __call__(  self      :					List[str]  ,						UpperCamelCase__      :					Union[str, List[str]]  ,						**UpperCamelCase__      :					Dict ):


       """simple docstring"""







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






    def  A       (  self      :					Tuple  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					Tuple=None  ,						UpperCamelCase__      :					Tuple=1 ):


       """simple docstring"""







       if num_frames is None:
          UpperCamelCase					=  self.model.config.num_frames

       if video.startswith('http://' ) or video.startswith('https://' ):
          UpperCamelCase					=  BytesIO(requests.get(UpperCamelCase__ ).content )

       UpperCamelCase					=  VideoReader(UpperCamelCase__ )
       videoreader.seek(0 )

       UpperCamelCase					=  0
       UpperCamelCase					=  num_frames * frame_sampling_rate - 1
       UpperCamelCase					=  np.linspace(UpperCamelCase__  ,						UpperCamelCase__  ,						num=UpperCamelCase__  ,						dtype=np.intaa )

       UpperCamelCase					=  videoreader.get_batch(UpperCamelCase__ ).asnumpy()
       UpperCamelCase					=  list(UpperCamelCase__ )

       UpperCamelCase					=  self.image_processor(UpperCamelCase__  ,						return_tensors=self.framework )
       return model_inputs






    def  A       (  self      :					Union[str, Any]  ,						UpperCamelCase__      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  self.model(**UpperCamelCase__ )
       return model_outputs






    def  A       (  self      :					int  ,						UpperCamelCase__      :					str  ,						UpperCamelCase__      :					List[Any]=5 ):


       """simple docstring"""







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

       if self.framework == "pt":
          UpperCamelCase					=  model_outputs.logits.softmax(-1 )[0]
          UpperCamelCase				,      UpperCamelCase					=  probs.topk(UpperCamelCase__ )
       else:
          raise ValueError(f"""Unsupported framework: {self.framework}""" )

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

