





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


lowerCAmelCase_    =				logging.get_logger(__name__)

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

lowerCAmelCase_    =				{
    '''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'''
        ),
    },
}

lowerCAmelCase_    =				{
    '''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,
}


lowerCAmelCase_    =				{
    '''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 					__lowerCAmelCase       (			_a     ):
			lowerCamelCase_     :     Optional[Any]       			=      VOCAB_FILES_NAMES
			lowerCamelCase_     :     Optional[Any]       			=      PRETRAINED_VOCAB_FILES_MAP
			lowerCamelCase_     :     List[str]       			=      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			lowerCamelCase_     :     Optional[int]       			=      PRETRAINED_INIT_CONFIGURATION
			lowerCamelCase_     :     str       			=      ['''input_ids''', '''attention_mask''']
			lowerCamelCase_     :     List[Any]       			=      DistilBertTokenizer






			def __init__(self					,							__magic_name__=None					,							__magic_name__=None					,							__magic_name__=True					,							__magic_name__="[UNK]"					,							__magic_name__="[SEP]"					,							__magic_name__="[PAD]"					,							__magic_name__="[CLS]"					,							__magic_name__="[MASK]"					,							__magic_name__=True					,							__magic_name__=None					,							**__magic_name__					,							)     ->   List[Any]:


							'''simple docstring'''



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

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

							snake_case_						:    str				=  do_lower_case






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__=None    )     ->   Union[str, Any]:


							'''simple docstring'''



							snake_case_						:    Dict				=  [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					,							__magic_name__					,							__magic_name__ = None    )     ->   List[int]:


							'''simple docstring'''



							snake_case_						:    str				=  [self.sep_token_id]
							snake_case_						:    Optional[int]				=  [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					,							__magic_name__					,							__magic_name__ = None    )     ->   Tuple[str]:


							'''simple docstring'''



							snake_case_						:    Optional[int]				=  self._tokenizer.model.save(__magic_name__					,							name=__magic_name__    )
							return tuple(__magic_name__    )







import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse('''9.1.0'''):
	lowerCAmelCase_    =				{
	    '''linear''': PIL.Image.Resampling.BILINEAR,
	    '''bilinear''': PIL.Image.Resampling.BILINEAR,
	    '''bicubic''': PIL.Image.Resampling.BICUBIC,
	    '''lanczos''': PIL.Image.Resampling.LANCZOS,
	    '''nearest''': PIL.Image.Resampling.NEAREST,
	}
else:
	lowerCAmelCase_    =				{
	    '''linear''': PIL.Image.LINEAR,
	    '''bilinear''': PIL.Image.BILINEAR,
	    '''bicubic''': PIL.Image.BICUBIC,
	    '''lanczos''': PIL.Image.LANCZOS,
	    '''nearest''': PIL.Image.NEAREST,
	}






def      lowerCamelCase_						(				_UpperCamelCase )		->						Optional[int]:






				"""simple docstring"""


				snake_case_						:    Dict				=  (images / 2 + 0.5).clamp(0 ,				1 )
				snake_case_						:    Dict				=  images.cpu().permute(0 ,				2 ,				3 ,				1 ).float().numpy()
				snake_case_						:    int				=  numpy_to_pil(_UpperCamelCase )
				return images






def      lowerCamelCase_						(				_UpperCamelCase )		->						List[Any]:






				"""simple docstring"""


				if images.ndim == 3:
								snake_case_						:    Optional[Any]				=  images[None, ...]
				snake_case_						:    Any				=  (images * 255).round().astype('''uint8''' )
				if images.shape[-1] == 1:
								# special case for grayscale (single channel) images
								snake_case_						:    str				=  [Image.fromarray(image.squeeze() ,				mode='''L''' ) for image in images]
				else:
								snake_case_						:    List[Any]				=  [Image.fromarray(_UpperCamelCase ) for image in images]

				return pil_images
