






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


lowercase_				     =     '\\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'

lowercase_				     =     '\\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'

lowercase_				     =     '\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 					snake_case		(							datasets.Metric						):


   '''simple docstring'''

   def 				_SCREAMING_SNAKE_CASE				(	self :     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 				_SCREAMING_SNAKE_CASE				(	self :     int,       _lowerCamelCase :     str,       _lowerCamelCase :     Optional[Any],       _lowerCamelCase :     Any=None,       _lowerCamelCase :     Tuple=None,       _lowerCamelCase :     Optional[Any]=None,       _lowerCamelCase :     Union[str, Any]=None,       _lowerCamelCase :     str="auto",       _lowerCamelCase :     Union[str, Any]=-1,       _lowerCamelCase :     List[str]=0.9,       _lowerCamelCase :     int=5,       _lowerCamelCase :     Tuple=5_00,       _lowerCamelCase :     Union[str, Any]="gpt2-large",       _lowerCamelCase :     int=-1,       _lowerCamelCase :     Union[str, Any]=10_24,       _lowerCamelCase :     Union[str, Any]=25,       _lowerCamelCase :     str=5,       _lowerCamelCase :     Any=True,       _lowerCamelCase :     Union[str, Any]=25,       ):

     '''simple docstring'''
     __A									= compute_mauve(
         p_text=_lowerCamelCase,       q_text=_lowerCamelCase,       p_features=_lowerCamelCase,       q_features=_lowerCamelCase,       p_tokens=_lowerCamelCase,       q_tokens=_lowerCamelCase,       num_buckets=_lowerCamelCase,       pca_max_data=_lowerCamelCase,       kmeans_explained_var=_lowerCamelCase,       kmeans_num_redo=_lowerCamelCase,       kmeans_max_iter=_lowerCamelCase,       featurize_model_name=_lowerCamelCase,       device_id=_lowerCamelCase,       max_text_length=_lowerCamelCase,       divergence_curve_discretization_size=_lowerCamelCase,       mauve_scaling_factor=_lowerCamelCase,       verbose=_lowerCamelCase,       seed=_lowerCamelCase,       )
     return out












"""simple docstring"""


import argparse
import struct
import unittest


class 					snake_case		:


   '''simple docstring'''

   def __init__(	self :     Optional[int],       _lowerCamelCase :     bytes  ):

     '''simple docstring'''
     __A									= data

     # Initialize hash values
     __A									= [
         0X6a_09e_667,
         0Xbb_67a_e85,
         0X3c_6ef_372,
         0Xa5_4ff_53a,
         0X51_0e5_27f,
         0X9b_056_88c,
         0X1f_83d_9ab,
         0X5b_e0c_d19,
     ]

     # Initialize round constants
     __A									= [
         0X42_8a2_f98,
         0X71_374_491,
         0Xb5_c0f_bcf,
         0Xe9_b5d_ba5,
         0X39_56c_25b,
         0X59_f11_1f1,
         0X92_3f8_2a4,
         0Xab_1c5_ed5,
         0Xd8_07a_a98,
         0X12_835_b01,
         0X24_318_5be,
         0X55_0c7_dc3,
         0X72_be5_d74,
         0X80_deb_1fe,
         0X9b_dc0_6a7,
         0Xc1_9bf_174,
         0Xe4_9b6_9c1,
         0Xef_be4_786,
         0X0f_c19_dc6,
         0X24_0ca_1cc,
         0X2d_e92_c6f,
         0X4a_748_4aa,
         0X5c_b0a_9dc,
         0X76_f98_8da,
         0X98_3e5_152,
         0Xa8_31c_66d,
         0Xb0_032_7c8,
         0Xbf_597_fc7,
         0Xc6_e00_bf3,
         0Xd5_a79_147,
         0X06_ca6_351,
         0X14_292_967,
         0X27_b70_a85,
         0X2e_1b2_138,
         0X4d_2c6_dfc,
         0X53_380_d13,
         0X65_0a7_354,
         0X76_6a0_abb,
         0X81_c2c_92e,
         0X92_722_c85,
         0Xa2_bfe_8a1,
         0Xa8_1a6_64b,
         0Xc2_4b8_b70,
         0Xc7_6c5_1a3,
         0Xd1_92e_819,
         0Xd6_990_624,
         0Xf4_0e3_585,
         0X10_6aa_070,
         0X19_a4c_116,
         0X1e_376_c08,
         0X27_487_74c,
         0X34_b0b_cb5,
         0X39_1c0_cb3,
         0X4e_d8a_a4a,
         0X5b_9cc_a4f,
         0X68_2e6_ff3,
         0X74_8f8_2ee,
         0X78_a56_36f,
         0X84_c87_814,
         0X8c_c70_208,
         0X90_bef_ffa,
         0Xa4_506_ceb,
         0Xbe_f9a_3f7,
         0Xc6_717_8f2,
     ]

     __A									= self.preprocessing(self.data  )
     self.final_hash()


   @staticmethod
   def 				_SCREAMING_SNAKE_CASE				(	_lowerCamelCase :     bytes  ):

     '''simple docstring'''
     __A									= b'''\x80''' + (b'''\x00''' * (63 - (len(_lowerCamelCase  ) + 8) % 64))
     __A									= struct.pack('''>Q''',       (len(_lowerCamelCase  ) * 8)  )
     return data + padding + big_endian_integer


   def 				_SCREAMING_SNAKE_CASE				(	self :     int  ):

     '''simple docstring'''
     # Convert into blocks of 64 bytes
     __A									= [
         self.preprocessed_data[x : x + 64]
         for x in range(0,       len(self.preprocessed_data  ),       64  )
     ]

     for block in self.blocks:
       # Convert the given block into a list of 4 byte integers
       __A									= list(struct.unpack('''>16L''',       _lowerCamelCase  )  )
       # add 48 0-ed integers
       words += [0] * 48

       __A			,    __A			,    __A			,    __A			,    __A			,    __A			,    __A			,    __A									= self.hashes

       for index in range(0,       64  ):
         if index > 15:
           # modify the zero-ed indexes at the end of the array
           __A									= (
               self.ror(words[index - 15],       7  )
               ^ self.ror(words[index - 15],       18  )
               ^ (words[index - 15] >> 3)
           )
           __A									= (
               self.ror(words[index - 2],       17  )
               ^ self.ror(words[index - 2],       19  )
               ^ (words[index - 2] >> 10)
           )

           __A									= (
               words[index - 16] + sa + words[index - 7] + sa
           ) % 0X100_000_000

         # Compression
         __A									= self.ror(_lowerCamelCase,       6  ) ^ self.ror(_lowerCamelCase,       11  ) ^ self.ror(_lowerCamelCase,       25  )
         __A									= (e & f) ^ ((~e & 0Xff_fff_fff) & g)
         __A									= (
             h + sa + ch + self.round_constants[index] + words[index]
         ) % 0X100_000_000
         __A									= self.ror(_lowerCamelCase,       2  ) ^ self.ror(_lowerCamelCase,       13  ) ^ self.ror(_lowerCamelCase,       22  )
         __A									= (a & b) ^ (a & c) ^ (b & c)
         __A									= (sa + maj) % 0X100_000_000

         __A			,    __A			,    __A			,    __A			,    __A			,    __A			,    __A			,    __A									= (
             g,
             f,
             e,
             ((d + tempa) % 0X100_000_000),
             c,
             b,
             a,
             ((tempa + tempa) % 0X100_000_000),
         )

       __A									= [a, b, c, d, e, f, g, h]

       # Modify final values
       __A									= [
           ((element + mutated_hash_values[index]) % 0X100_000_000)
           for index, element in enumerate(self.hashes  )
       ]

     __A									= ''''''.join([hex(_lowerCamelCase  )[2:].zfill(8  ) for value in self.hashes]  )






   def 				_SCREAMING_SNAKE_CASE				(	self :     Union[str, Any],       _lowerCamelCase :     int,       _lowerCamelCase :     int  ):

     '''simple docstring'''
     return 0Xff_fff_fff & (value << (32 - rotations)) | (value >> rotations)





class 					snake_case		(							unittest.TestCase						):


   '''simple docstring'''

   def 				_SCREAMING_SNAKE_CASE				(	self :     Dict  ):

     '''simple docstring'''
     import hashlib

     __A									= bytes('''Test String''',       '''utf-8'''  )
     self.assertEqual(SHAaaa(_lowerCamelCase  ).hash,       hashlib.shaaaa(_lowerCamelCase  ).hexdigest()  )





def 					lowerCAmelCase				(    ):




  """simple docstring"""







  import doctest

  doctest.testmod()

  __A									= argparse.ArgumentParser()
  parser.add_argument(
      '''-s'''		,       '''--string'''		,       dest='''input_string'''		,       default='''Hello World!! Welcome to Cryptography'''		,       help='''Hash the string'''		,       )
  parser.add_argument(
      '''-f'''		,       '''--file'''		,       dest='''input_file'''		,       help='''Hash contents of a file''' )

  __A									= parser.parse_args()

  __A									= args.input_string

  # hash input should be a bytestring
  if args.input_file:
    with open(args.input_file		,       '''rb''' ) as f:
      __A									= f.read()
  else:
    __A									= bytes(__UpperCamelCase		,       '''utf-8''' )

  print(SHAaaa(__UpperCamelCase ).hash )


if __name__ == "__main__":
       main()




