




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


SCREAMING_SNAKE_CASE__     :     Optional[int]		    =       logging.get_logger(__name__)



class       a_       (     SCREAMING_SNAKE_CASE__     ):
	A    							= ['''pixel_values''']





	def __init__(							self      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = PILImageResampling.BILINEAR      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = 1 / 255      ,     SCREAMING_SNAKE_CASE = True      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					None:




				"""simple docstring"""



				super().__init__(**SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						size if size is not None else {'shortest_edge': 256}
				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      ,     default_to_square=SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						crop_size if crop_size is not None else {'height': 224, 'width': 224}
				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						do_resize
				SCREAMING_SNAKE_CASE_								=						size
				SCREAMING_SNAKE_CASE_								=						resample
				SCREAMING_SNAKE_CASE_								=						do_center_crop
				SCREAMING_SNAKE_CASE_								=						crop_size
				SCREAMING_SNAKE_CASE_								=						do_rescale
				SCREAMING_SNAKE_CASE_								=						rescale_factor
				SCREAMING_SNAKE_CASE_								=						do_normalize
				SCREAMING_SNAKE_CASE_								=						image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
				SCREAMING_SNAKE_CASE_								=						image_std if image_std is not None else IMAGENET_STANDARD_STD





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = PILImageResampling.BICUBIC      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					np.ndarray:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      ,     default_to_square=SCREAMING_SNAKE_CASE      )
				if "shortest_edge" not in size:
							raise ValueError(f'The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'      )
				SCREAMING_SNAKE_CASE_								=						get_resize_output_image_size(SCREAMING_SNAKE_CASE      ,     size=size['shortest_edge']      ,     default_to_square=SCREAMING_SNAKE_CASE      )
				return resize(SCREAMING_SNAKE_CASE      ,     size=SCREAMING_SNAKE_CASE      ,     resample=SCREAMING_SNAKE_CASE      ,     data_format=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					np.ndarray:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      )
				return center_crop(SCREAMING_SNAKE_CASE      ,     size=(size['height'], size['width'])      ,     data_format=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      )  ->					np.ndarray:




				"""simple docstring"""



				return rescale(SCREAMING_SNAKE_CASE      ,     scale=SCREAMING_SNAKE_CASE      ,     data_format=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					np.ndarray:




				"""simple docstring"""



				return normalize(SCREAMING_SNAKE_CASE      ,     mean=SCREAMING_SNAKE_CASE      ,     std=SCREAMING_SNAKE_CASE      ,     data_format=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      )





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = None      ,     SCREAMING_SNAKE_CASE = ChannelDimension.FIRST      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					Tuple:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						do_resize if do_resize is not None else self.do_resize
				SCREAMING_SNAKE_CASE_								=						size if size is not None else self.size
				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      ,     default_to_square=SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						resample if resample is not None else self.resample
				SCREAMING_SNAKE_CASE_								=						do_center_crop if do_center_crop is not None else self.do_center_crop
				SCREAMING_SNAKE_CASE_								=						crop_size if crop_size is not None else self.crop_size
				SCREAMING_SNAKE_CASE_								=						get_size_dict(SCREAMING_SNAKE_CASE      )
				SCREAMING_SNAKE_CASE_								=						do_rescale if do_rescale is not None else self.do_rescale
				SCREAMING_SNAKE_CASE_								=						rescale_factor if rescale_factor is not None else self.rescale_factor
				SCREAMING_SNAKE_CASE_								=						do_normalize if do_normalize is not None else self.do_normalize
				SCREAMING_SNAKE_CASE_								=						image_mean if image_mean is not None else self.image_mean
				SCREAMING_SNAKE_CASE_								=						image_std if image_std is not None else self.image_std

				SCREAMING_SNAKE_CASE_								=						make_list_of_images(SCREAMING_SNAKE_CASE      )

				if not valid_images(SCREAMING_SNAKE_CASE      ):
							raise ValueError(
							    'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
							    'torch.Tensor, tf.Tensor or jax.ndarray.'      )

				if do_resize and size is None:
							raise ValueError('Size must be specified if do_resize is True.'      )

				if do_center_crop and crop_size is None:
							raise ValueError('Crop size must be specified if do_center_crop is True.'      )

				if do_rescale and rescale_factor is None:
							raise ValueError('Rescale factor must be specified if do_rescale is True.'      )

				if do_normalize and (image_mean is None or image_std is None):
							raise ValueError('Image mean and std must be specified if do_normalize is True.'      )

				# All transformations expect numpy arrays.
				SCREAMING_SNAKE_CASE_								=						[to_numpy_array(SCREAMING_SNAKE_CASE      ) for image in images]

				if do_resize:
							SCREAMING_SNAKE_CASE_								=						[self.resize(image=SCREAMING_SNAKE_CASE      ,     size=SCREAMING_SNAKE_CASE      ,     resample=SCREAMING_SNAKE_CASE      ) for image in images]

				if do_center_crop:
							SCREAMING_SNAKE_CASE_								=						[self.center_crop(image=SCREAMING_SNAKE_CASE      ,     size=SCREAMING_SNAKE_CASE      ) for image in images]

				if do_rescale:
							SCREAMING_SNAKE_CASE_								=						[self.rescale(image=SCREAMING_SNAKE_CASE      ,     scale=SCREAMING_SNAKE_CASE      ) for image in images]

				if do_normalize:
							SCREAMING_SNAKE_CASE_								=						[self.normalize(image=SCREAMING_SNAKE_CASE      ,     mean=SCREAMING_SNAKE_CASE      ,     std=SCREAMING_SNAKE_CASE      ) for image in images]

				SCREAMING_SNAKE_CASE_								=						[to_channel_dimension_format(SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE      ) for image in images]

				SCREAMING_SNAKE_CASE_								=						{'pixel_values': images}
				return BatchFeature(data=SCREAMING_SNAKE_CASE      ,     tensor_type=SCREAMING_SNAKE_CASE      )






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


SCREAMING_SNAKE_CASE__     :     Dict		    =       logging.get_logger(__name__)

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

SCREAMING_SNAKE_CASE__     :     Dict		    =       {
    "vocab_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/vocab.txt",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/vocab.txt",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"
        ),
        "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt",
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"
        ),
        "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt",
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"
        ),
        "bert-base-multilingual-cased": (
            "https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-cased": (
            "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"
        ),
    },
}

SCREAMING_SNAKE_CASE__     :     List[Any]		    =       {
    "bert-base-uncased": 5_12,
    "bert-large-uncased": 5_12,
    "bert-base-cased": 5_12,
    "bert-large-cased": 5_12,
    "bert-base-multilingual-uncased": 5_12,
    "bert-base-multilingual-cased": 5_12,
    "bert-base-chinese": 5_12,
    "bert-base-german-cased": 5_12,
    "bert-large-uncased-whole-word-masking": 5_12,
    "bert-large-cased-whole-word-masking": 5_12,
    "bert-large-uncased-whole-word-masking-finetuned-squad": 5_12,
    "bert-large-cased-whole-word-masking-finetuned-squad": 5_12,
    "bert-base-cased-finetuned-mrpc": 5_12,
    "bert-base-german-dbmdz-cased": 5_12,
    "bert-base-german-dbmdz-uncased": 5_12,
    "TurkuNLP/bert-base-finnish-cased-v1": 5_12,
    "TurkuNLP/bert-base-finnish-uncased-v1": 5_12,
    "wietsedv/bert-base-dutch-cased": 5_12,
}

SCREAMING_SNAKE_CASE__     :     Union[str, Any]		    =       {
    "bert-base-uncased": {"do_lower_case": True},
    "bert-large-uncased": {"do_lower_case": True},
    "bert-base-cased": {"do_lower_case": False},
    "bert-large-cased": {"do_lower_case": False},
    "bert-base-multilingual-uncased": {"do_lower_case": True},
    "bert-base-multilingual-cased": {"do_lower_case": False},
    "bert-base-chinese": {"do_lower_case": False},
    "bert-base-german-cased": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking-finetuned-squad": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking-finetuned-squad": {"do_lower_case": False},
    "bert-base-cased-finetuned-mrpc": {"do_lower_case": False},
    "bert-base-german-dbmdz-cased": {"do_lower_case": False},
    "bert-base-german-dbmdz-uncased": {"do_lower_case": True},
    "TurkuNLP/bert-base-finnish-cased-v1": {"do_lower_case": False},
    "TurkuNLP/bert-base-finnish-uncased-v1": {"do_lower_case": True},
    "wietsedv/bert-base-dutch-cased": {"do_lower_case": False},
}



class       a_       (     SCREAMING_SNAKE_CASE__     ):
	A    							= VOCAB_FILES_NAMES
	A    							= PRETRAINED_VOCAB_FILES_MAP
	A    							= PRETRAINED_INIT_CONFIGURATION
	A    							= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	A    							= BertTokenizer





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




				"""simple docstring"""



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

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

				SCREAMING_SNAKE_CASE_								=						do_lower_case





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE=None      )  ->					Union[str, Any]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						[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 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      )  ->					List[int]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						[self.sep_token_id]
				SCREAMING_SNAKE_CASE_								=						[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 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      )  ->					Tuple[str]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						self._tokenizer.model.save(SCREAMING_SNAKE_CASE      ,     name=SCREAMING_SNAKE_CASE      )
				return tuple(SCREAMING_SNAKE_CASE      )
