
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


A		: Tuple								=     logging.get_logger(__name__)



class    a_ (			_a    ):
			a	:			Tuple					   =							['''pixel_values''']






			def __init__(      self				,			__UpperCamelCase = True				,			__UpperCamelCase = None				,			__UpperCamelCase = PILImageResampling.BILINEAR				,			__UpperCamelCase = True				,			__UpperCamelCase = None				,			__UpperCamelCase = True				,			__UpperCamelCase = 1 / 255				,			__UpperCamelCase = True				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			**__UpperCamelCase				,			):
									super().__init__(**__UpperCamelCase  )
									_lowercase					       =					size if size is not None else {"""shortest_edge""": 256}
									_lowercase					       =					get_size_dict(__UpperCamelCase				,			default_to_square=__UpperCamelCase  )
									_lowercase					       =					crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
									_lowercase					       =					get_size_dict(__UpperCamelCase  )
									_lowercase					       =					do_resize
									_lowercase					       =					size
									_lowercase					       =					resample
									_lowercase					       =					do_center_crop
									_lowercase					       =					crop_size
									_lowercase					       =					do_rescale
									_lowercase					       =					rescale_factor
									_lowercase					       =					do_normalize
									_lowercase					       =					image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
									_lowercase					       =					image_std if image_std is not None else IMAGENET_STANDARD_STD






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase = PILImageResampling.BICUBIC				,			__UpperCamelCase = None				,			**__UpperCamelCase				,			):
									_lowercase					       =					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()}"""  )
									_lowercase					       =					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    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase = None				,			**__UpperCamelCase				,			):
									_lowercase					       =					get_size_dict(__UpperCamelCase  )
									return center_crop(__UpperCamelCase				,			size=(size["""height"""], size["""width"""])				,			data_format=__UpperCamelCase				,			**__UpperCamelCase  )






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase = None				,			**__UpperCamelCase  ):
									return rescale(__UpperCamelCase				,			scale=__UpperCamelCase				,			data_format=__UpperCamelCase				,			**__UpperCamelCase  )






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase				,			__UpperCamelCase = None				,			**__UpperCamelCase				,			):
									return normalize(__UpperCamelCase				,			mean=__UpperCamelCase				,			std=__UpperCamelCase				,			data_format=__UpperCamelCase				,			**__UpperCamelCase  )






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = None				,			__UpperCamelCase = ChannelDimension.FIRST				,			**__UpperCamelCase				,			):
									_lowercase					       =					do_resize if do_resize is not None else self.do_resize
									_lowercase					       =					size if size is not None else self.size
									_lowercase					       =					get_size_dict(__UpperCamelCase				,			default_to_square=__UpperCamelCase  )
									_lowercase					       =					resample if resample is not None else self.resample
									_lowercase					       =					do_center_crop if do_center_crop is not None else self.do_center_crop
									_lowercase					       =					crop_size if crop_size is not None else self.crop_size
									_lowercase					       =					get_size_dict(__UpperCamelCase  )
									_lowercase					       =					do_rescale if do_rescale is not None else self.do_rescale
									_lowercase					       =					rescale_factor if rescale_factor is not None else self.rescale_factor
									_lowercase					       =					do_normalize if do_normalize is not None else self.do_normalize
									_lowercase					       =					image_mean if image_mean is not None else self.image_mean
									_lowercase					       =					image_std if image_std is not None else self.image_std

									_lowercase					       =					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.
									_lowercase					       =					[to_numpy_array(__UpperCamelCase  ) for image in images]

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

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

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

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

									_lowercase					       =					[to_channel_dimension_format(__UpperCamelCase				,			__UpperCamelCase  ) for image in images]

									_lowercase					       =					{"""pixel_values""": images}
									return BatchFeature(data=__UpperCamelCase				,			tensor_type=__UpperCamelCase  )

import datasets


A		: Optional[int]								=     '''\
@InProceedings{conneau2018xnli,
  author = "Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin",
  title = "XNLI: Evaluating Cross-lingual Sentence Representations",
  booktitle = "Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing",
  year = "2018",
  publisher = "Association for Computational Linguistics",
  location = "Brussels, Belgium",
}
'''

A		: Optional[int]								=     '''\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
'''

A		: str								=     '''
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    \'accuracy\': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric("xnli")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'accuracy\': 1.0}
'''




def 	UpperCamelCase__  (     SCREAMING_SNAKE_CASE_	:	List[str]		,   SCREAMING_SNAKE_CASE_	:	List[Any]       )  ->     str:
						return (preds == labels).mean()



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION					,			_KWARGS_DESCRIPTION    )
class    a_ (			datasets.Metric    ):






			def    UpperCamelCase_				(      self  ):
									return datasets.MetricInfo(
									    description=_DESCRIPTION				,			citation=_CITATION				,			inputs_description=_KWARGS_DESCRIPTION				,			features=datasets.Features(
									        {
									            """predictions""": datasets.Value("""int64""" if self.config_name != """sts-b""" else """float32"""  ),
									            """references""": datasets.Value("""int64""" if self.config_name != """sts-b""" else """float32"""  ),
									        }  )				,			codebase_urls=[]				,			reference_urls=[]				,			format="""numpy"""				,			)






			def    UpperCamelCase_				(      self				,			__UpperCamelCase				,			__UpperCamelCase  ):
									return {"accuracy": simple_accuracy(__UpperCamelCase				,			__UpperCamelCase  )}