



"""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,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


A:   Any								=		logging.get_logger(__name__)


if is_vision_available():
      import PIL



class       SCREAMING_SNAKE_CASE__  (					UpperCAmelCase__ ):
   __lowerCAmelCase  :   str						=						['pixel_values']

   def __init__(   self      ,     _SCREAMING_SNAKE_CASE = True      ,     _SCREAMING_SNAKE_CASE = None      ,     _SCREAMING_SNAKE_CASE = PILImageResampling.BICUBIC      ,     _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 = True      ,     **_SCREAMING_SNAKE_CASE      ,     )  ->      None:





    '''simple docstring'''




    super().__init__(**_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					int	=	size if size is not None else {"""shortest_edge""": 224}
    UpperCAmelCase	:					Optional[Any]	=	get_size_dict(_SCREAMING_SNAKE_CASE      ,     default_to_square=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					List[Any]	=	crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
    UpperCAmelCase	:					List[str]	=	get_size_dict(_SCREAMING_SNAKE_CASE      ,     default_to_square=_SCREAMING_SNAKE_CASE      ,     param_name="""crop_size"""						)

    UpperCAmelCase	:					Tuple	=	do_resize
    UpperCAmelCase	:					Dict	=	size
    UpperCAmelCase	:					List[Any]	=	resample
    UpperCAmelCase	:					Union[str, Any]	=	do_center_crop
    UpperCAmelCase	:					List[str]	=	crop_size
    UpperCAmelCase	:					List[Any]	=	do_rescale
    UpperCAmelCase	:					int	=	rescale_factor
    UpperCAmelCase	:					Optional[int]	=	do_normalize
    UpperCAmelCase	:					List[str]	=	image_mean if image_mean is not None else OPENAI_CLIP_MEAN
    UpperCAmelCase	:					List[str]	=	image_std if image_std is not None else OPENAI_CLIP_STD
    UpperCAmelCase	:					List[Any]	=	do_convert_rgb

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





    '''simple docstring'''




    UpperCAmelCase	:					int	=	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()}"						)
    UpperCAmelCase	:					int	=	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 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE = None      ,     **_SCREAMING_SNAKE_CASE      ,     )  ->      np.ndarray:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	get_size_dict(_SCREAMING_SNAKE_CASE						)
    if "height" not in size or "width" not in size:
     raise ValueError(F"The `size` parameter must contain the keys (height, width). Got {size.keys()}"						)
    return center_crop(_SCREAMING_SNAKE_CASE      ,     size=(size["""height"""], size["""width"""])      ,     data_format=_SCREAMING_SNAKE_CASE      ,     **_SCREAMING_SNAKE_CASE						)

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





    '''simple docstring'''




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

   def 	SCREAMING_SNAKE_CASE     (   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 	SCREAMING_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 = None      ,     _SCREAMING_SNAKE_CASE = ChannelDimension.FIRST      ,     **_SCREAMING_SNAKE_CASE      ,     )  ->      PIL.Image.Image:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	do_resize if do_resize is not None else self.do_resize
    UpperCAmelCase	:					Tuple	=	size if size is not None else self.size
    UpperCAmelCase	:					Union[str, Any]	=	get_size_dict(_SCREAMING_SNAKE_CASE      ,     param_name="""size"""      ,     default_to_square=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					Union[str, Any]	=	resample if resample is not None else self.resample
    UpperCAmelCase	:					Tuple	=	do_center_crop if do_center_crop is not None else self.do_center_crop
    UpperCAmelCase	:					Union[str, Any]	=	crop_size if crop_size is not None else self.crop_size
    UpperCAmelCase	:					Union[str, Any]	=	get_size_dict(_SCREAMING_SNAKE_CASE      ,     param_name="""crop_size"""      ,     default_to_square=_SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					Optional[Any]	=	do_rescale if do_rescale is not None else self.do_rescale
    UpperCAmelCase	:					Dict	=	rescale_factor if rescale_factor is not None else self.rescale_factor
    UpperCAmelCase	:					str	=	do_normalize if do_normalize is not None else self.do_normalize
    UpperCAmelCase	:					str	=	image_mean if image_mean is not None else self.image_mean
    UpperCAmelCase	:					Optional[Any]	=	image_std if image_std is not None else self.image_std
    UpperCAmelCase	:					Dict	=	do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

    UpperCAmelCase	:					Any	=	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."""						)

    # PIL RGBA images are converted to RGB
    if do_convert_rgb:
     UpperCAmelCase	:					int	=	[convert_to_rgb(_SCREAMING_SNAKE_CASE						) for image in images]

    # All transformations expect numpy arrays.
    UpperCAmelCase	:					Optional[int]	=	[to_numpy_array(_SCREAMING_SNAKE_CASE						) for image in images]

    if do_resize:
     UpperCAmelCase	:					Dict	=	[self.resize(image=_SCREAMING_SNAKE_CASE      ,     size=_SCREAMING_SNAKE_CASE      ,     resample=_SCREAMING_SNAKE_CASE						) for image in images]

    if do_center_crop:
     UpperCAmelCase	:					Tuple	=	[self.center_crop(image=_SCREAMING_SNAKE_CASE      ,     size=_SCREAMING_SNAKE_CASE						) for image in images]

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

    if do_normalize:
     UpperCAmelCase	:					str	=	[self.normalize(image=_SCREAMING_SNAKE_CASE      ,     mean=_SCREAMING_SNAKE_CASE      ,     std=_SCREAMING_SNAKE_CASE						) for image in images]

    UpperCAmelCase	:					Union[str, Any]	=	[to_channel_dimension_format(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						) for image in images]

    UpperCAmelCase	:					Union[str, Any]	=	{"""pixel_values""": images}
    return BatchFeature(data=_SCREAMING_SNAKE_CASE      ,     tensor_type=_SCREAMING_SNAKE_CASE						)







'''simple docstring'''




import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
  from .tokenization_albert import AlbertTokenizer
else:
  __SCREAMING_SNAKE_CASE     :List[Any]       =				None

__SCREAMING_SNAKE_CASE     :Union[str, Any]       =				logging.get_logger(__name__)
__SCREAMING_SNAKE_CASE     :List[str]       =				{'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

__SCREAMING_SNAKE_CASE     :List[Any]       =				{
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    },
    '''tokenizer_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/tokenizer.json''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/tokenizer.json''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/tokenizer.json''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/tokenizer.json''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/tokenizer.json''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/tokenizer.json''',
    },
}

__SCREAMING_SNAKE_CASE     :Optional[Any]       =				{
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

__SCREAMING_SNAKE_CASE     :Optional[int]       =				'''▁'''







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : Optional[int]           =							VOCAB_FILES_NAMES
 _lowerCamelCase  : Any           =							PRETRAINED_VOCAB_FILES_MAP
 _lowerCamelCase  : Tuple           =							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 _lowerCamelCase  : int           =							AlbertTokenizer




 def __init__(					self       :    Optional[Any]	,			snake_case_       :    Optional[Any]=None	,			snake_case_       :    Optional[Any]=None	,			snake_case_       :    Optional[Any]=True	,			snake_case_       :    str=True	,			snake_case_       :    Tuple=False	,			snake_case_       :    List[Any]="[CLS]"	,			snake_case_       :    Union[str, Any]="[SEP]"	,			snake_case_       :    str="<unk>"	,			snake_case_       :    Union[str, Any]="[SEP]"	,			snake_case_       :    List[Any]="<pad>"	,			snake_case_       :    List[str]="[CLS]"	,			snake_case_       :    int="[MASK]"	,			**snake_case_       :    Any	,			):
      # Mask token behave like a normal word, i.e. include the space before it and
      # is included in the raw text, there should be a match in a non-normalized sentence.
      _UpperCAmelCase     							=   (
          AddedToken(snake_case_	,			lstrip=snake_case_	,			rstrip=snake_case_	,			normalized=snake_case_    )
          if isinstance(snake_case_	,			snake_case_    )
          else mask_token
      )

      super().__init__(
          snake_case_	,			tokenizer_file=snake_case_	,			do_lower_case=snake_case_	,			remove_space=snake_case_	,			keep_accents=snake_case_	,			bos_token=snake_case_	,			eos_token=snake_case_	,			unk_token=snake_case_	,			sep_token=snake_case_	,			pad_token=snake_case_	,			cls_token=snake_case_	,			mask_token=snake_case_	,			**snake_case_	,			)

      _UpperCAmelCase     							=   do_lower_case
      _UpperCAmelCase     							=   remove_space
      _UpperCAmelCase     							=   keep_accents
      _UpperCAmelCase     							=   vocab_file
      _UpperCAmelCase     							=   False if not self.vocab_file else True




 def      lowercase	(					self       :    Union[str, Any]	,			snake_case_       :    List[int]	,			snake_case_       :    Optional[List[int]] = None    ):
      _UpperCAmelCase     							=   [self.sep_token_id]
      _UpperCAmelCase     							=   [self.cls_token_id]
      if token_ids_a is None:
           return cls + token_ids_a + sep
      return cls + token_ids_a + sep + token_ids_a + sep




 def      lowercase	(					self       :    Dict	,			snake_case_       :    List[int]	,			snake_case_       :    Optional[List[int]] = None    ):
      _UpperCAmelCase     							=   [self.sep_token_id]
      _UpperCAmelCase     							=   [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      lowercase	(					self       :    Optional[Any]	,			snake_case_       :    str	,			snake_case_       :    Optional[str] = None    ):
      if not self.can_save_slow_tokenizer:
           raise ValueError(
               "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
               "tokenizer."    )

      if not os.path.isdir(snake_case_    ):
           logger.error(f'Vocabulary path ({save_directory}) should be a directory'    )
           return
      _UpperCAmelCase     							=   os.path.join(
          snake_case_	,			(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]    )

      if os.path.abspath(self.vocab_file    ) != os.path.abspath(snake_case_    ):
           copyfile(self.vocab_file	,			snake_case_    )

      return (out_vocab_file,)




