





"""simple docstring"""





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


_UpperCamelCase							=      threading.Lock()
_UpperCamelCase							=      None

_UpperCamelCase							=      {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

_UpperCamelCase							=      logging.WARNING

_UpperCamelCase							=      True



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      List[Any]         =os.getenv('''TRANSFORMERS_VERBOSITY'''    ,						SCREAMING_SNAKE_CASE   )
							if env_level_str:
														if env_level_str in log_levels:
																					return log_levels[env_level_str]
														else:
																					logging.getLogger().warning(
																					    F'Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '
																					    F'has to be one of: { ", ".join(log_levels.keys()   ) }'   )
							return _default_log_level



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return __name__.split('''.'''   )[0]



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return logging.getLogger(_get_library_name()   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							global _default_handler

							with _lock:
														if _default_handler:
																					# This library has already configured the library root logger.
																					return
														__lowerCamelCase      :      str         =logging.StreamHandler()  # Set sys.stderr as stream.
														__lowerCamelCase      :      int         =sys.stderr.flush

														# Apply our default configuration to the library root logger.
														__lowerCamelCase      :      Union[str, Any]         =_get_library_root_logger()
														library_root_logger.addHandler(_default_handler   )
														library_root_logger.setLevel(_get_default_logging_level()   )
														__lowerCamelCase      :      Tuple         =False



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							global _default_handler

							with _lock:
														if not _default_handler:
																					return

														__lowerCamelCase      :      Tuple         =_get_library_root_logger()
														library_root_logger.removeHandler(_default_handler   )
														library_root_logger.setLevel(logging.NOTSET   )
														__lowerCamelCase      :      Union[str, Any]         =None



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return log_levels



def 				lowerCAmelCase_			(      SCREAMING_SNAKE_CASE       :							Optional[str] = None   ):


							'''simple docstring'''







							if name is None:
														__lowerCamelCase      :      str         =_get_library_name()

							_configure_library_root_logger()
							return logging.getLogger(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							_configure_library_root_logger()
							return _get_library_root_logger().getEffectiveLevel()



def 				lowerCAmelCase_			(      SCREAMING_SNAKE_CASE       :							int   ):


							'''simple docstring'''







							_configure_library_root_logger()
							_get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return set_verbosity(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return set_verbosity(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return set_verbosity(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							return set_verbosity(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							_configure_library_root_logger()

							assert _default_handler is not None
							_get_library_root_logger().removeHandler(_default_handler   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							_configure_library_root_logger()

							assert _default_handler is not None
							_get_library_root_logger().addHandler(_default_handler   )



def 				lowerCAmelCase_			(      SCREAMING_SNAKE_CASE       :							logging.Handler   ):


							'''simple docstring'''







							_configure_library_root_logger()

							assert handler is not None
							_get_library_root_logger().addHandler(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      SCREAMING_SNAKE_CASE       :							logging.Handler   ):


							'''simple docstring'''







							_configure_library_root_logger()

							assert handler is not None and handler not in _get_library_root_logger().handlers
							_get_library_root_logger().removeHandler(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							_configure_library_root_logger()
							__lowerCamelCase      :      List[str]         =False



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							_configure_library_root_logger()
							__lowerCamelCase      :      Optional[Any]         =True



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      Dict         =_get_library_root_logger().handlers

							for handler in handlers:
														__lowerCamelCase      :      Optional[Any]         =logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''   )
														handler.setFormatter(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      Dict         =_get_library_root_logger().handlers

							for handler in handlers:
														handler.setFormatter(SCREAMING_SNAKE_CASE   )



def 				lowerCAmelCase_			(      self       :							Any    ,						*SCREAMING_SNAKE_CASE       :							Optional[Any]    ,						**SCREAMING_SNAKE_CASE       :							Dict   ):


							'''simple docstring'''







							__lowerCamelCase      :      Union[str, Any]         =os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''    ,						SCREAMING_SNAKE_CASE   )
							if no_advisory_warnings:
														return
							self.warning(*SCREAMING_SNAKE_CASE    ,						**SCREAMING_SNAKE_CASE   )


_UpperCamelCase							=      warning_advice



@functools.lru_cache(SCREAMING_SNAKE_CASE   )
def 				lowerCAmelCase_			(      self       :							List[str]    ,						*SCREAMING_SNAKE_CASE       :							Any    ,						**SCREAMING_SNAKE_CASE       :							str   ):


							'''simple docstring'''







							self.warning(*SCREAMING_SNAKE_CASE    ,						**SCREAMING_SNAKE_CASE   )


_UpperCamelCase							=      warning_once
class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __init__(     self  :str						,    *__lowercase  :Optional[int]						,    **__lowercase  :Dict			):  # pylint: disable=unused-argument
											__lowerCamelCase      :      Tuple         =args[0] if args else None




				def __iter__(     self  :Optional[int]			):
											return iter(self._iterator			)




				def __getattr__(     self  :List[Any]						,    __lowercase  :List[str]			):

											def empty_fn(*__lowercase  :Optional[Any]						,    **__lowercase  :Tuple			):  # pylint: disable=unused-argument
																		return

											return empty_fn




				def __enter__(     self  :List[str]			):
											return self




				def __exit__(     self  :List[Any]						,    __lowercase  :Any						,    __lowercase  :Tuple						,    __lowercase  :List[str]			):
											return

class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __call__(     self  :Dict						,    *__lowercase  :Dict						,    **__lowercase  :Dict			):
											if _tqdm_active:
																		return tqdm_lib.tqdm(*__lowercase						,    **__lowercase			)
											else:
																		return EmptyTqdm(*__lowercase						,    **__lowercase			)




				def 					__lowercase  (     self  :Union[str, Any]						,    *__lowercase  :Union[str, Any]						,    **__lowercase  :int			):
											__lowerCamelCase      :      Any         =None
											if _tqdm_active:
																		return tqdm_lib.tqdm.set_lock(*__lowercase						,    **__lowercase			)




				def 					__lowercase  (     self  :Optional[int]			):
											if _tqdm_active:
																		return tqdm_lib.tqdm.get_lock()

_UpperCamelCase							=      _tqdm_cls()



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							global _tqdm_active
							return bool(_tqdm_active   )



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							global _tqdm_active
							__lowerCamelCase      :      str         =True
							hf_hub_utils.enable_progress_bars()



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							global _tqdm_active
							__lowerCamelCase      :      Any         =False
							hf_hub_utils.disable_progress_bars()











"""simple docstring"""





from typing import Dict, List

from nltk.translate import gleu_score

import datasets
from datasets import MetricInfo


_UpperCamelCase							=      '\\n@misc{wu2016googles,\n      title={Google\'s Neural Machine Translation System: Bridging the Gap between Human and Machine Translation},\n      author={Yonghui Wu and Mike Schuster and Zhifeng Chen and Quoc V. Le and Mohammad Norouzi and Wolfgang Macherey\n              and Maxim Krikun and Yuan Cao and Qin Gao and Klaus Macherey and Jeff Klingner and Apurva Shah and Melvin\n              Johnson and Xiaobing Liu and Łukasz Kaiser and Stephan Gouws and Yoshikiyo Kato and Taku Kudo and Hideto\n              Kazawa and Keith Stevens and George Kurian and Nishant Patil and Wei Wang and Cliff Young and\n              Jason Smith and Jason Riesa and Alex Rudnick and Oriol Vinyals and Greg Corrado and Macduff Hughes\n              and Jeffrey Dean},\n      year={2016},\n      eprint={1609.08144},\n      archivePrefix={arXiv},\n      primaryClass={cs.CL}\n}\n'

_UpperCamelCase							=      '\\nThe BLEU score has some undesirable properties when used for single\nsentences, as it was designed to be a corpus measure. We therefore\nuse a slightly different score for our RL experiments which we call\nthe \'GLEU score\'. For the GLEU score, we record all sub-sequences of\n1, 2, 3 or 4 tokens in output and target sequence (n-grams). We then\ncompute a recall, which is the ratio of the number of matching n-grams\nto the number of total n-grams in the target (ground truth) sequence,\nand a precision, which is the ratio of the number of matching n-grams\nto the number of total n-grams in the generated output sequence. Then\nGLEU score is simply the minimum of recall and precision. This GLEU\nscore\'s range is always between 0 (no matches) and 1 (all match) and\nit is symmetrical when switching output and target. According to\nour experiments, GLEU score correlates quite well with the BLEU\nmetric on a corpus level but does not have its drawbacks for our per\nsentence reward objective.\n'

_UpperCamelCase							=      '\\nComputes corpus-level Google BLEU (GLEU) score of translated segments against one or more references.\nInstead of averaging the sentence level GLEU scores (i.e. macro-average precision), Wu et al. (2016) sum up the matching\ntokens and the max of hypothesis and reference tokens for each sentence, then compute using the aggregate values.\n\nArgs:\n    predictions (list of str): list of translations to score.\n        Each translation should be tokenized into a list of tokens.\n    references (list of list of str): list of lists of references for each translation.\n        Each reference should be tokenized into a list of tokens.\n    min_len (int): The minimum order of n-gram this function should extract. Defaults to 1.\n    max_len (int): The maximum order of n-gram this function should extract. Defaults to 4.\n\nReturns:\n    \'google_bleu\': google_bleu score\n\nExamples:\n    Example 1:\n        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',\n        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',\n        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']\n        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',\n        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',\n        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']\n\n        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',\n        ...         \'interested\', \'in\', \'world\', \'history\']\n        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',\n        ...          \'because\', \'he\', \'read\', \'the\', \'book\']\n\n        >>> list_of_references = [[ref1a], [ref2a]]\n        >>> hypotheses = [hyp1, hyp2]\n        >>> google_bleu = datasets.load_metric("google_bleu")\n        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)\n        >>> print(round(results["google_bleu"], 2))\n        0.44\n\n    Example 2:\n        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',\n        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',\n        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']\n        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',\n        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',\n        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']\n        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',\n        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',\n        ...          \'heed\', \'the\', \'cat\', \'commands\']\n        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',\n        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',\n        ...          \'of\', \'the\', \'cat\']\n\n        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',\n        ...         \'interested\', \'in\', \'world\', \'history\']\n        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',\n        ...          \'because\', \'he\', \'read\', \'the\', \'book\']\n\n        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]\n        >>> hypotheses = [hyp1, hyp2]\n        >>> google_bleu = datasets.load_metric("google_bleu")\n        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)\n        >>> print(round(results["google_bleu"], 2))\n        0.61\n\n    Example 3:\n        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',\n        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',\n        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']\n        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',\n        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',\n        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']\n        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',\n        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',\n        ...          \'heed\', \'the\', \'cat\', \'commands\']\n        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',\n        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',\n        ...          \'of\', \'the\', \'cat\']\n\n        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',\n        ...         \'interested\', \'in\', \'world\', \'history\']\n        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',\n        ...          \'because\', \'he\', \'read\', \'the\', \'book\']\n\n        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]\n        >>> hypotheses = [hyp1, hyp2]\n        >>> google_bleu = datasets.load_metric("google_bleu")\n        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references, min_len=2)\n        >>> print(round(results["google_bleu"], 2))\n        0.53\n\n    Example 4:\n        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',\n        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',\n        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']\n        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',\n        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',\n        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']\n        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',\n        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',\n        ...          \'heed\', \'the\', \'cat\', \'commands\']\n        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',\n        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',\n        ...          \'of\', \'the\', \'cat\']\n\n        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',\n        ...         \'interested\', \'in\', \'world\', \'history\']\n        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',\n        ...          \'because\', \'he\', \'read\', \'the\', \'book\']\n\n        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]\n        >>> hypotheses = [hyp1, hyp2]\n        >>> google_bleu = datasets.load_metric("google_bleu")\n        >>> results = google_bleu.compute(predictions=hypotheses,references=list_of_references, min_len=2, max_len=6)\n        >>> print(round(results["google_bleu"], 2))\n        0.4\n'
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,  _KWARGS_DESCRIPTION   )
class 		SCREAMING_SNAKE_CASE_							(    datasets.Metric   ):
				"""simple docstring"""




				def 					__lowercase  (     self  :Optional[Any]			):
											return datasets.MetricInfo(
											    description=_DESCRIPTION						,    citation=_CITATION						,    inputs_description=_KWARGS_DESCRIPTION						,    features=datasets.Features(
											        {
											            '''predictions''': datasets.Sequence(datasets.Value('''string'''						,    id='''token'''			)						,    id='''sequence'''			),
											            '''references''': datasets.Sequence(
											                datasets.Sequence(datasets.Value('''string'''						,    id='''token'''			)						,    id='''sequence'''			)						,    id='''references'''			),
											        }			)						,    )




				def 					__lowercase  (     self  :Optional[Any]						,    __lowercase  :List[List[List[str]]]						,    __lowercase  :List[List[str]]						,    __lowercase  :int = 1						,    __lowercase  :int = 4						,    ):
											return {
											    "google_bleu": gleu_score.corpus_gleu(
											        list_of_references=__lowercase						,    hypotheses=__lowercase						,    min_len=__lowercase						,    max_len=__lowercase			)
											}




