


import numpy as np

from transformers import Pipeline



def 			lowerCAmelCase (		lowerCAmelCase_ )-> Dict:
				lowerCAmelCase_ :      List[Any]    				=				np.max(lowerCAmelCase_ ,   axis=-1 ,   keepdims=lowerCAmelCase_ )
				lowerCAmelCase_ :      Dict    				=				np.exp(outputs - maxes )
				return shifted_exp / shifted_exp.sum(axis=-1 ,   keepdims=lowerCAmelCase_ )







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						def 						lowercase_ (				self   ,						**__lowercase							)					->    Optional[int]:
										lowerCAmelCase_ :      Tuple    				=				{}
										if "second_text" in kwargs:
														lowerCAmelCase_ :      Tuple    				=				kwargs['''second_text''']
										return preprocess_kwargs, {}, {}




						def 						lowercase_ (				self   ,						__lowercase   ,						__lowercase=None							)					->    Tuple:
										return self.tokenizer(__lowercase   ,						text_pair=__lowercase   ,						return_tensors=self.framework							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    Tuple:
										return self.model(**__lowercase							)




						def 						lowercase_ (				self   ,						__lowercase							)					->    Dict:
										lowerCAmelCase_ :      List[str]    				=				model_outputs.logits[0].numpy()
										lowerCAmelCase_ :      Union[str, Any]    				=				softmax(__lowercase							)

										lowerCAmelCase_ :      str    				=				np.argmax(__lowercase							)
										lowerCAmelCase_ :      Union[str, Any]    				=				self.model.config.idalabel[best_class]
										lowerCAmelCase_ :      int    				=				probabilities[best_class].item()
										lowerCAmelCase_ :      str    				=				logits.tolist()
										return {"label": label, "score": score, "logits": logits}



import copy

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


_UpperCAmelCase			:  str     =logging.get_logger(__name__)







class 				snake_case__(							UpperCAmelCase__							):







						'''simple docstring'''




						SCREAMING_SNAKE_CASE__      :  Optional[int]					=							"""encoder-decoder"""
						SCREAMING_SNAKE_CASE__      :  str					=							True




						def __init__(				self   ,						**__lowercase							)					->    Union[str, Any]:
										super().__init__(**__lowercase							)
										assert (
										    "encoder" in kwargs and "decoder" in kwargs
										), "Config has to be initialized with encoder and decoder config"
										lowerCAmelCase_ :      str    				=				kwargs.pop('''encoder'''							)
										lowerCAmelCase_ :      int    				=				encoder_config.pop('''model_type'''							)
										lowerCAmelCase_ :      Optional[Any]    				=				kwargs.pop('''decoder'''							)
										lowerCAmelCase_ :      Optional[Any]    				=				decoder_config.pop('''model_type'''							)

										from ..auto.configuration_auto import AutoConfig

										lowerCAmelCase_ :      Union[str, Any]    				=				AutoConfig.for_model(__lowercase   ,						**__lowercase							)
										lowerCAmelCase_ :      List[str]    				=				AutoConfig.for_model(__lowercase   ,						**__lowercase							)
										lowerCAmelCase_ :      Any    				=				True




						@classmethod
						def 						lowercase_ (				cls   ,						__lowercase   ,						__lowercase   ,						**__lowercase							)					->    PretrainedConfig:
										logger.info('''Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config'''							)
										lowerCAmelCase_ :      int    				=				True
										lowerCAmelCase_ :      List[Any]    				=				True

										return cls(encoder=encoder_config.to_dict()   ,						decoder=decoder_config.to_dict()   ,						**__lowercase							)




						def 						lowercase_ (				self							)					->    Any:
										lowerCAmelCase_ :      Optional[Any]    				=				copy.deepcopy(self.__dict__							)
										lowerCAmelCase_ :      List[str]    				=				self.encoder.to_dict()
										lowerCAmelCase_ :      Dict    				=				self.decoder.to_dict()
										lowerCAmelCase_ :      Optional[Any]    				=				self.__class__.model_type
										return output