

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


lowercase_			=  logging.get_logger(__name__)

lowercase_			=  {
    "google/realm-cc-news-pretrained-embedder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-embedder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-encoder": (
        "https://huggingface.co/google/realm-cc-news-pretrained-encoder/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-scorer": (
        "https://huggingface.co/google/realm-cc-news-pretrained-scorer/resolve/main/config.json"
    ),
    "google/realm-cc-news-pretrained-openqa": (
        "https://huggingface.co/google/realm-cc-news-pretrained-openqa/aresolve/main/config.json"
    ),
    "google/realm-orqa-nq-openqa": "https://huggingface.co/google/realm-orqa-nq-openqa/resolve/main/config.json",
    "google/realm-orqa-nq-reader": "https://huggingface.co/google/realm-orqa-nq-reader/resolve/main/config.json",
    "google/realm-orqa-wq-openqa": "https://huggingface.co/google/realm-orqa-wq-openqa/resolve/main/config.json",
    "google/realm-orqa-wq-reader": "https://huggingface.co/google/realm-orqa-wq-reader/resolve/main/config.json",
    # See all REALM models at https://huggingface.co/models?filter=realm
}


class 			A						(							_UpperCAmelCase			):







    """simple docstring"""





    lowerCamelCase		     =							'realm'


    def __init__(				self			:	Tuple,lowercase_			:	Dict=3_0_5_2_2,lowercase_			:	Union[str, Any]=7_6_8,lowercase_			:	Any=1_2_8,lowercase_			:	Any=1_2,lowercase_			:	List[Any]=1_2,lowercase_			:	Union[str, Any]=8,lowercase_			:	str=3_0_7_2,lowercase_			:	str="gelu_new",lowercase_			:	List[Any]=0.1,lowercase_			:	Optional[int]=0.1,lowercase_			:	List[str]=5_1_2,lowercase_			:	int=2,lowercase_			:	int=0.02,lowercase_			:	str=1E-12,lowercase_			:	Optional[Any]=2_5_6,lowercase_			:	Optional[Any]=1_0,lowercase_			:	Optional[int]=1E-3,lowercase_			:	Optional[Any]=5,lowercase_			:	int=3_2_0,lowercase_			:	int=1_3_3_5_3_7_1_8,lowercase_			:	Optional[int]=5_0_0_0,lowercase_			:	Dict=1,lowercase_			:	int=0,lowercase_			:	List[Any]=2,**lowercase_			:	List[Any],)->   int:





        '''simple docstring'''







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

        # Common config
        A__   				=       vocab_size
        A__   				=       max_position_embeddings
        A__   				=       hidden_size
        A__   				=       retriever_proj_size
        A__   				=       num_hidden_layers
        A__   				=       num_attention_heads
        A__   				=       num_candidates
        A__   				=       intermediate_size
        A__   				=       hidden_act
        A__   				=       hidden_dropout_prob
        A__   				=       attention_probs_dropout_prob
        A__   				=       initializer_range
        A__   				=       type_vocab_size
        A__   				=       layer_norm_eps

        # Reader config
        A__   				=       span_hidden_size
        A__   				=       max_span_width
        A__   				=       reader_layer_norm_eps
        A__   				=       reader_beam_size
        A__   				=       reader_seq_len

        # Retrieval config
        A__   				=       num_block_records
        A__   				=       searcher_beam_size




import numpy as np

from transformers import Pipeline
def 						_snake_case(   SCREAMING_SNAKE_CASE__      :     int				)							->				int:





    '''simple docstring'''






    A__   				=       np.max(SCREAMING_SNAKE_CASE__   ,      axis=-1   ,      keepdims=SCREAMING_SNAKE_CASE__				)
    A__   				=       np.exp(outputs - maxes				)
    return shifted_exp / shifted_exp.sum(axis=-1   ,      keepdims=SCREAMING_SNAKE_CASE__				)


class 			A						(							_UpperCAmelCase			):







    """simple docstring"""





    def 						snake_case__					(				self			:	Dict,**lowercase_			:	Tuple		)->   Tuple:





        '''simple docstring'''







        A__   				=       {}
        if "second_text" in kwargs:
            A__   				=       kwargs['second_text']
        return preprocess_kwargs, {}, {}


    def 						snake_case__					(				self			:	List[Any],lowercase_			:	int,lowercase_			:	Optional[int]=None		)->   List[str]:





        '''simple docstring'''







        return self.tokenizer(lowercase_,text_pair=lowercase_,return_tensors=self.framework		)


    def 						snake_case__					(				self			:	str,lowercase_			:	Dict		)->   List[str]:





        '''simple docstring'''







        return self.model(**lowercase_		)


    def 						snake_case__					(				self			:	Dict,lowercase_			:	Optional[int]		)->   Dict:





        '''simple docstring'''







        A__   				=       model_outputs.logits[0].numpy()
        A__   				=       softmax(lowercase_		)

        A__   				=       np.argmax(lowercase_		)
        A__   				=       self.model.config.idalabel[best_class]
        A__   				=       probabilities[best_class].item()
        A__   				=       logits.tolist()
        return {"label": label, "score": score, "logits": logits}

