


"""simple docstring"""







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


__lowercase    					=      logging.get_logger(__name__)






class 						_A  (  _a  ):







    """simple docstring"""




    UpperCAmelCase       :							Tuple	=       ["""pixel_values"""]






    def __init__(					self				:    Optional[Any]				, __UpperCAmelCase				:    bool = True				, __UpperCAmelCase				:    Optional[Dict[str, int]] = None				, __UpperCAmelCase				:    PILImageResampling = PILImageResampling.BILINEAR				, __UpperCAmelCase				:    bool = True				, __UpperCAmelCase				:    Dict[str, int] = None				, __UpperCAmelCase				:    bool = True				, __UpperCAmelCase				:    Union[int, float] = 1 / 255				, __UpperCAmelCase				:    bool = True				, __UpperCAmelCase				:    Optional[Union[float, List[float]]] = None				, __UpperCAmelCase				:    Optional[Union[float, List[float]]] = None				, **__UpperCAmelCase				:    Union[str, Any]				, ):
      super().__init__(**__UpperCAmelCase)
      a						:		Any      							=			size if size is not None else {"shortest_edge": 256}
      a						:		Union[str, Any]      							=			get_size_dict(__UpperCAmelCase				, default_to_square=__UpperCAmelCase)
      a						:		List[Any]      							=			crop_size if crop_size is not None else {"height": 224, "width": 224}
      a						:		Dict      							=			get_size_dict(__UpperCAmelCase)
      a						:		List[Any]      							=			do_resize
      a						:		Dict      							=			size
      a						:		str      							=			resample
      a						:		Tuple      							=			do_center_crop
      a						:		int      							=			crop_size
      a						:		Dict      							=			do_rescale
      a						:		List[str]      							=			rescale_factor
      a						:		Optional[Any]      							=			do_normalize
      a						:		List[Any]      							=			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      a						:		int      							=			image_std if image_std is not None else IMAGENET_STANDARD_STD






    def 	__snake_case							(					self				:    Dict				, __UpperCAmelCase				:    np.ndarray				, __UpperCAmelCase				:    Dict[str, int]				, __UpperCAmelCase				:    PILImageResampling = PILImageResampling.BICUBIC				, __UpperCAmelCase				:    Optional[Union[str, ChannelDimension]] = None				, **__UpperCAmelCase				:    List[str]				, ):
      a						:		Optional[int]      							=			get_size_dict(__UpperCAmelCase				, default_to_square=__UpperCAmelCase)
      if "shortest_edge" not in size:
        raise ValueError(f'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}''')
      a						:		int      							=			get_resize_output_image_size(__UpperCAmelCase				, size=size["shortest_edge"]				, default_to_square=__UpperCAmelCase)
      return resize(__UpperCAmelCase				, size=__UpperCAmelCase				, resample=__UpperCAmelCase				, data_format=__UpperCAmelCase				, **__UpperCAmelCase)






    def 	__snake_case							(					self				:    Dict				, __UpperCAmelCase				:    np.ndarray				, __UpperCAmelCase				:    Dict[str, int]				, __UpperCAmelCase				:    Optional[Union[str, ChannelDimension]] = None				, **__UpperCAmelCase				:    Union[str, Any]				, ):
      a						:		Dict      							=			get_size_dict(__UpperCAmelCase)
      return center_crop(__UpperCAmelCase				, size=(size["height"], size["width"])				, data_format=__UpperCAmelCase				, **__UpperCAmelCase)






    def 	__snake_case							(					self				:    Union[str, Any]				, __UpperCAmelCase				:    np.ndarray				, __UpperCAmelCase				:    float				, __UpperCAmelCase				:    Optional[Union[str, ChannelDimension]] = None				, **__UpperCAmelCase				:    List[str]):
      return rescale(__UpperCAmelCase				, scale=__UpperCAmelCase				, data_format=__UpperCAmelCase				, **__UpperCAmelCase)






    def 	__snake_case							(					self				:    Any				, __UpperCAmelCase				:    np.ndarray				, __UpperCAmelCase				:    Union[float, List[float]]				, __UpperCAmelCase				:    Union[float, List[float]]				, __UpperCAmelCase				:    Optional[Union[str, ChannelDimension]] = None				, **__UpperCAmelCase				:    Optional[Any]				, ):
      return normalize(__UpperCAmelCase				, mean=__UpperCAmelCase				, std=__UpperCAmelCase				, data_format=__UpperCAmelCase				, **__UpperCAmelCase)






    def 	__snake_case							(					self				:    List[Any]				, __UpperCAmelCase				:    ImageInput				, __UpperCAmelCase				:    Optional[bool] = None				, __UpperCAmelCase				:    Dict[str, int] = None				, __UpperCAmelCase				:    PILImageResampling = None				, __UpperCAmelCase				:    bool = None				, __UpperCAmelCase				:    Dict[str, int] = None				, __UpperCAmelCase				:    Optional[bool] = None				, __UpperCAmelCase				:    Optional[float] = None				, __UpperCAmelCase				:    Optional[bool] = None				, __UpperCAmelCase				:    Optional[Union[float, List[float]]] = None				, __UpperCAmelCase				:    Optional[Union[float, List[float]]] = None				, __UpperCAmelCase				:    Optional[Union[str, TensorType]] = None				, __UpperCAmelCase				:    Union[str, ChannelDimension] = ChannelDimension.FIRST				, **__UpperCAmelCase				:    List[str]				, ):
      a						:		Union[str, Any]      							=			do_resize if do_resize is not None else self.do_resize
      a						:		Any      							=			size if size is not None else self.size
      a						:		Dict      							=			get_size_dict(__UpperCAmelCase				, default_to_square=__UpperCAmelCase)
      a						:		List[Any]      							=			resample if resample is not None else self.resample
      a						:		int      							=			do_center_crop if do_center_crop is not None else self.do_center_crop
      a						:		Union[str, Any]      							=			crop_size if crop_size is not None else self.crop_size
      a						:		Optional[Any]      							=			get_size_dict(__UpperCAmelCase)
      a						:		Tuple      							=			do_rescale if do_rescale is not None else self.do_rescale
      a						:		Optional[Any]      							=			rescale_factor if rescale_factor is not None else self.rescale_factor
      a						:		Optional[int]      							=			do_normalize if do_normalize is not None else self.do_normalize
      a						:		Any      							=			image_mean if image_mean is not None else self.image_mean
      a						:		Optional[int]      							=			image_std if image_std is not None else self.image_std

      a						:		Tuple      							=			make_list_of_images(__UpperCAmelCase)

      if not valid_images(__UpperCAmelCase):
        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.
      a						:		int      							=			[to_numpy_array(__UpperCAmelCase) for image in images]

      if do_resize:
        a						:		Optional[int]      							=			[self.resize(image=__UpperCAmelCase				, size=__UpperCAmelCase				, resample=__UpperCAmelCase) for image in images]

      if do_center_crop:
        a						:		List[Any]      							=			[self.center_crop(image=__UpperCAmelCase				, size=__UpperCAmelCase) for image in images]

      if do_rescale:
        a						:		List[Any]      							=			[self.rescale(image=__UpperCAmelCase				, scale=__UpperCAmelCase) for image in images]

      if do_normalize:
        a						:		Union[str, Any]      							=			[self.normalize(image=__UpperCAmelCase				, mean=__UpperCAmelCase				, std=__UpperCAmelCase) for image in images]

      a						:		Any      							=			[to_channel_dimension_format(__UpperCAmelCase				, __UpperCAmelCase) for image in images]

      a						:		List[Any]      							=			{"pixel_values": images}
      return BatchFeature(data=__UpperCAmelCase				, tensor_type=__UpperCAmelCase)














import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_electra import ElectraTokenizer


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

UpperCAmelCase__				   =		{
    "vocab_file": {
        "google/electra-small-generator": (
            "https://huggingface.co/google/electra-small-generator/resolve/main/vocab.txt"
        ),
        "google/electra-base-generator": "https://huggingface.co/google/electra-base-generator/resolve/main/vocab.txt",
        "google/electra-large-generator": (
            "https://huggingface.co/google/electra-large-generator/resolve/main/vocab.txt"
        ),
        "google/electra-small-discriminator": (
            "https://huggingface.co/google/electra-small-discriminator/resolve/main/vocab.txt"
        ),
        "google/electra-base-discriminator": (
            "https://huggingface.co/google/electra-base-discriminator/resolve/main/vocab.txt"
        ),
        "google/electra-large-discriminator": (
            "https://huggingface.co/google/electra-large-discriminator/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "google/electra-small-generator": (
            "https://huggingface.co/google/electra-small-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-base-generator": (
            "https://huggingface.co/google/electra-base-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-large-generator": (
            "https://huggingface.co/google/electra-large-generator/resolve/main/tokenizer.json"
        ),
        "google/electra-small-discriminator": (
            "https://huggingface.co/google/electra-small-discriminator/resolve/main/tokenizer.json"
        ),
        "google/electra-base-discriminator": (
            "https://huggingface.co/google/electra-base-discriminator/resolve/main/tokenizer.json"
        ),
        "google/electra-large-discriminator": (
            "https://huggingface.co/google/electra-large-discriminator/resolve/main/tokenizer.json"
        ),
    },
}

UpperCAmelCase__				   =		{
    "google/electra-small-generator": 512,
    "google/electra-base-generator": 512,
    "google/electra-large-generator": 512,
    "google/electra-small-discriminator": 512,
    "google/electra-base-discriminator": 512,
    "google/electra-large-discriminator": 512,
}

UpperCAmelCase__				   =		{
    "google/electra-small-generator": {"do_lower_case": True},
    "google/electra-base-generator": {"do_lower_case": True},
    "google/electra-large-generator": {"do_lower_case": True},
    "google/electra-small-discriminator": {"do_lower_case": True},
    "google/electra-base-discriminator": {"do_lower_case": True},
    "google/electra-large-discriminator": {"do_lower_case": True},
}






class 		lowercase_					(	lowercase   ):






      '''simple docstring'''




      __snake_case       =  VOCAB_FILES_NAMES
      __snake_case       =  PRETRAINED_VOCAB_FILES_MAP
      __snake_case       =  PRETRAINED_INIT_CONFIGURATION
      __snake_case       =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      __snake_case       =  ElectraTokenizer







      def __init__(      self      :						Dict ,					__UpperCAmelCase      :						int=None ,					__UpperCAmelCase      :						str=None ,					__UpperCAmelCase      :						Optional[int]=True ,					__UpperCAmelCase      :						str="[UNK]" ,					__UpperCAmelCase      :						Any="[SEP]" ,					__UpperCAmelCase      :						str="[PAD]" ,					__UpperCAmelCase      :						Optional[Any]="[CLS]" ,					__UpperCAmelCase      :						Union[str, Any]="[MASK]" ,					__UpperCAmelCase      :						List[str]=True ,					__UpperCAmelCase      :						Tuple=None ,					**__UpperCAmelCase      :						Optional[int] ,					)    ->str:




       """simple docstring"""


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

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

       a		  =      do_lower_case







      def       __lowerCAmelCase					(      self      :						List[Any] ,					__UpperCAmelCase      :						Optional[int] ,					__UpperCAmelCase      :						Tuple=None  )    ->str:




       """simple docstring"""


       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       __lowerCAmelCase					(      self      :						Optional[Any] ,					__UpperCAmelCase      :						List[int] ,					__UpperCAmelCase      :						Optional[List[int]] = None  )    ->List[int]:




       """simple docstring"""


       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       __lowerCAmelCase					(      self      :						List[str] ,					__UpperCAmelCase      :						str ,					__UpperCAmelCase      :						Optional[str] = None  )    ->Tuple[str]:




       """simple docstring"""


       a		  =      self._tokenizer.model.save(__UpperCAmelCase ,					name=__UpperCAmelCase  )
       return tuple(__UpperCAmelCase  )


