



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_distilbert import DistilBertTokenizer


__SCREAMING_SNAKE_CASE						:   List[Any]         =			logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE						:   Any         =			{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE						:   Union[str, Any]         =			{
    'vocab_file': {
        'distilbert-base-uncased': 'https://huggingface.co/distilbert-base-uncased/resolve/main/vocab.txt',
        'distilbert-base-uncased-distilled-squad': (
            'https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/vocab.txt'
        ),
        'distilbert-base-cased': 'https://huggingface.co/distilbert-base-cased/resolve/main/vocab.txt',
        'distilbert-base-cased-distilled-squad': (
            'https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/vocab.txt'
        ),
        'distilbert-base-german-cased': 'https://huggingface.co/distilbert-base-german-cased/resolve/main/vocab.txt',
        'distilbert-base-multilingual-cased': (
            'https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'distilbert-base-uncased': 'https://huggingface.co/distilbert-base-uncased/resolve/main/tokenizer.json',
        'distilbert-base-uncased-distilled-squad': (
            'https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/tokenizer.json'
        ),
        'distilbert-base-cased': 'https://huggingface.co/distilbert-base-cased/resolve/main/tokenizer.json',
        'distilbert-base-cased-distilled-squad': (
            'https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/tokenizer.json'
        ),
        'distilbert-base-german-cased': (
            'https://huggingface.co/distilbert-base-german-cased/resolve/main/tokenizer.json'
        ),
        'distilbert-base-multilingual-cased': (
            'https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
    },
}

__SCREAMING_SNAKE_CASE						:   Optional[int]         =			{
    'distilbert-base-uncased': 5_1_2,
    'distilbert-base-uncased-distilled-squad': 5_1_2,
    'distilbert-base-cased': 5_1_2,
    'distilbert-base-cased-distilled-squad': 5_1_2,
    'distilbert-base-german-cased': 5_1_2,
    'distilbert-base-multilingual-cased': 5_1_2,
}


__SCREAMING_SNAKE_CASE						:   List[Any]         =			{
    'distilbert-base-uncased': {'do_lower_case': True},
    'distilbert-base-uncased-distilled-squad': {'do_lower_case': True},
    'distilbert-base-cased': {'do_lower_case': False},
    'distilbert-base-cased-distilled-squad': {'do_lower_case': False},
    'distilbert-base-german-cased': {'do_lower_case': False},
    'distilbert-base-multilingual-cased': {'do_lower_case': False},
}



class        lowercase_   (					__snake_case		):
							_lowerCamelCase						=		VOCAB_FILES_NAMES
							_lowerCamelCase						=		PRETRAINED_VOCAB_FILES_MAP
							_lowerCamelCase						=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							_lowerCamelCase						=		PRETRAINED_INIT_CONFIGURATION
							_lowerCamelCase						=		['input_ids', 'attention_mask']
							_lowerCamelCase						=		DistilBertTokenizer



							def __init__(						self				,    lowercase_=None				,    lowercase_=None				,    lowercase_=True				,    lowercase_="[UNK]"				,    lowercase_="[SEP]"				,    lowercase_="[PAD]"				,    lowercase_="[CLS]"				,    lowercase_="[MASK]"				,    lowercase_=True				,    lowercase_=None				,    **lowercase_				,    ):
													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_				,    )

													_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
													):
																			_snake_case						:					Tuple    =   getattr(lowercase_				,    normalizer_state.pop("type"    )    )
																			_snake_case						:					List[str]    =   do_lower_case
																			_snake_case						:					Any    =   strip_accents
																			_snake_case						:					Dict    =   tokenize_chinese_chars
																			_snake_case						:					Optional[int]    =   normalizer_class(**lowercase_    )

													_snake_case						:					Tuple    =   do_lower_case



							def 	UpperCamelCase	(						self				,    lowercase_				,    lowercase_=None    ):
													_snake_case						:					Optional[int]    =   [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 	UpperCamelCase	(						self				,    lowercase_				,    lowercase_ = None    ):
													_snake_case						:					Tuple    =   [self.sep_token_id]
													_snake_case						:					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 	UpperCamelCase	(						self				,    lowercase_				,    lowercase_ = None    ):
													_snake_case						:					Dict    =   self._tokenizer.model.save(lowercase_				,    name=lowercase_    )
													return tuple(lowercase_    )
import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel



class        lowercase_   (					__snake_case		):
							_lowerCamelCase						=		'M-CLIP'



							def __init__(						self				,    lowercase_=1_024				,    lowercase_=768				,    **lowercase_    ):
													_snake_case						:					str    =   transformerDimSize
													_snake_case						:					Union[str, Any]    =   imageDimSize
													super().__init__(**lowercase_    )




class        lowercase_   (					__snake_case		):
							_lowerCamelCase						=		MCLIPConfig



							def __init__(						self				,    lowercase_				,    *lowercase_				,    **lowercase_    ):
													super().__init__(lowercase_				,    *lowercase_				,    **lowercase_    )
													_snake_case						:					List[Any]    =   XLMRobertaModel(lowercase_    )
													_snake_case						:					int    =   torch.nn.Linear(
													    in_features=config.transformerDimensions				,    out_features=config.numDims    )



							def 	UpperCamelCase	(						self				,    lowercase_				,    lowercase_    ):
													_snake_case						:					Tuple    =   self.transformer(input_ids=lowercase_				,    attention_mask=lowercase_    )[0]
													_snake_case						:					Tuple    =   (embs * attention_mask.unsqueeze(2    )).sum(dim=1    ) / attention_mask.sum(dim=1    )[:, None]
													return self.LinearTransformation(lowercase_    ), embs