






"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_squeezebert import SqueezeBertTokenizer


UpperCAmelCase_   : str   			= logging.get_logger(__name__)

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

UpperCAmelCase_   : Union[str, Any]   			= {
    """vocab_file""": {
        """squeezebert/squeezebert-uncased""": (
            """https://huggingface.co/squeezebert/squeezebert-uncased/resolve/main/vocab.txt"""
        ),
        """squeezebert/squeezebert-mnli""": """https://huggingface.co/squeezebert/squeezebert-mnli/resolve/main/vocab.txt""",
        """squeezebert/squeezebert-mnli-headless""": (
            """https://huggingface.co/squeezebert/squeezebert-mnli-headless/resolve/main/vocab.txt"""
        ),
    },
    """tokenizer_file""": {
        """squeezebert/squeezebert-uncased""": (
            """https://huggingface.co/squeezebert/squeezebert-uncased/resolve/main/tokenizer.json"""
        ),
        """squeezebert/squeezebert-mnli""": (
            """https://huggingface.co/squeezebert/squeezebert-mnli/resolve/main/tokenizer.json"""
        ),
        """squeezebert/squeezebert-mnli-headless""": (
            """https://huggingface.co/squeezebert/squeezebert-mnli-headless/resolve/main/tokenizer.json"""
        ),
    },
}

UpperCAmelCase_   : Optional[Any]   			= {
    """squeezebert/squeezebert-uncased""": 512,
    """squeezebert/squeezebert-mnli""": 512,
    """squeezebert/squeezebert-mnli-headless""": 512,
}


UpperCAmelCase_   : Any   			= {
    """squeezebert/squeezebert-uncased""": {"""do_lower_case""": True},
    """squeezebert/squeezebert-mnli""": {"""do_lower_case""": True},
    """squeezebert/squeezebert-mnli-headless""": {"""do_lower_case""": True},
}




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  VOCAB_FILES_NAMES
      __UpperCamelCase	 =  PRETRAINED_VOCAB_FILES_MAP
      __UpperCamelCase	 =  PRETRAINED_INIT_CONFIGURATION
      __UpperCamelCase	 =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      __UpperCamelCase	 =  SqueezeBertTokenizer
      def __init__(						self     :  str						,	lowercase_     :  List[Any]=None						,	lowercase_     :  Optional[Any]=None						,	lowercase_     :  Tuple=True						,	lowercase_     :  int="[UNK]"						,	lowercase_     :  List[Any]="[SEP]"						,	lowercase_     :  str="[PAD]"						,	lowercase_     :  List[str]="[CLS]"						,	lowercase_     :  Tuple="[MASK]"						,	lowercase_     :  Optional[int]=True						,	lowercase_     :  Optional[Any]=None						,	**lowercase_     :  Tuple						,	):




          '''simple docstring'''


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

          SCREAMING_SNAKE_CASE_      :  str    						=		json.loads(self.backend_tokenizer.normalizer.__getstate__())
          if (
              normalizer_state.get('''lowercase'''						,	lowercase_) != do_lower_case
              or normalizer_state.get('''strip_accents'''						,	lowercase_) != strip_accents
              or normalizer_state.get('''handle_chinese_chars'''						,	lowercase_) != tokenize_chinese_chars
          ):
              SCREAMING_SNAKE_CASE_      :  Dict    						=		getattr(lowercase_						,	normalizer_state.pop('''type'''))
              SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		do_lower_case
              SCREAMING_SNAKE_CASE_      :  str    						=		strip_accents
              SCREAMING_SNAKE_CASE_      :  List[str]    						=		tokenize_chinese_chars
              SCREAMING_SNAKE_CASE_      :  List[str]    						=		normalizer_class(**lowercase_)

          SCREAMING_SNAKE_CASE_      :  Any    						=		do_lower_case
      def _SCREAMING_SNAKE_CASE (						self     :  Tuple						,	lowercase_     :  Tuple						,	lowercase_     :  str=None):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  str    						=		[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 _SCREAMING_SNAKE_CASE (						self     :  Union[str, Any]						,	lowercase_     :  List[int]						,	lowercase_     :  Optional[List[int]] = None):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Dict    						=		[self.sep_token_id]
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		[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 _SCREAMING_SNAKE_CASE (						self     :  Optional[int]						,	lowercase_     :  str						,	lowercase_     :  Optional[str] = None):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  int    						=		self._tokenizer.model.save(lowercase_						,	name=lowercase_)
          return tuple(lowercase_)









import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Tuple						=			"""M-CLIP"""







      def __init__(    self		,      lowerCAmelCase__=1_0_2_4		,      lowerCAmelCase__=7_6_8		,      **lowerCAmelCase__							)   ->						Any:



        '''simple docstring'''




        a__	:					int										=transformerDimSize
        a__	:					Dict										=imageDimSize
        super().__init__(**lowerCAmelCase__							)







class 				__lowerCAmelCase       (    UpperCamelCase__):
      _lowercase				:					Optional[Any]						=			MCLIPConfig







      def __init__(    self		,      lowerCAmelCase__		,      *lowerCAmelCase__		,      **lowerCAmelCase__							)   ->						List[str]:



        '''simple docstring'''




        super().__init__(lowerCAmelCase__		,      *lowerCAmelCase__		,      **lowerCAmelCase__							)
        a__	:					Tuple										=XLMRobertaModel(lowerCAmelCase__							)
        a__	:					List[str]										=torch.nn.Linear(
            in_features=config.transformerDimensions		,      out_features=config.numDims							)







      def    _lowercase  (    self		,      lowerCAmelCase__		,      lowerCAmelCase__							)   ->						Union[str, Any]:



        '''simple docstring'''




        a__	:					Optional[Any]										=self.transformer(input_ids=lowerCAmelCase__		,      attention_mask=lowerCAmelCase__							)[0]
        a__	:					int										=(embs * attention_mask.unsqueeze(2							)).sum(dim=1							) / attention_mask.sum(dim=1							)[:, None]
        return self.LinearTransformation(lowerCAmelCase__							), embs






