




'''simple docstring'''







import faiss  # noqa: F401 # Here to have a nice missing dependency error message early on
import numpy  # noqa: F401 # Here to have a nice missing dependency error message early on
import requests  # noqa: F401 # Here to have a nice missing dependency error message early on
import sklearn  # noqa: F401 # Here to have a nice missing dependency error message early on
import tqdm  # noqa: F401 # Here to have a nice missing dependency error message early on
from mauve import compute_mauve  # From: mauve-text

import datasets


A									='\\n@inproceedings{pillutla-etal:mauve:neurips2021,\n  title={MAUVE: Measuring the Gap Between Neural Text and Human Text using Divergence Frontiers},\n  author={Pillutla, Krishna and Swayamdipta, Swabha and Zellers, Rowan and Thickstun, John and Welleck, Sean and Choi, Yejin and Harchaoui, Zaid},\n  booktitle = {NeurIPS},\n  year      = {2021}\n}\n\n'

A									='\\nMAUVE is a library built on PyTorch and HuggingFace Transformers to measure the gap between neural text and human text with the eponymous MAUVE measure.\n\nMAUVE summarizes both Type I and Type II errors measured softly using Kullback–Leibler (KL) divergences.\n\nFor details, see the MAUVE paper: https://arxiv.org/abs/2102.01454 (Neurips, 2021).\n\nThis metrics is a wrapper around the official implementation of MAUVE:\nhttps://github.com/krishnap25/mauve\n'

A									='\nCalculates MAUVE scores between two lists of generated text and reference text.\nArgs:\n    predictions: list of generated text to score. Each predictions\n        should be a string with tokens separated by spaces.\n    references: list of reference for each prediction. Each\n        reference should be a string with tokens separated by spaces.\nOptional Args:\n    num_buckets: the size of the histogram to quantize P and Q. Options: \'auto\' (default) or an integer\n    pca_max_data: the number data points to use for PCA dimensionality reduction prior to clustering. If -1, use all the data. Default -1\n    kmeans_explained_var: amount of variance of the data to keep in dimensionality reduction by PCA. Default 0.9\n    kmeans_num_redo: number of times to redo k-means clustering (the best objective is kept). Default 5\n    kmeans_max_iter: maximum number of k-means iterations. Default 500\n    featurize_model_name: name of the model from which features are obtained. Default \'gpt2-large\' Use one of [\'gpt2\', \'gpt2-medium\', \'gpt2-large\', \'gpt2-xl\'].\n    device_id: Device for featurization. Supply a GPU id (e.g. 0 or 3) to use GPU. If no GPU with this id is found, use CPU\n    max_text_length: maximum number of tokens to consider. Default 1024\n    divergence_curve_discretization_size: Number of points to consider on the divergence curve. Default 25\n    mauve_scaling_factor: "c" from the paper. Default 5.\n    verbose: If True (default), print running time updates\n    seed: random seed to initialize k-means cluster assignments.\nReturns:\n    mauve: MAUVE score, a number between 0 and 1. Larger values indicate that P and Q are closer,\n    frontier_integral: Frontier Integral, a number between 0 and 1. Smaller values indicate that P and Q are closer,\n    divergence_curve: a numpy.ndarray of shape (m, 2); plot it with matplotlib to view the divergence curve,\n    p_hist: a discrete distribution, which is a quantized version of the text distribution p_text,\n    q_hist: same as above, but with q_text.\nExamples:\n\n    >>> # faiss segfaults in doctest for some reason, so the .compute call is not tested with doctest\n    >>> import datasets\n    >>> mauve = datasets.load_metric(\'mauve\')\n    >>> predictions = ["hello there", "general kenobi"]\n    >>> references = ["hello there", "general kenobi"]\n    >>> out = mauve.compute(predictions=predictions, references=references) # doctest: +SKIP\n    >>> print(out.mauve) # doctest: +SKIP\n    1.0\n'


@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							,							_KWARGS_DESCRIPTION				)
class     _a						(			datasets.Metric				):
							def 					A   (			self		:			List[Any]       ):



											'''simple docstring'''

											return datasets.MetricInfo(
											    description=_DESCRIPTION     ,       citation=_CITATION     ,       homepage='''https://github.com/krishnap25/mauve'''     ,       inputs_description=_KWARGS_DESCRIPTION     ,       features=datasets.Features(
											        {
											            '''predictions''': datasets.Value('''string'''     ,       id='''sequence'''       ),
											            '''references''': datasets.Value('''string'''     ,       id='''sequence'''       ),
											        }       )     ,       codebase_urls=['''https://github.com/krishnap25/mauve''']     ,       reference_urls=[
											        '''https://arxiv.org/abs/2102.01454''',
											        '''https://github.com/krishnap25/mauve''',
											    ]     ,       )







							def 					A   (			self		:			Dict     ,       lowercase		:			str     ,       lowercase		:			List[str]     ,       lowercase		:			Tuple=None     ,       lowercase		:			Union[str, Any]=None     ,       lowercase		:			str=None     ,       lowercase		:			Optional[Any]=None     ,       lowercase		:			Optional[int]="auto"     ,       lowercase		:			Optional[int]=-1     ,       lowercase		:			Optional[Any]=0.9     ,       lowercase		:			str=5     ,       lowercase		:			Optional[Any]=500     ,       lowercase		:			Dict="gpt2-large"     ,       lowercase		:			List[Any]=-1     ,       lowercase		:			Dict=1_024     ,       lowercase		:			Optional[Any]=25     ,       lowercase		:			str=5     ,       lowercase		:			Tuple=True     ,       lowercase		:			Union[str, Any]=25     ,       ):



											'''simple docstring'''

											UpperCAmelCase     =	compute_mauve(
											    p_text=lowercase     ,       q_text=lowercase     ,       p_features=lowercase     ,       q_features=lowercase     ,       p_tokens=lowercase     ,       q_tokens=lowercase     ,       num_buckets=lowercase     ,       pca_max_data=lowercase     ,       kmeans_explained_var=lowercase     ,       kmeans_num_redo=lowercase     ,       kmeans_max_iter=lowercase     ,       featurize_model_name=lowercase     ,       device_id=lowercase     ,       max_text_length=lowercase     ,       divergence_curve_discretization_size=lowercase     ,       mauve_scaling_factor=lowercase     ,       verbose=lowercase     ,       seed=lowercase     ,       )
											return out










'''simple docstring'''







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				):
       def 					A   (			self		:			Dict       ):



           '''simple docstring'''

           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 					A   (			self		:			List[Any]     ,       lowercase		:			Union[str, Any]       ):



           '''simple docstring'''

           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\').'''       )
               UpperCAmelCase     =	'''bleurt-base-128'''

           if self.config_name.lower() in CHECKPOINT_URLS:
               UpperCAmelCase     =	self.config_name.lower()

           elif self.config_name.upper() in CHECKPOINT_URLS:
               UpperCAmelCase     =	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
           UpperCAmelCase     =	dl_manager.download_and_extract(CHECKPOINT_URLS[checkpoint_name]       )
           UpperCAmelCase     =	score.BleurtScorer(os.path.join(lowercase     ,       lowercase       )       )







       def 					A   (			self		:			str     ,       lowercase		:			str     ,       lowercase		:			str       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.scorer.score(references=lowercase     ,       candidates=lowercase       )
           return {"scores": scores}




