




'''simple docstring'''







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


A									=logging.get_logger(__name__)

A									={
    'transfo-xl-wt103': 'https://huggingface.co/transfo-xl-wt103/resolve/main/config.json',
}


class     _a						(			__a				):
       __a       :  List[str]            =      """transfo-xl"""
       __a       :  Tuple            =      ["""mems"""]
       __a       :  Dict            =      {
           """n_token""": """vocab_size""",
           """hidden_size""": """d_model""",
           """num_attention_heads""": """n_head""",
           """num_hidden_layers""": """n_layer""",
       }
       def __init__(			self		:			Optional[int]     ,       lowercase		:			str=267_735     ,       lowercase		:			Optional[Any]=[20_000, 40_000, 200_000]     ,       lowercase		:			Optional[Any]=1_024     ,       lowercase		:			Dict=1_024     ,       lowercase		:			str=16     ,       lowercase		:			List[str]=64     ,       lowercase		:			Tuple=4_096     ,       lowercase		:			Union[str, Any]=4     ,       lowercase		:			Any=False     ,       lowercase		:			str=18     ,       lowercase		:			Tuple=1_600     ,       lowercase		:			int=1_000     ,       lowercase		:			List[Any]=True     ,       lowercase		:			Optional[Any]=True     ,       lowercase		:			Optional[Any]=0     ,       lowercase		:			Optional[int]=-1     ,       lowercase		:			List[Any]=True     ,       lowercase		:			int=0.1     ,       lowercase		:			Any=0.0     ,       lowercase		:			Union[str, Any]=True     ,       lowercase		:			Union[str, Any]="normal"     ,       lowercase		:			Union[str, Any]=0.01     ,       lowercase		:			Dict=0.01     ,       lowercase		:			Optional[int]=0.02     ,       lowercase		:			List[Any]=1E-5     ,       lowercase		:			Any=0     ,       **lowercase		:			int     ,       ):



           '''simple docstring'''

           UpperCAmelCase     =	vocab_size
           UpperCAmelCase     =	[]
           self.cutoffs.extend(lowercase       )
           if proj_share_all_but_first:
               UpperCAmelCase     =	[False] + [True] * len(self.cutoffs       )
           else:
               UpperCAmelCase     =	[False] + [False] * len(self.cutoffs       )
           UpperCAmelCase     =	d_model
           UpperCAmelCase     =	d_embed
           UpperCAmelCase     =	d_head
           UpperCAmelCase     =	d_inner
           UpperCAmelCase     =	div_val
           UpperCAmelCase     =	pre_lnorm
           UpperCAmelCase     =	n_layer
           UpperCAmelCase     =	n_head
           UpperCAmelCase     =	mem_len
           UpperCAmelCase     =	same_length
           UpperCAmelCase     =	attn_type
           UpperCAmelCase     =	clamp_len
           UpperCAmelCase     =	sample_softmax
           UpperCAmelCase     =	adaptive
           UpperCAmelCase     =	dropout
           UpperCAmelCase     =	dropatt
           UpperCAmelCase     =	untie_r
           UpperCAmelCase     =	init
           UpperCAmelCase     =	init_range
           UpperCAmelCase     =	proj_init_std
           UpperCAmelCase     =	init_std
           UpperCAmelCase     =	layer_norm_epsilon
           super().__init__(eos_token_id=lowercase     ,       **lowercase       )
       @property
       def 					A   (			self		:			Any       ):



           '''simple docstring'''

           logger.info(f"The model {self.model_type} is one of the few models that has no sequence length limit."       )
           return -1







       @max_position_embeddings.setter
       def 					A   (			self		:			int     ,       lowercase		:			Optional[int]       ):



           '''simple docstring'''

           raise NotImplementedError(
               f"The model {self.model_type} is one of the few models that has no sequence length limit."       )










'''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									=logging.get_logger(__name__)


@add_end_docstrings(__a				)
class     _a						(			__a				):
       def __init__(			self		:			Optional[int]     ,       *lowercase		:			Any     ,       **lowercase		:			Optional[int]       ):



           '''simple docstring'''

           super().__init__(*lowercase     ,       **lowercase       )
           self.check_model_type(lowercase       )
       def 					A   (			self		:			List[str]     ,       lowercase		:			str=None     ,       lowercase		:			List[str]=None     ,       lowercase		:			List[str]=None     ,       **lowercase		:			List[str]       ):



           '''simple docstring'''

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



           '''simple docstring'''

           if isinstance(lowercase     ,       (Image.Image, str)       ) and isinstance(lowercase     ,       lowercase       ):
               UpperCAmelCase     =	{'''image''': image, '''question''': question}
           else:
               UpperCAmelCase     =	image
           UpperCAmelCase     =	super().__call__(lowercase     ,       **lowercase       )
           return results
       def 					A   (			self		:			List[Any]     ,       lowercase		:			List[str]     ,       lowercase		:			Any=False     ,       lowercase		:			Any=False       ):



           '''simple docstring'''

           UpperCAmelCase     =	load_image(inputs['''image''']       )
           UpperCAmelCase     =	self.tokenizer(
               inputs['''question''']     ,       return_tensors=self.framework     ,       padding=lowercase     ,       truncation=lowercase       )
           UpperCAmelCase     =	self.image_processor(images=lowercase     ,       return_tensors=self.framework       )
           model_inputs.update(lowercase       )
           return model_inputs
       def 					A   (			self		:			Dict     ,       lowercase		:			Optional[Any]       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.model(**lowercase       )
           return model_outputs







       def 					A   (			self		:			Union[str, Any]     ,       lowercase		:			int     ,       lowercase		:			Optional[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.sigmoid()[0]
               UpperCAmelCase ,  UpperCAmelCase     =	probs.topk(lowercase       )
           else:
               raise ValueError(f"Unsupported framework: {self.framework}"       )

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




