



"""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


UpperCamelCase     =							logging.get_logger(__name__)






class       UpperCamelCase__			(   _lowerCAmelCase      ):

			"""simple docstring"""


			A__	:					int							  =     ["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:
				super().__init__(**SCREAMING_SNAKE_CASE__		)
				A__											=					size if size is not None else {"shortest_edge": 256}
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__						,	default_to_square=SCREAMING_SNAKE_CASE__		)
				A__											=					crop_size if crop_size is not None else {"height": 224, "width": 224}
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__		)
				A__											=					do_resize
				A__											=					size
				A__											=					resample
				A__											=					do_center_crop
				A__											=					crop_size
				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   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = PILImageResampling.BICUBIC						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	np.ndarray:
				A__											=					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()}"""		)
				A__											=					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   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	np.ndarray:
				A__											=					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   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__		)      ->	np.ndarray:
				return rescale(SCREAMING_SNAKE_CASE__						,	scale=SCREAMING_SNAKE_CASE__						,	data_format=SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__		)


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







			def   snake_case__	(      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__						,	)      ->	Optional[int]:
				A__											=					do_resize if do_resize is not None else self.do_resize
				A__											=					size if size is not None else self.size
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__						,	default_to_square=SCREAMING_SNAKE_CASE__		)
				A__											=					resample if resample is not None else self.resample
				A__											=					do_center_crop if do_center_crop is not None else self.do_center_crop
				A__											=					crop_size if crop_size is not None else self.crop_size
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__		)
				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__											=					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.
				A__											=					[to_numpy_array(SCREAMING_SNAKE_CASE__		) for image in images]

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

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

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

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

				A__											=					[to_channel_dimension_format(SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__		) for image in images]

				A__											=					{"pixel_values": images}
				return BatchFeature(data=SCREAMING_SNAKE_CASE__						,	tensor_type=SCREAMING_SNAKE_CASE__		)









"""simple docstring"""







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       UpperCamelCase__			(   _lowerCAmelCase      ):

			"""simple docstring"""


			A__	:					Dict							  =     VOCAB_FILES_NAMES
			A__	:					str							  =     PRETRAINED_VOCAB_FILES_MAP
			A__	:					List[Any]							  =     PRETRAINED_INIT_CONFIGURATION
			A__	:					Any							  =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			A__	:					List[str]							  =     ElectraTokenizer


			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__						,	)      ->	str:
				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__						,	)

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

				A__											=					do_lower_case


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__=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   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = 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   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None		)      ->	Tuple[str]:
				A__											=					self._tokenizer.model.save(SCREAMING_SNAKE_CASE__						,	name=SCREAMING_SNAKE_CASE__		)
				return tuple(SCREAMING_SNAKE_CASE__		)




