





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


_lowerCAmelCase				:   Union[str, Any]						       =						logging.get_logger(__name__)


class        __magic_name__	(				lowerCamelCase__				):





     """simple docstring"""



     __UpperCamelCase            =  ['pixel_values']



     def __init__(				self							:Tuple      ,   snake_case							:bool = True      ,   snake_case							:Optional[Dict[str, int]] = None      ,   snake_case							:PILImageResampling = PILImageResampling.BILINEAR      ,   snake_case							:bool = True      ,   snake_case							:Dict[str, int] = None      ,   snake_case							:bool = True      ,   snake_case							:Union[int, float] = 1 / 255      ,   snake_case							:bool = True      ,   snake_case							:Optional[Union[float, List[float]]] = None      ,   snake_case							:Optional[Union[float, List[float]]] = None      ,   **snake_case							:Tuple      ,   ):





        '''simple docstring'''




        super().__init__(**SCREAMING_SNAKE_CASE_	)
        A_       :					Union[str, Any]        =      size if size is not None else {"shortest_edge": 256}
        A_       :					Dict        =      get_size_dict(SCREAMING_SNAKE_CASE_      ,   default_to_square=SCREAMING_SNAKE_CASE_	)
        A_       :					Optional[int]        =      crop_size if crop_size is not None else {"height": 224, "width": 224}
        A_       :					Union[str, Any]        =      get_size_dict(SCREAMING_SNAKE_CASE_	)
        A_       :					Optional[int]        =      do_resize
        A_       :					Dict        =      size
        A_       :					int        =      resample
        A_       :					Dict        =      do_center_crop
        A_       :					Optional[Any]        =      crop_size
        A_       :					Union[str, Any]        =      do_rescale
        A_       :					Dict        =      rescale_factor
        A_       :					Tuple        =      do_normalize
        A_       :					int        =      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        A_       :					List[str]        =      image_std if image_std is not None else IMAGENET_STANDARD_STD



     def     SCREAMING_SNAKE_CASE		(				self							:str      ,   snake_case							:np.ndarray      ,   snake_case							:Dict[str, int]      ,   snake_case							:PILImageResampling = PILImageResampling.BICUBIC      ,   snake_case							:Optional[Union[str, ChannelDimension]] = None      ,   **snake_case							:List[str]      ,   ):





        '''simple docstring'''




        A_       :					Optional[Any]        =      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_       :					str        =      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							:int      ,   snake_case							:np.ndarray      ,   snake_case							:Dict[str, int]      ,   snake_case							:Optional[Union[str, ChannelDimension]] = None      ,   **snake_case							:Tuple      ,   ):





        '''simple docstring'''




        A_       :					Optional[int]        =      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     SCREAMING_SNAKE_CASE		(				self							:str      ,   snake_case							:np.ndarray      ,   snake_case							:float      ,   snake_case							:Optional[Union[str, ChannelDimension]] = None      ,   **snake_case							:List[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							:Union[str, Any]      ,   snake_case							:np.ndarray      ,   snake_case							:Union[float, List[float]]      ,   snake_case							:Union[float, List[float]]      ,   snake_case							:Optional[Union[str, ChannelDimension]] = None      ,   **snake_case							:Any      ,   ):





        '''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							:int      ,   snake_case							:ImageInput      ,   snake_case							:Optional[bool] = None      ,   snake_case							:Dict[str, int] = None      ,   snake_case							:PILImageResampling = None      ,   snake_case							:bool = None      ,   snake_case							:Dict[str, int] = None      ,   snake_case							:Optional[bool] = None      ,   snake_case							:Optional[float] = None      ,   snake_case							:Optional[bool] = None      ,   snake_case							:Optional[Union[float, List[float]]] = None      ,   snake_case							:Optional[Union[float, List[float]]] = None      ,   snake_case							:Optional[Union[str, TensorType]] = None      ,   snake_case							:Union[str, ChannelDimension] = ChannelDimension.FIRST      ,   **snake_case							:Optional[int]      ,   ):





        '''simple docstring'''




        A_       :					int        =      do_resize if do_resize is not None else self.do_resize
        A_       :					int        =      size if size is not None else self.size
        A_       :					Dict        =      get_size_dict(SCREAMING_SNAKE_CASE_      ,   default_to_square=SCREAMING_SNAKE_CASE_	)
        A_       :					Any        =      resample if resample is not None else self.resample
        A_       :					List[Any]        =      do_center_crop if do_center_crop is not None else self.do_center_crop
        A_       :					Any        =      crop_size if crop_size is not None else self.crop_size
        A_       :					Optional[int]        =      get_size_dict(SCREAMING_SNAKE_CASE_	)
        A_       :					Optional[Any]        =      do_rescale if do_rescale is not None else self.do_rescale
        A_       :					Dict        =      rescale_factor if rescale_factor is not None else self.rescale_factor
        A_       :					Any        =      do_normalize if do_normalize is not None else self.do_normalize
        A_       :					Optional[Any]        =      image_mean if image_mean is not None else self.image_mean
        A_       :					List[Any]        =      image_std if image_std is not None else self.image_std

        A_       :					Tuple        =      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_       :					Optional[Any]        =      [to_numpy_array(SCREAMING_SNAKE_CASE_	) for image in images]

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

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

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

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

        A_       :					Optional[Any]        =      [to_channel_dimension_format(SCREAMING_SNAKE_CASE_      ,   SCREAMING_SNAKE_CASE_	) for image in images]

        A_       :					Dict        =      {"pixel_values": images}
        return BatchFeature(data=SCREAMING_SNAKE_CASE_      ,   tensor_type=SCREAMING_SNAKE_CASE_	)


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__a         =   logging.get_logger(__name__)

__a         =   {
    'xlm-mlm-en-2048': 'https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json',
    'xlm-mlm-ende-1024': 'https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json',
    'xlm-mlm-enfr-1024': 'https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json',
    'xlm-mlm-enro-1024': 'https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json',
    'xlm-mlm-tlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json',
    'xlm-mlm-xnli15-1024': 'https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json',
    'xlm-clm-enfr-1024': 'https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json',
    'xlm-clm-ende-1024': 'https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json',
    'xlm-mlm-17-1280': 'https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json',
    'xlm-mlm-100-1280': 'https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json',
}
class 					lowercase__(							UpperCAmelCase				):



	"""simple docstring"""




	a     :List[Any]       	=      'xlm'
	a     :Dict       	=      {
	    'hidden_size': 'emb_dim',
	    'num_attention_heads': 'n_heads',
	    'num_hidden_layers': 'n_layers',
	    'n_words': 'vocab_size',  # For backward compatibility
	}
	def __init__(			self    :     List[Any]			,				SCREAMING_SNAKE_CASE_    :     Dict=3_0_1_4_5			,				SCREAMING_SNAKE_CASE_    :     Dict=2_0_4_8			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=1_2			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=1_6			,				SCREAMING_SNAKE_CASE_    :     Dict=0.1			,				SCREAMING_SNAKE_CASE_    :     str=0.1			,				SCREAMING_SNAKE_CASE_    :     Any=True			,				SCREAMING_SNAKE_CASE_    :     Any=False			,				SCREAMING_SNAKE_CASE_    :     str=False			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=False			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=1			,				SCREAMING_SNAKE_CASE_    :     Dict=True			,				SCREAMING_SNAKE_CASE_    :     Dict=5_1_2			,				SCREAMING_SNAKE_CASE_    :     Optional[int]=2_0_4_8**-0.5			,				SCREAMING_SNAKE_CASE_    :     Dict=1e-12			,				SCREAMING_SNAKE_CASE_    :     Any=0.02			,				SCREAMING_SNAKE_CASE_    :     str=0			,				SCREAMING_SNAKE_CASE_    :     List[Any]=1			,				SCREAMING_SNAKE_CASE_    :     List[Any]=2			,				SCREAMING_SNAKE_CASE_    :     int=3			,				SCREAMING_SNAKE_CASE_    :     Dict=5			,				SCREAMING_SNAKE_CASE_    :     int=True			,				SCREAMING_SNAKE_CASE_    :     List[Any]="first"			,				SCREAMING_SNAKE_CASE_    :     Any=True			,				SCREAMING_SNAKE_CASE_    :     List[Any]=None			,				SCREAMING_SNAKE_CASE_    :     str=True			,				SCREAMING_SNAKE_CASE_    :     Union[str, Any]=0.1			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=5			,				SCREAMING_SNAKE_CASE_    :     List[str]=5			,				SCREAMING_SNAKE_CASE_    :     Any=0			,				SCREAMING_SNAKE_CASE_    :     str=0			,				SCREAMING_SNAKE_CASE_    :     Optional[Any]=2			,				SCREAMING_SNAKE_CASE_    :     Tuple=0			,				**SCREAMING_SNAKE_CASE_    :     Dict			,				)			->	List[Any]:
					lowercase_	    =   vocab_size
					lowercase_	    =   emb_dim
					lowercase_	    =   n_layers
					lowercase_	    =   n_heads
					lowercase_	    =   dropout
					lowercase_	    =   attention_dropout
					lowercase_	    =   gelu_activation
					lowercase_	    =   sinusoidal_embeddings
					lowercase_	    =   causal
					lowercase_	    =   asm
					lowercase_	    =   n_langs
					lowercase_	    =   use_lang_emb
					lowercase_	    =   layer_norm_eps
					lowercase_	    =   bos_index
					lowercase_	    =   eos_index
					lowercase_	    =   pad_index
					lowercase_	    =   unk_index
					lowercase_	    =   mask_index
					lowercase_	    =   is_encoder
					lowercase_	    =   max_position_embeddings
					lowercase_	    =   embed_init_std
					lowercase_	    =   init_std
					lowercase_	    =   summary_type
					lowercase_	    =   summary_use_proj
					lowercase_	    =   summary_activation
					lowercase_	    =   summary_proj_to_labels
					lowercase_	    =   summary_first_dropout
					lowercase_	    =   start_n_top
					lowercase_	    =   end_n_top
					lowercase_	    =   mask_token_id
					lowercase_	    =   lang_id

					if "n_words" in kwargs:
									lowercase_	    =   kwargs['''n_words''']

					super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_			,				bos_token_id=SCREAMING_SNAKE_CASE_			,				**SCREAMING_SNAKE_CASE_			)

class 					lowercase__(							UpperCAmelCase				):



	"""simple docstring"""




	@property
	def 		_lowercase    (			self    :     int			)			->	Mapping[str, Mapping[int, str]]:
					if self.task == "multiple-choice":
									lowercase_	    =   {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
					else:
									lowercase_	    =   {0: '''batch''', 1: '''sequence'''}
					return OrderedDict(
					    [
					        ('''input_ids''', dynamic_axis),
					        ('''attention_mask''', dynamic_axis),
					        ('''token_type_ids''', dynamic_axis),
					    ]			)




