



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


if is_vision_available():
 import PIL


__lowercase    =				logging.get_logger(__name__)






class 						_A  (  __lowerCamelCase  ):







    """simple docstring"""




    UpperCAmelCase	:							int     =	['pixel_values']






    def __init__( self    :   Dict    ,			__UpperCAmelCase    :   bool = True    ,			__UpperCAmelCase    :   Dict[str, int] = None    ,			__UpperCAmelCase    :   PILImageResampling = PILImageResampling.BICUBIC    ,			__UpperCAmelCase    :   bool = True    ,			__UpperCAmelCase    :   Union[int, float] = 1 / 255    ,			__UpperCAmelCase    :   bool = True    ,			__UpperCAmelCase    :   Optional[Union[float, List[float]]] = None    ,			__UpperCAmelCase    :   Optional[Union[float, List[float]]] = None    ,			__UpperCAmelCase    :   bool = True    ,			**__UpperCAmelCase    :   Any    ,			):
      super().__init__(**UpperCamelCase_)
      a						:		Dict											=      size if size is not None else {"height": 384, "width": 384}
      a						:		Union[str, Any]											=      get_size_dict(UpperCamelCase_    ,			default_to_square=UpperCamelCase_)

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






    def      __snake_case							( self    :   List[str]    ,			__UpperCAmelCase    :   np.ndarray    ,			__UpperCAmelCase    :   Dict[str, int]    ,			__UpperCAmelCase    :   PILImageResampling = PILImageResampling.BICUBIC    ,			__UpperCAmelCase    :   Optional[Union[str, ChannelDimension]] = None    ,			**__UpperCAmelCase    :   Optional[int]    ,			):
      a						:		Optional[int]											=      get_size_dict(UpperCamelCase_    ,			default_to_square=UpperCamelCase_)
      if "height" not in size or "width" not in size:
        raise ValueError(f'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}''')
      a						:		int											=      (size["height"], size["width"])
      return resize(UpperCamelCase_    ,			size=UpperCamelCase_    ,			resample=UpperCamelCase_    ,			data_format=UpperCamelCase_    ,			**UpperCamelCase_)






    def      __snake_case							( self    :   List[str]    ,			__UpperCAmelCase    :   np.ndarray    ,			__UpperCAmelCase    :   Union[int, float]    ,			__UpperCAmelCase    :   Optional[Union[str, ChannelDimension]] = None    ,			**__UpperCAmelCase    :   Dict    ,			):
      return rescale(UpperCamelCase_    ,			scale=UpperCamelCase_    ,			data_format=UpperCamelCase_    ,			**UpperCamelCase_)






    def      __snake_case							( self    :   Dict    ,			__UpperCAmelCase    :   np.ndarray    ,			__UpperCAmelCase    :   Union[float, List[float]]    ,			__UpperCAmelCase    :   Union[float, List[float]]    ,			__UpperCAmelCase    :   Optional[Union[str, ChannelDimension]] = None    ,			**__UpperCAmelCase    :   Optional[Any]    ,			):
      return normalize(UpperCamelCase_    ,			mean=UpperCamelCase_    ,			std=UpperCamelCase_    ,			data_format=UpperCamelCase_    ,			**UpperCamelCase_)






    def      __snake_case							( self    :   List[Any]    ,			__UpperCAmelCase    :   ImageInput    ,			__UpperCAmelCase    :   Optional[bool] = None    ,			__UpperCAmelCase    :   Optional[Dict[str, int]] = None    ,			__UpperCAmelCase    :   PILImageResampling = None    ,			__UpperCAmelCase    :   Optional[bool] = None    ,			__UpperCAmelCase    :   Optional[float] = None    ,			__UpperCAmelCase    :   Optional[bool] = None    ,			__UpperCAmelCase    :   Optional[Union[float, List[float]]] = None    ,			__UpperCAmelCase    :   Optional[Union[float, List[float]]] = None    ,			__UpperCAmelCase    :   Optional[Union[str, TensorType]] = None    ,			__UpperCAmelCase    :   bool = None    ,			__UpperCAmelCase    :   ChannelDimension = ChannelDimension.FIRST    ,			**__UpperCAmelCase    :   Any    ,			):
      a						:		Dict											=      do_resize if do_resize is not None else self.do_resize
      a						:		Dict											=      resample if resample is not None else self.resample
      a						:		Union[str, Any]											=      do_rescale if do_rescale is not None else self.do_rescale
      a						:		Optional[int]											=      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						:		int											=      image_mean if image_mean is not None else self.image_mean
      a						:		Dict											=      image_std if image_std is not None else self.image_std
      a						:		Union[str, Any]											=      do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

      a						:		int											=      size if size is not None else self.size
      a						:		Optional[Any]											=      get_size_dict(UpperCamelCase_    ,			default_to_square=UpperCamelCase_)

      a						:		Tuple											=      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 or resample is None:
        raise ValueError("Size and resample must be specified if do_resize 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:
        a						:		Dict											=      [convert_to_rgb(UpperCamelCase_) for image in images]

      # All transformations expect numpy arrays.
      a						:		Tuple											=      [to_numpy_array(UpperCamelCase_) for image in images]

      if do_resize:
        a						:		Optional[int]											=      [self.resize(image=UpperCamelCase_    ,			size=UpperCamelCase_    ,			resample=UpperCamelCase_) for image in images]

      if do_rescale:
        a						:		List[str]											=      [self.rescale(image=UpperCamelCase_    ,			scale=UpperCamelCase_) for image in images]

      if do_normalize:
        a						:		Optional[Any]											=      [self.normalize(image=UpperCamelCase_    ,			mean=UpperCamelCase_    ,			std=UpperCamelCase_) for image in images]

      a						:		Any											=      [to_channel_dimension_format(UpperCamelCase_    ,			UpperCamelCase_) for image in images]

      a						:		Tuple											=      BatchFeature(data={"pixel_values": images}    ,			tensor_type=UpperCamelCase_)

      return encoded_outputs










"""simple docstring"""







import datasets


__lowercase    =				"""\
@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\",
}
"""

__lowercase    =				"""\
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).
"""

__lowercase    =				"""
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 					lowercase      (    A_  ,       A_	)->				List[str]:
  '''simple docstring'''







  return (preds == labels).mean()







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







    """simple docstring"""




    def      __snake_case							( self    :   List[str]):
      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      __snake_case							( self    :   str    ,			__UpperCAmelCase    :   List[Any]    ,			__UpperCAmelCase    :   Tuple):
      return {"accuracy": simple_accuracy(__UpperCAmelCase    ,			__UpperCAmelCase)}






