




'''simple docstring'''


from typing import Callable, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case   :   Any     							=	logging.get_logger(__name__)

_snake_case   :   List[str]     							=	{
    'microsoft/xprophetnet-large-wiki100-cased': (
        'https://huggingface.co/microsoft/xprophetnet-large-wiki100-cased/resolve/main/config.json'
    ),
}

class     A					(	_a					):
							lowercase_           =       'xlm-prophetnet'
							lowercase_           =       ['past_key_values']
							lowercase_           =       {
							    'num_attention_heads': 'num_encoder_attention_heads',
							}







							def __init__(						self :						List[str]							,    lowerCAmelCase_ :						Optional[float] = 0.1							,    lowerCAmelCase_ :						Optional[Union[str, Callable]] = "gelu"							,    lowerCAmelCase_ :						Optional[int] = 3_05_22							,    lowerCAmelCase_ :						Optional[int] = 10_24							,    lowerCAmelCase_ :						Optional[int] = 40_96							,    lowerCAmelCase_ :						Optional[int] = 12							,    lowerCAmelCase_ :						Optional[int] = 16							,    lowerCAmelCase_ :						Optional[int] = 40_96							,    lowerCAmelCase_ :						Optional[int] = 12							,    lowerCAmelCase_ :						Optional[int] = 16							,    lowerCAmelCase_ :						Optional[float] = 0.1							,    lowerCAmelCase_ :						Optional[float] = 0.1							,    lowerCAmelCase_ :						Optional[int] = 5_12							,    lowerCAmelCase_ :						Optional[float] = 0.0_2							,    lowerCAmelCase_ :						Optional[bool] = True							,    lowerCAmelCase_ :						Optional[bool] = True							,    lowerCAmelCase_ :						Optional[int] = 0							,    lowerCAmelCase_ :						Optional[int] = 2							,    lowerCAmelCase_ :						Optional[int] = 32							,    lowerCAmelCase_ :						Optional[int] = 1_28							,    lowerCAmelCase_ :						Optional[bool] = False							,    lowerCAmelCase_ :						Optional[float] = 0.0							,    lowerCAmelCase_ :						Optional[bool] = True							,    lowerCAmelCase_ :						Optional[int] = 0							,    lowerCAmelCase_ :						Optional[int] = 1							,    lowerCAmelCase_ :						Optional[int] = 2							,    **lowerCAmelCase_ :						int							,    )    ->							Any:


														"""simple docstring"""


														_a			  =       vocab_size
														_a			  =       hidden_size
														_a			  =       encoder_ffn_dim
														_a			  =       num_encoder_layers
														_a			  =       num_encoder_attention_heads
														_a			  =       decoder_ffn_dim
														_a			  =       num_decoder_layers
														_a			  =       num_decoder_attention_heads
														_a			  =       max_position_embeddings
														_a			  =       init_std  # Normal(0, this parameter)
														_a			  =       activation_function

														# parameters for xlmprophetnet
														_a			  =       ngram
														_a			  =       num_buckets
														_a			  =       relative_max_distance
														_a			  =       disable_ngram_loss
														_a			  =       eps

														# 3 Types of Dropout
														_a			  =       attention_dropout
														_a			  =       activation_dropout
														_a			  =       dropout

														_a			  =       use_cache

														super().__init__(
														    pad_token_id=lowerCAmelCase_							,    bos_token_id=lowerCAmelCase_							,    eos_token_id=lowerCAmelCase_							,    is_encoder_decoder=lowerCAmelCase_							,    add_cross_attention=lowerCAmelCase_							,    decoder_start_token_id=lowerCAmelCase_							,    **lowerCAmelCase_							,    )







							@property
							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							int:


														"""simple docstring"""


														return self.num_encoder_layers + self.num_decoder_layers







							@num_hidden_layers.setter
							def      __lowerCAmelCase    (						self :						int							,    lowerCAmelCase_ :						Any      )    ->							Union[str, Any]:


														"""simple docstring"""


														raise NotImplementedError(
														    '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
														    ''' `num_decoder_layers`.'''      )







'''simple docstring'''


from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
				import PIL

_snake_case   :   str     							=	logging.get_logger(__name__)
def 	snake_case_					(UpperCamelCase :						Optional[int]   ):





							'''simple docstring'''


							if isinstance(UpperCamelCase				,		(list, tuple)   ) and isinstance(videos[0]				,		(list, tuple)   ) and is_valid_image(videos[0][0]   ):
														return videos

							elif isinstance(UpperCamelCase				,		(list, tuple)   ) and is_valid_image(videos[0]   ):
														return [videos]

							elif is_valid_image(UpperCamelCase   ):
														return [[videos]]

							raise ValueError(f'Could not make batched video from {videos}'   )

class     A					(	_a					):
							lowercase_           =       ['pixel_values']







							def __init__(						self :						List[Any]							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						PILImageResampling = PILImageResampling.BILINEAR							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Union[int, float] = 1 / 2_55							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    **lowerCAmelCase_ :						List[str]							,    )    ->							None:


														"""simple docstring"""


														super().__init__(**lowerCAmelCase_      )
														_a			  =       size if size is not None else {'''shortest_edge''': 2_56}
														_a			  =       get_size_dict(lowerCAmelCase_							,    default_to_square=lowerCAmelCase_      )
														_a			  =       crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
														_a			  =       get_size_dict(lowerCAmelCase_							,    param_name='''crop_size'''      )

														_a			  =       do_resize
														_a			  =       size
														_a			  =       do_center_crop
														_a			  =       crop_size
														_a			  =       resample
														_a			  =       do_rescale
														_a			  =       rescale_factor
														_a			  =       offset
														_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      __lowerCAmelCase    (						self :						List[str]							,    lowerCAmelCase_ :						np.ndarray							,    lowerCAmelCase_ :						Dict[str, int]							,    lowerCAmelCase_ :						PILImageResampling = PILImageResampling.BILINEAR							,    lowerCAmelCase_ :						Optional[Union[str, ChannelDimension]] = None							,    **lowerCAmelCase_ :						Union[str, Any]							,    )    ->							np.ndarray:


														"""simple docstring"""


														_a			  =       get_size_dict(lowerCAmelCase_							,    default_to_square=lowerCAmelCase_      )
														if "shortest_edge" in size:
																					_a			  =       get_resize_output_image_size(lowerCAmelCase_							,    size['''shortest_edge''']							,    default_to_square=lowerCAmelCase_      )
														elif "height" in size and "width" in size:
																					_a			  =       (size['''height'''], size['''width'''])
														else:
																					raise ValueError(F'Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'      )
														return resize(lowerCAmelCase_							,    size=lowerCAmelCase_							,    resample=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						Optional[Any]							,    lowerCAmelCase_ :						np.ndarray							,    lowerCAmelCase_ :						Dict[str, int]							,    lowerCAmelCase_ :						Optional[Union[str, ChannelDimension]] = None							,    **lowerCAmelCase_ :						Tuple							,    )    ->							np.ndarray:


														"""simple docstring"""


														_a			  =       get_size_dict(lowerCAmelCase_      )
														if "height" not in size or "width" not in size:
																					raise ValueError(F'Size must have \'height\' and \'width\' as keys. Got {size.keys()}'      )
														return center_crop(lowerCAmelCase_							,    size=(size['''height'''], size['''width'''])							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[Any]							,    lowerCAmelCase_ :						np.ndarray							,    lowerCAmelCase_ :						Union[int, float]							,    lowerCAmelCase_ :						bool = True							,    lowerCAmelCase_ :						Optional[Union[str, ChannelDimension]] = None							,    **lowerCAmelCase_ :						Any							,    )    ->							Optional[Any]:


														"""simple docstring"""


														_a			  =       image.astype(np.floataa      )
														if offset:
																					_a			  =       image - (scale / 2)
														return rescale(lowerCAmelCase_							,    scale=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[Any]							,    lowerCAmelCase_ :						np.ndarray							,    lowerCAmelCase_ :						Union[float, List[float]]							,    lowerCAmelCase_ :						Union[float, List[float]]							,    lowerCAmelCase_ :						Optional[Union[str, ChannelDimension]] = None							,    **lowerCAmelCase_ :						Union[str, Any]							,    )    ->							np.ndarray:


														"""simple docstring"""


														return normalize(lowerCAmelCase_							,    mean=lowerCAmelCase_							,    std=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    **lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						Tuple							,    lowerCAmelCase_ :						ImageInput							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						PILImageResampling = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						float = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[ChannelDimension] = ChannelDimension.FIRST							,    )    ->							np.ndarray:


														"""simple docstring"""


														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_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.'''      )

														if offset and not do_rescale:
																					raise ValueError('''For offset, do_rescale must also be set to True.'''      )

														# All transformations expect numpy arrays.
														_a			  =       to_numpy_array(lowerCAmelCase_      )

														if do_resize:
																					_a			  =       self.resize(image=lowerCAmelCase_							,    size=lowerCAmelCase_							,    resample=lowerCAmelCase_      )

														if do_center_crop:
																					_a			  =       self.center_crop(lowerCAmelCase_							,    size=lowerCAmelCase_      )

														if do_rescale:
																					_a			  =       self.rescale(image=lowerCAmelCase_							,    scale=lowerCAmelCase_							,    offset=lowerCAmelCase_      )

														if do_normalize:
																					_a			  =       self.normalize(image=lowerCAmelCase_							,    mean=lowerCAmelCase_							,    std=lowerCAmelCase_      )

														_a			  =       to_channel_dimension_format(lowerCAmelCase_							,    lowerCAmelCase_      )
														return image







							def      __lowerCAmelCase    (						self :						str							,    lowerCAmelCase_ :						ImageInput							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						PILImageResampling = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Dict[str, int] = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						float = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						bool = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[float, List[float]]] = None							,    lowerCAmelCase_ :						Optional[Union[str, TensorType]] = None							,    lowerCAmelCase_ :						ChannelDimension = ChannelDimension.FIRST							,    **lowerCAmelCase_ :						Any							,    )    ->							PIL.Image.Image:


														"""simple docstring"""


														_a			  =       do_resize if do_resize is not None else self.do_resize
														_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			  =       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			  =       offset if offset is not None else self.offset
														_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			  =       crop_size if crop_size is not None else self.crop_size
														_a			  =       get_size_dict(lowerCAmelCase_							,    param_name='''crop_size'''      )

														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.'''      )

														_a			  =       make_batched(lowerCAmelCase_      )

														_a			  =       [
														    [
														        self._preprocess_image(
														            image=lowerCAmelCase_							,    do_resize=lowerCAmelCase_							,    size=lowerCAmelCase_							,    resample=lowerCAmelCase_							,    do_center_crop=lowerCAmelCase_							,    crop_size=lowerCAmelCase_							,    do_rescale=lowerCAmelCase_							,    rescale_factor=lowerCAmelCase_							,    offset=lowerCAmelCase_							,    do_normalize=lowerCAmelCase_							,    image_mean=lowerCAmelCase_							,    image_std=lowerCAmelCase_							,    data_format=lowerCAmelCase_							,    )
														        for img in video
														    ]
														    for video in videos
														]

														_a			  =       {'''pixel_values''': videos}
														return BatchFeature(data=lowerCAmelCase_							,    tensor_type=lowerCAmelCase_      )

