



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        =			logging.get_logger(__name__)


if is_vision_available():
				import PIL


class 							__a							(  __A						):





		'''simple docstring'''



		UpperCAmelCase__      :				Any				    =						["""pixel_values"""]


		def __init__(						self ,    UpperCamelCase__ = True ,    UpperCamelCase__ = None ,    UpperCamelCase__ = PILImageResampling.BICUBIC ,    UpperCamelCase__ = True ,    UpperCamelCase__ = None ,    UpperCamelCase__ = True ,    UpperCamelCase__ = 1 / 255 ,    UpperCamelCase__ = True ,    UpperCamelCase__ = None ,    UpperCamelCase__ = None ,    UpperCamelCase__ = True ,    **UpperCamelCase__ ,    ):
						super().__init__(**UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   size if size is not None else {'shortest_edge': 224}
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   get_size_dict(UpperCamelCase__ ,    default_to_square=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	Any													=   crop_size if crop_size is not None else {'height': 224, 'width': 224}
						SCREAMING_SNAKE_CASE_   :	str													=   get_size_dict(UpperCamelCase__ ,    default_to_square=UpperCamelCase__ ,    param_name='crop_size'       )

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


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = PILImageResampling.BICUBIC ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   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()}'''       )
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   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   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	Optional[Any]													=   get_size_dict(UpperCamelCase__       )
						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(UpperCamelCase__ ,    size=(size['height'], size['width']) ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						return rescale(UpperCamelCase__ ,    scale=UpperCamelCase__ ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )


		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ ,    UpperCamelCase__ = None ,    **UpperCamelCase__ ,    ):
						return normalize(UpperCamelCase__ ,    mean=UpperCamelCase__ ,    std=UpperCamelCase__ ,    data_format=UpperCamelCase__ ,    **UpperCamelCase__       )






		def   __snake_case			(						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__ = None ,    UpperCamelCase__ = ChannelDimension.FIRST ,    **UpperCamelCase__ ,    ):
						SCREAMING_SNAKE_CASE_   :	Dict													=   do_resize if do_resize is not None else self.do_resize
						SCREAMING_SNAKE_CASE_   :	Any													=   size if size is not None else self.size
						SCREAMING_SNAKE_CASE_   :	List[str]													=   get_size_dict(UpperCamelCase__ ,    param_name='size' ,    default_to_square=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	int													=   resample if resample is not None else self.resample
						SCREAMING_SNAKE_CASE_   :	Optional[int]													=   do_center_crop if do_center_crop is not None else self.do_center_crop
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   crop_size if crop_size is not None else self.crop_size
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   get_size_dict(UpperCamelCase__ ,    param_name='crop_size' ,    default_to_square=UpperCamelCase__       )
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   do_rescale if do_rescale is not None else self.do_rescale
						SCREAMING_SNAKE_CASE_   :	str													=   rescale_factor if rescale_factor is not None else self.rescale_factor
						SCREAMING_SNAKE_CASE_   :	int													=   do_normalize if do_normalize is not None else self.do_normalize
						SCREAMING_SNAKE_CASE_   :	Any													=   image_mean if image_mean is not None else self.image_mean
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   image_std if image_std is not None else self.image_std
						SCREAMING_SNAKE_CASE_   :	int													=   do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   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.'       )

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

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

						if do_resize:
										SCREAMING_SNAKE_CASE_   :	List[str]													=   [self.resize(image=UpperCamelCase__ ,    size=UpperCamelCase__ ,    resample=UpperCamelCase__       ) for image in images]

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

						if do_rescale:
										SCREAMING_SNAKE_CASE_   :	Union[str, Any]													=   [self.rescale(image=UpperCamelCase__ ,    scale=UpperCamelCase__       ) for image in images]

						if do_normalize:
										SCREAMING_SNAKE_CASE_   :	Dict													=   [self.normalize(image=UpperCamelCase__ ,    mean=UpperCamelCase__ ,    std=UpperCamelCase__       ) for image in images]

						SCREAMING_SNAKE_CASE_   :	List[Any]													=   [to_channel_dimension_format(UpperCamelCase__ ,    UpperCamelCase__       ) for image in images]

						SCREAMING_SNAKE_CASE_   :	Any													=   {'pixel_values': images}
						return BatchFeature(data=UpperCamelCase__ ,    tensor_type=UpperCamelCase__       )







import os

from bleurt import score  # From: git+https://github.com/google-research/bleurt.git

import datasets


A        =			datasets.logging.get_logger(__name__)


A        =			'\\n@inproceedings{bleurt,\n  title={BLEURT: Learning Robust Metrics for Text Generation},\n  author={Thibault Sellam and Dipanjan Das and Ankur P. Parikh},\n  booktitle={ACL},\n  year={2020},\n  url={https://arxiv.org/abs/2004.04696}\n}\n'

A        =			'\\nBLEURT a learnt evaluation metric for Natural Language Generation. It is built using multiple phases of transfer learning starting from a pretrained BERT model (Devlin et al. 2018)\nand then employing another pre-training phrase using synthetic data. Finally it is trained on WMT human annotations. You may run BLEURT out-of-the-box or fine-tune\nit for your specific application (the latter is expected to perform better).\n\nSee the project\'s README at https://github.com/google-research/bleurt#readme for more information.\n'

A        =			'\nBLEURT score.\n\nArgs:\n    `predictions` (list of str): prediction/candidate sentences\n    `references` (list of str): reference sentences\n    `checkpoint` BLEURT checkpoint. Will default to BLEURT-tiny if None.\n\nReturns:\n    \'scores\': List of scores.\nExamples:\n\n    >>> predictions = ["hello there", "general kenobi"]\n    >>> references = ["hello there", "general kenobi"]\n    >>> bleurt = datasets.load_metric("bleurt")\n    >>> results = bleurt.compute(predictions=predictions, references=references)\n    >>> print([round(v, 2) for v in results["scores"]])\n    [1.03, 1.04]\n'

A        =			{
    'bleurt-tiny-128': 'https://storage.googleapis.com/bleurt-oss/bleurt-tiny-128.zip',
    'bleurt-tiny-512': 'https://storage.googleapis.com/bleurt-oss/bleurt-tiny-512.zip',
    'bleurt-base-128': 'https://storage.googleapis.com/bleurt-oss/bleurt-base-128.zip',
    'bleurt-base-512': 'https://storage.googleapis.com/bleurt-oss/bleurt-base-512.zip',
    'bleurt-large-128': 'https://storage.googleapis.com/bleurt-oss/bleurt-large-128.zip',
    'bleurt-large-512': 'https://storage.googleapis.com/bleurt-oss/bleurt-large-512.zip',
    'BLEURT-20-D3': 'https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D3.zip',
    'BLEURT-20-D6': 'https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D6.zip',
    'BLEURT-20-D12': 'https://storage.googleapis.com/bleurt-oss-21/BLEURT-20-D12.zip',
    'BLEURT-20': 'https://storage.googleapis.com/bleurt-oss-21/BLEURT-20.zip',
}


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





		'''simple docstring'''



		def   __snake_case			(						self       ):
						return datasets.MetricInfo(
						    description=_DESCRIPTION ,    citation=_CITATION ,    homepage='https://github.com/google-research/bleurt' ,    inputs_description=_KWARGS_DESCRIPTION ,    features=datasets.Features(
						        {
						            'predictions': datasets.Value('string' ,    id='sequence'       ),
						            'references': datasets.Value('string' ,    id='sequence'       ),
						        }       ) ,    codebase_urls=['https://github.com/google-research/bleurt'] ,    reference_urls=['https://github.com/google-research/bleurt', 'https://arxiv.org/abs/2004.04696'] ,    )


		def   __snake_case			(						self ,    UpperCamelCase__       ):
						# check that config name specifies a valid BLEURT model
						if self.config_name == "default":
										logger.warning(
										    'Using default BLEURT-Base checkpoint for sequence maximum length 128. '
										    'You can use a bigger model for better results with e.g.: datasets.load_metric(\'bleurt\', \'bleurt-large-512\').'       )
										SCREAMING_SNAKE_CASE_   :	List[Any]													=   'bleurt-base-128'

						if self.config_name.lower() in CHECKPOINT_URLS:
										SCREAMING_SNAKE_CASE_   :	Tuple													=   self.config_name.lower()

						elif self.config_name.upper() in CHECKPOINT_URLS:
										SCREAMING_SNAKE_CASE_   :	Any													=   self.config_name.upper()

						else:
										raise KeyError(
										    F'''{self.config_name} model not found. You should supply the name of a model checkpoint for bleurt in {CHECKPOINT_URLS.keys()}'''       )

						# download the model checkpoint specified by self.config_name and set up the scorer
						SCREAMING_SNAKE_CASE_   :	List[Any]													=   dl_manager.download_and_extract(CHECKPOINT_URLS[checkpoint_name]       )
						SCREAMING_SNAKE_CASE_   :	int													=   score.BleurtScorer(os.path.join(UpperCamelCase__ ,    UpperCamelCase__       )       )






		def   __snake_case			(						self ,    UpperCamelCase__ ,    UpperCamelCase__       ):
						SCREAMING_SNAKE_CASE_   :	Tuple													=   self.scorer.score(references=UpperCamelCase__ ,    candidates=UpperCamelCase__       )
						return {"scores": scores}