





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ....tokenization_utils_fast import PreTrainedTokenizerFast
from ....utils import logging
from .tokenization_retribert import RetriBertTokenizer


_a 						=      logging.get_logger(__name__)

_a 						=      {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

_a 						=      {
    "vocab_file": {
        "yjernite/retribert-base-uncased": (
            "https://huggingface.co/yjernite/retribert-base-uncased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "yjernite/retribert-base-uncased": (
            "https://huggingface.co/yjernite/retribert-base-uncased/resolve/main/tokenizer.json"
        ),
    },
}

_a 						=      {
    "yjernite/retribert-base-uncased": 512,
}


_a 						=      {
    "yjernite/retribert-base-uncased": {"do_lower_case": True},
}






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			lowerCAmelCase_							     =						VOCAB_FILES_NAMES
			lowerCAmelCase_							     =						PRETRAINED_VOCAB_FILES_MAP
			lowerCAmelCase_							     =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			lowerCAmelCase_							     =						PRETRAINED_INIT_CONFIGURATION
			lowerCAmelCase_							     =						RetriBertTokenizer
			lowerCAmelCase_							     =						["""input_ids""", """attention_mask"""]





			def __init__(    self       ,  __lowerCAmelCase=None       ,  __lowerCAmelCase=None       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase="[UNK]"       ,  __lowerCAmelCase="[SEP]"       ,  __lowerCAmelCase="[PAD]"       ,  __lowerCAmelCase="[CLS]"       ,  __lowerCAmelCase="[MASK]"       ,  __lowerCAmelCase=True       ,  __lowerCAmelCase=None       ,  **__lowerCAmelCase       ,  ):



				'''simple docstring'''







				super().__init__(
				    __lowerCAmelCase       ,  tokenizer_file=__lowerCAmelCase       ,  do_lower_case=__lowerCAmelCase       ,  unk_token=__lowerCAmelCase       ,  sep_token=__lowerCAmelCase       ,  pad_token=__lowerCAmelCase       ,  cls_token=__lowerCAmelCase       ,  mask_token=__lowerCAmelCase       ,  tokenize_chinese_chars=__lowerCAmelCase       ,  strip_accents=__lowerCAmelCase       ,  **__lowerCAmelCase       ,  )

				lowerCamelCase__								=		json.loads(self.backend_tokenizer.normalizer.__getstate__()							)
				if (
				    normalizer_state.get('''lowercase'''       ,  __lowerCAmelCase							) != do_lower_case
				    or normalizer_state.get('''strip_accents'''       ,  __lowerCAmelCase							) != strip_accents
				    or normalizer_state.get('''handle_chinese_chars'''       ,  __lowerCAmelCase							) != tokenize_chinese_chars
				):
					lowerCamelCase__								=		getattr(__lowerCAmelCase       ,  normalizer_state.pop('''type'''							)							)
					lowerCamelCase__								=		do_lower_case
					lowerCamelCase__								=		strip_accents
					lowerCamelCase__								=		tokenize_chinese_chars
					lowerCamelCase__								=		normalizer_class(**__lowerCAmelCase							)

				lowerCamelCase__								=		do_lower_case





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase=None							):



				'''simple docstring'''







				lowerCamelCase__								=		[self.cls_token_id] + token_ids_a + [self.sep_token_id]

				if token_ids_a:
					output += token_ids_a + [self.sep_token_id]

				return output





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase = None							):



				'''simple docstring'''







				lowerCamelCase__								=		[self.sep_token_id]
				lowerCamelCase__								=		[self.cls_token_id]
				if token_ids_a is None:
					return len(cls + token_ids_a + sep							) * [0]
				return len(cls + token_ids_a + sep							) * [0] + len(token_ids_a + sep							) * [1]





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase = None							):



				'''simple docstring'''







				lowerCamelCase__								=		self._tokenizer.model.save(__lowerCAmelCase       ,  name=__lowerCAmelCase							)
				return tuple(__lowerCAmelCase							)










import numpy as np

from transformers import Pipeline





def lowerCAmelCase__(__snake_case							)				->      Tuple:







	'''simple docstring'''







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






class 					__A    (    lowerCAmelCase ):

			'''simple docstring'''







			def 		__lowerCamelCase				(    self       ,  **__lowerCAmelCase							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase       ,  __lowerCAmelCase=None							):



				'''simple docstring'''







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





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				return self.model(**__lowerCAmelCase							)





			def 		__lowerCamelCase				(    self       ,  __lowerCAmelCase							):



				'''simple docstring'''







				lowerCamelCase__								=		model_outputs.logits[0].numpy()
				lowerCamelCase__								=		softmax(__lowerCAmelCase							)

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



