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, is_vision_available, logging


if is_vision_available():
    import PIL


_SCREAMING_SNAKE_CASE										=						logging.get_logger(__name__)



class 				a							(			__lowerCAmelCase       ):







 """simple docstring"""






 lowerCamelCase	:Tuple    			=		['''pixel_values''']



 def __init__(					self		,				lowerCAmelCase_ = True		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = PILImageResampling.BILINEAR		,				lowerCAmelCase_ = True		,				lowerCAmelCase_ = 1 / 2_55		,				lowerCAmelCase_ = True		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				**lowerCAmelCase_		,				)  ->					None:
        super().__init__(**lowerCAmelCase_							)
        _A        =  size if size is not None else {"""shortest_edge""": 3_84}
        _A        =  get_size_dict(lowerCAmelCase_		,				default_to_square=lowerCAmelCase_							)

        _A        =  do_resize
        _A        =  size
        # Default value set here for backwards compatibility where the value in config is None
        _A        =  crop_pct if crop_pct is not None else 2_24 / 2_56
        _A        =  resample
        _A        =  do_rescale
        _A        =  rescale_factor
        _A        =  do_normalize
        _A        =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        _A        =  image_std if image_std is not None else IMAGENET_STANDARD_STD



 def      UpperCAmelCase							(					self		,				lowerCAmelCase_		,				lowerCAmelCase_		,				lowerCAmelCase_		,				lowerCAmelCase_ = PILImageResampling.BICUBIC		,				lowerCAmelCase_ = None		,				**lowerCAmelCase_		,				)  ->					np.ndarray:
        _A        =  get_size_dict(lowerCAmelCase_		,				default_to_square=lowerCAmelCase_							)
        if "shortest_edge" not in size:
               raise ValueError(F'''Size dictionary must contain \'shortest_edge\' key. Got {size.keys()}'''							)
        _A        =  size["""shortest_edge"""]

        if shortest_edge < 3_84:
               # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
               _A        =  int(shortest_edge / crop_pct							)
               _A        =  get_resize_output_image_size(lowerCAmelCase_		,				size=lowerCAmelCase_		,				default_to_square=lowerCAmelCase_							)
               _A        =  resize(image=lowerCAmelCase_		,				size=lowerCAmelCase_		,				resample=lowerCAmelCase_		,				data_format=lowerCAmelCase_		,				**lowerCAmelCase_							)
               # then crop to (shortest_edge, shortest_edge)
               return center_crop(image=lowerCAmelCase_		,				size=(shortest_edge, shortest_edge)		,				data_format=lowerCAmelCase_		,				**lowerCAmelCase_							)
        else:
               # warping (no cropping) when evaluated at 384 or larger
               return resize(
                   lowerCAmelCase_		,				size=(shortest_edge, shortest_edge)		,				resample=lowerCAmelCase_		,				data_format=lowerCAmelCase_		,				**lowerCAmelCase_							)



 def      UpperCAmelCase							(					self		,				lowerCAmelCase_		,				lowerCAmelCase_		,				lowerCAmelCase_ = None		,				**lowerCAmelCase_		,				)  ->					Tuple:
        return rescale(lowerCAmelCase_		,				scale=lowerCAmelCase_		,				data_format=lowerCAmelCase_		,				**lowerCAmelCase_							)



 def      UpperCAmelCase							(					self		,				lowerCAmelCase_		,				lowerCAmelCase_		,				lowerCAmelCase_		,				lowerCAmelCase_ = None		,				**lowerCAmelCase_		,				)  ->					np.ndarray:
        return normalize(lowerCAmelCase_		,				mean=lowerCAmelCase_		,				std=lowerCAmelCase_		,				data_format=lowerCAmelCase_		,				**lowerCAmelCase_							)



 def      UpperCAmelCase							(					self		,				lowerCAmelCase_		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = None		,				lowerCAmelCase_ = ChannelDimension.FIRST		,				**lowerCAmelCase_		,				)  ->					PIL.Image.Image:
        _A        =  do_resize if do_resize is not None else self.do_resize
        _A        =  crop_pct if crop_pct is not None else self.crop_pct
        _A        =  resample if resample is not None else self.resample
        _A        =  do_rescale if do_rescale is not None else self.do_rescale
        _A        =  rescale_factor if rescale_factor is not None else self.rescale_factor
        _A        =  do_normalize if do_normalize is not None else self.do_normalize
        _A        =  image_mean if image_mean is not None else self.image_mean
        _A        =  image_std if image_std is not None else self.image_std

        _A        =  size if size is not None else self.size
        _A        =  get_size_dict(lowerCAmelCase_		,				default_to_square=lowerCAmelCase_							)

        _A        =  make_list_of_images(lowerCAmelCase_							)

        if not valid_images(lowerCAmelCase_							):
               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 or resample is None:
               raise ValueError("""Size and resample must be specified if do_resize is True."""							)

        if do_resize and size["shortest_edge"] < 3_84 and crop_pct is None:
               raise ValueError("""crop_pct must be specified if size < 384."""							)

        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.
        _A        =  [to_numpy_array(lowerCAmelCase_							) for image in images]

        if do_resize:
               _A        =  [self.resize(image=lowerCAmelCase_		,				size=lowerCAmelCase_		,				crop_pct=lowerCAmelCase_		,				resample=lowerCAmelCase_							) for image in images]

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

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

        _A        =  [to_channel_dimension_format(lowerCAmelCase_		,				lowerCAmelCase_							) for image in images]

        _A        =  {"""pixel_values""": images}
        return BatchFeature(data=lowerCAmelCase_		,				tensor_type=lowerCAmelCase_							)





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										=						logging.get_logger(__name__)

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

_SCREAMING_SNAKE_CASE										=						{
    '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										=						{
    'bert-base-uncased': 512,
    'bert-large-uncased': 512,
    'bert-base-cased': 512,
    'bert-large-cased': 512,
    'bert-base-multilingual-uncased': 512,
    'bert-base-multilingual-cased': 512,
    'bert-base-chinese': 512,
    'bert-base-german-cased': 512,
    'bert-large-uncased-whole-word-masking': 512,
    'bert-large-cased-whole-word-masking': 512,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 512,
    'bert-large-cased-whole-word-masking-finetuned-squad': 512,
    'bert-base-cased-finetuned-mrpc': 512,
    'bert-base-german-dbmdz-cased': 512,
    'bert-base-german-dbmdz-uncased': 512,
    'TurkuNLP/bert-base-finnish-cased-v1': 512,
    'TurkuNLP/bert-base-finnish-uncased-v1': 512,
    'wietsedv/bert-base-dutch-cased': 512,
}

_SCREAMING_SNAKE_CASE										=						{
    '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							(			__lowerCAmelCase       ):







 """simple docstring"""






 lowerCamelCase	:Tuple    			=		VOCAB_FILES_NAMES
 lowerCamelCase	:Union[str, Any]    			=		PRETRAINED_VOCAB_FILES_MAP
 lowerCamelCase	:Dict    			=		PRETRAINED_INIT_CONFIGURATION
 lowerCamelCase	:Optional[Any]    			=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowerCamelCase	:Optional[Any]    			=		BertTokenizer



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

        _A        =  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
        ):
               _A        =  getattr(lowerCAmelCase_		,				normalizer_state.pop("""type"""							)							)
               _A        =  do_lower_case
               _A        =  strip_accents
               _A        =  tokenize_chinese_chars
               _A        =  normalizer_class(**lowerCAmelCase_							)

        _A        =  do_lower_case



 def      UpperCAmelCase							(					self		,				lowerCAmelCase_		,				lowerCAmelCase_=None							)  ->					List[str]:
        _A        =  [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		,				lowerCAmelCase_		,				lowerCAmelCase_ = None							)  ->					List[int]:
        _A        =  [self.sep_token_id]
        _A        =  [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		,				lowerCAmelCase_		,				lowerCAmelCase_ = None							)  ->					Tuple[str]:
        _A        =  self._tokenizer.model.save(lowerCAmelCase_		,				name=lowerCAmelCase_							)
        return tuple(lowerCAmelCase_							)




