


'''simple docstring'''


import inspect
import unittest

from transformers import YolosConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch
						from torch import nn

						from transformers import YolosForObjectDetection, YolosModel
						from transformers.models.yolos.modeling_yolos import YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor






class 		lowerCAmelCase__	:




			def __init__(						self     :   Tuple		,     lowerCamelCase__     :   Tuple		,     lowerCamelCase__     :   Union[str, Any]=13		,     lowerCamelCase__     :   Any=[30, 30]		,     lowerCamelCase__     :   List[str]=2		,     lowerCamelCase__     :   List[Any]=3		,     lowerCamelCase__     :   str=True		,     lowerCamelCase__     :   int=True		,     lowerCamelCase__     :   Tuple=32		,     lowerCamelCase__     :   int=5		,     lowerCamelCase__     :   Union[str, Any]=4		,     lowerCamelCase__     :   Optional[Any]=37		,     lowerCamelCase__     :   Tuple="gelu"		,     lowerCamelCase__     :   Dict=0.1		,     lowerCamelCase__     :   int=0.1		,     lowerCamelCase__     :   int=10		,     lowerCamelCase__     :   Optional[int]=0.0_2		,     lowerCamelCase__     :   Dict=3		,     lowerCamelCase__     :   List[Any]=None		,     lowerCamelCase__     :   Optional[Any]=8		,     lowerCamelCase__     :   Any=10		,     )      ->Optional[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				int	    =					parent
					_UpperCAmelCase						:				Optional[int]	    =					batch_size
					_UpperCAmelCase						:				Optional[int]	    =					image_size
					_UpperCAmelCase						:				Dict	    =					patch_size
					_UpperCAmelCase						:				Optional[Any]	    =					num_channels
					_UpperCAmelCase						:				List[Any]	    =					is_training
					_UpperCAmelCase						:				Tuple	    =					use_labels
					_UpperCAmelCase						:				Dict	    =					hidden_size
					_UpperCAmelCase						:				Optional[int]	    =					num_hidden_layers
					_UpperCAmelCase						:				Any	    =					num_attention_heads
					_UpperCAmelCase						:				Optional[Any]	    =					intermediate_size
					_UpperCAmelCase						:				Any	    =					hidden_act
					_UpperCAmelCase						:				Any	    =					hidden_dropout_prob
					_UpperCAmelCase						:				str	    =					attention_probs_dropout_prob
					_UpperCAmelCase						:				List[str]	    =					type_sequence_label_size
					_UpperCAmelCase						:				Optional[int]	    =					initializer_range
					_UpperCAmelCase						:				str	    =					num_labels
					_UpperCAmelCase						:				str	    =					scope
					_UpperCAmelCase						:				Dict	    =					n_targets
					_UpperCAmelCase						:				List[Any]	    =					num_detection_tokens
					# we set the expected sequence length (which is used in several tests)
					# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token) + num_detection_tokens
					_UpperCAmelCase						:				Any	    =					(image_size[1] // patch_size) * (image_size[0] // patch_size)
					_UpperCAmelCase						:				Optional[int]	    =					num_patches + 1 + self.num_detection_tokens




			def 							lowerCAmelCase__			(						self     :   Any       )      ->List[Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Optional[int]	    =					floats_tensor([self.batch_size, self.num_channels, self.image_size[0], self.image_size[1]]       )

					_UpperCAmelCase						:				Any	    =					None
					if self.use_labels:
							# labels is a list of Dict (each Dict being the labels for a given example in the batch)
							_UpperCAmelCase						:				Union[str, Any]	    =					[]
							for i in range(self.batch_size       ):
									_UpperCAmelCase						:				Any	    =					{}
									_UpperCAmelCase						:				Dict	    =					torch.randint(
									    high=self.num_labels		,     size=(self.n_targets,)		,     device=lowerCamelCase__       )
									_UpperCAmelCase						:				Any	    =					torch.rand(self.n_targets		,     4		,     device=lowerCamelCase__       )
									labels.append(lowerCamelCase__       )

					_UpperCAmelCase						:				Optional[int]	    =					self.get_config()

					return config, pixel_values, labels




			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->int:



					'''simple docstring'''







					return YolosConfig(
					    image_size=self.image_size		,     patch_size=self.patch_size		,     num_channels=self.num_channels		,     hidden_size=self.hidden_size		,     num_hidden_layers=self.num_hidden_layers		,     num_attention_heads=self.num_attention_heads		,     intermediate_size=self.intermediate_size		,     hidden_act=self.hidden_act		,     hidden_dropout_prob=self.hidden_dropout_prob		,     attention_probs_dropout_prob=self.attention_probs_dropout_prob		,     is_decoder=lowerCamelCase__		,     initializer_range=self.initializer_range		,     num_detection_tokens=self.num_detection_tokens		,     num_labels=self.num_labels		,     )




			def 							lowerCAmelCase__			(						self     :   List[Any]		,     lowerCamelCase__     :   List[Any]		,     lowerCamelCase__     :   int		,     lowerCamelCase__     :   Optional[int]       )      ->Any:



					'''simple docstring'''







					_UpperCAmelCase						:				str	    =					YolosModel(config=lowerCamelCase__       )
					model.to(lowerCamelCase__       )
					model.eval()
					_UpperCAmelCase						:				List[str]	    =					model(lowerCamelCase__       )
					self.parent.assertEqual(
					    result.last_hidden_state.shape		,     (self.batch_size, self.expected_seq_len, self.hidden_size)       )




			def 							lowerCAmelCase__			(						self     :   int		,     lowerCamelCase__     :   Dict		,     lowerCamelCase__     :   str		,     lowerCamelCase__     :   List[Any]       )      ->str:



					'''simple docstring'''







					_UpperCAmelCase						:				Dict	    =					YolosForObjectDetection(lowerCamelCase__       )
					model.to(lowerCamelCase__       )
					model.eval()

					_UpperCAmelCase						:				Optional[Any]	    =					model(pixel_values=lowerCamelCase__       )
					_UpperCAmelCase						:				int	    =					model(lowerCamelCase__       )

					self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_detection_tokens, self.num_labels + 1)       )
					self.parent.assertEqual(result.pred_boxes.shape		,     (self.batch_size, self.num_detection_tokens, 4)       )

					_UpperCAmelCase						:				Any	    =					model(pixel_values=lowerCamelCase__		,     labels=lowerCamelCase__       )

					self.parent.assertEqual(result.loss.shape		,     ()       )
					self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.num_detection_tokens, self.num_labels + 1)       )
					self.parent.assertEqual(result.pred_boxes.shape		,     (self.batch_size, self.num_detection_tokens, 4)       )






			def 							lowerCAmelCase__			(						self     :   List[str]       )      ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase						:				int	    =					self.prepare_config_and_inputs()
					_UpperCAmelCase    ,			_UpperCAmelCase    ,			_UpperCAmelCase						:				Optional[Any]	    =					config_and_inputs
					_UpperCAmelCase						:				Dict	    =					{"pixel_values": pixel_values}
					return config, inputs_dict






@require_torch
class 		lowerCAmelCase__	(	UpperCAmelCase__			,				UpperCAmelCase__			,				unittest.TestCase		):
			lowerCAmelCase       :		Dict				      =   (YolosModel, YolosForObjectDetection) if is_torch_available() else ()
			lowerCAmelCase       :		int				      =   (
			    {"feature-extraction": YolosModel, "object-detection": YolosForObjectDetection} if is_torch_available() else {}
			)

			lowerCAmelCase       :		Any				      =   False
			lowerCAmelCase       :		Any				      =   False
			lowerCAmelCase       :		int				      =   False
			lowerCAmelCase       :		List[str]				      =   False




			def 							lowerCAmelCase__			(						self     :   Optional[Any]		,     lowerCamelCase__     :   int		,     lowerCamelCase__     :   Optional[Any]		,     lowerCamelCase__     :   Union[str, Any]=False       )      ->List[str]:



					'''simple docstring'''







					_UpperCAmelCase						:				Union[str, Any]	    =					super()._prepare_for_class(lowerCamelCase__		,     lowerCamelCase__		,     return_labels=lowerCamelCase__       )

					if return_labels:
							if model_class.__name__ == "YolosForObjectDetection":
									_UpperCAmelCase						:				Tuple	    =					[]
									for i in range(self.model_tester.batch_size       ):
											_UpperCAmelCase						:				Any	    =					{}
											_UpperCAmelCase						:				Optional[Any]	    =					torch.ones(
											    size=(self.model_tester.n_targets,)		,     device=lowerCamelCase__		,     dtype=torch.long       )
											_UpperCAmelCase						:				Optional[int]	    =					torch.ones(
											    self.model_tester.n_targets		,     4		,     device=lowerCamelCase__		,     dtype=torch.float       )
											labels.append(lowerCamelCase__       )
									_UpperCAmelCase						:				Dict	    =					labels

					return inputs_dict




			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase						:				int	    =					YolosModelTester(self       )
					_UpperCAmelCase						:				Any	    =					ConfigTester(self		,     config_class=lowerCamelCase__		,     has_text_modality=lowerCamelCase__		,     hidden_size=37       )




			def 							lowerCAmelCase__			(						self     :   int       )      ->Tuple:



					'''simple docstring'''







					self.config_tester.run_common_tests()




			def 							lowerCAmelCase__			(						self     :   Union[str, Any]       )      ->str:



					'''simple docstring'''







					pass




			def 							lowerCAmelCase__			(						self     :   Any       )      ->int:



					'''simple docstring'''







					_UpperCAmelCase    ,			_UpperCAmelCase						:				Dict	    =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							_UpperCAmelCase						:				int	    =					model_class(lowerCamelCase__       )
							self.assertIsInstance(model.get_input_embeddings()		,     (nn.Module)       )
							_UpperCAmelCase						:				Optional[Any]	    =					model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(lowerCamelCase__		,     nn.Linear       )       )




			def 							lowerCAmelCase__			(						self     :   Union[str, Any]       )      ->Dict:



					'''simple docstring'''







					_UpperCAmelCase    ,			_UpperCAmelCase						:				Dict	    =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							_UpperCAmelCase						:				Any	    =					model_class(lowerCamelCase__       )
							_UpperCAmelCase						:				str	    =					inspect.signature(model.forward       )
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							_UpperCAmelCase						:				int	    =					[*signature.parameters.keys()]

							_UpperCAmelCase						:				List[str]	    =					["pixel_values"]
							self.assertListEqual(arg_names[:1]		,     lowerCamelCase__       )




			def 							lowerCAmelCase__			(						self     :   Optional[Any]       )      ->str:



					'''simple docstring'''







					_UpperCAmelCase						:				List[str]	    =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCamelCase__       )




			def 							lowerCAmelCase__			(						self     :   List[Any]       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase    ,			_UpperCAmelCase						:				int	    =					self.model_tester.prepare_config_and_inputs_for_common()
					_UpperCAmelCase						:				Dict	    =					True

					# in YOLOS, the seq_len is different
					_UpperCAmelCase						:				int	    =					self.model_tester.expected_seq_len
					for model_class in self.all_model_classes:
							_UpperCAmelCase						:				str	    =					True
							_UpperCAmelCase						:				Union[str, Any]	    =					False
							_UpperCAmelCase						:				List[Any]	    =					True
							_UpperCAmelCase						:				List[str]	    =					model_class(lowerCamelCase__       )
							model.to(lowerCamelCase__       )
							model.eval()
							with torch.no_grad():
									_UpperCAmelCase						:				Optional[int]	    =					model(**self._prepare_for_class(lowerCamelCase__		,     lowerCamelCase__       )       )
							_UpperCAmelCase						:				List[Any]	    =					outputs.attentions
							self.assertEqual(len(lowerCamelCase__       )		,     self.model_tester.num_hidden_layers       )

							# check that output_attentions also work using config
							del inputs_dict["output_attentions"]
							_UpperCAmelCase						:				Dict	    =					True
							_UpperCAmelCase						:				Any	    =					model_class(lowerCamelCase__       )
							model.to(lowerCamelCase__       )
							model.eval()
							with torch.no_grad():
									_UpperCAmelCase						:				Union[str, Any]	    =					model(**self._prepare_for_class(lowerCamelCase__		,     lowerCamelCase__       )       )
							_UpperCAmelCase						:				Union[str, Any]	    =					outputs.attentions
							self.assertEqual(len(lowerCamelCase__       )		,     self.model_tester.num_hidden_layers       )

							self.assertListEqual(
							    list(attentions[0].shape[-3:]       )		,     [self.model_tester.num_attention_heads, seq_len, seq_len]		,     )
							_UpperCAmelCase						:				Optional[int]	    =					len(lowerCamelCase__       )

							# Check attention is always last and order is fine
							_UpperCAmelCase						:				Optional[int]	    =					True
							_UpperCAmelCase						:				Dict	    =					True
							_UpperCAmelCase						:				int	    =					model_class(lowerCamelCase__       )
							model.to(lowerCamelCase__       )
							model.eval()
							with torch.no_grad():
									_UpperCAmelCase						:				str	    =					model(**self._prepare_for_class(lowerCamelCase__		,     lowerCamelCase__       )       )

							_UpperCAmelCase						:				str	    =					1
							self.assertEqual(out_len + added_hidden_states		,     len(lowerCamelCase__       )       )

							_UpperCAmelCase						:				Union[str, Any]	    =					outputs.attentions

							self.assertEqual(len(lowerCamelCase__       )		,     self.model_tester.num_hidden_layers       )
							self.assertListEqual(
							    list(self_attentions[0].shape[-3:]       )		,     [self.model_tester.num_attention_heads, seq_len, seq_len]		,     )




			def 							lowerCAmelCase__			(						self     :   Any       )      ->str:



					'''simple docstring'''







					def check_hidden_states_output(lowerCamelCase__     :   int		,     lowerCamelCase__     :   Dict		,     lowerCamelCase__     :   int       ):
							_UpperCAmelCase						:				str	    =					model_class(lowerCamelCase__       )
							model.to(lowerCamelCase__       )
							model.eval()

							with torch.no_grad():
									_UpperCAmelCase						:				List[Any]	    =					model(**self._prepare_for_class(lowerCamelCase__		,     lowerCamelCase__       )       )

							_UpperCAmelCase						:				Union[str, Any]	    =					outputs.hidden_states

							_UpperCAmelCase						:				int	    =					getattr(
							    self.model_tester		,     "expected_num_hidden_layers"		,     self.model_tester.num_hidden_layers + 1       )
							self.assertEqual(len(lowerCamelCase__       )		,     lowerCamelCase__       )

							# YOLOS has a different seq_length
							_UpperCAmelCase						:				Union[str, Any]	    =					self.model_tester.expected_seq_len

							self.assertListEqual(
							    list(hidden_states[0].shape[-2:]       )		,     [seq_length, self.model_tester.hidden_size]		,     )

					_UpperCAmelCase    ,			_UpperCAmelCase						:				str	    =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							_UpperCAmelCase						:				Optional[Any]	    =					True
							check_hidden_states_output(lowerCamelCase__		,     lowerCamelCase__		,     lowerCamelCase__       )

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							_UpperCAmelCase						:				Optional[int]	    =					True

							check_hidden_states_output(lowerCamelCase__		,     lowerCamelCase__		,     lowerCamelCase__       )




			def 							lowerCAmelCase__			(						self     :   Optional[int]       )      ->Dict:



					'''simple docstring'''







					_UpperCAmelCase						:				List[Any]	    =					self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_object_detection(*lowerCamelCase__       )






			@slow
			def 							lowerCAmelCase__			(						self     :   List[str]       )      ->Any:



					'''simple docstring'''







					for model_name in YOLOS_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							_UpperCAmelCase						:				List[str]	    =					YolosModel.from_pretrained(lowerCamelCase__       )
							self.assertIsNotNone(lowerCamelCase__       )






def        __lowerCAmelCase       ():
		_UpperCAmelCase						:				int	    =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"      )
		return image






@require_torch
@require_vision
class 		lowerCAmelCase__	(	unittest.TestCase		):




			@cached_property
			def 							lowerCAmelCase__			(						self     :   Tuple       )      ->str:



					'''simple docstring'''







					return AutoImageProcessor.from_pretrained("hustvl/yolos-small"       ) if is_vision_available() else None






			@slow
			def 							lowerCAmelCase__			(						self     :   Tuple       )      ->Union[str, Any]:



					'''simple docstring'''







					_UpperCAmelCase						:				Any	    =					YolosForObjectDetection.from_pretrained("hustvl/yolos-small"       ).to(lowerCamelCase__       )

					_UpperCAmelCase						:				Dict	    =					self.default_image_processor
					_UpperCAmelCase						:				Union[str, Any]	    =					prepare_img()
					_UpperCAmelCase						:				str	    =					image_processor(images=lowerCamelCase__		,     return_tensors="pt"       ).to(lowerCamelCase__       )

					# forward pass
					with torch.no_grad():
							_UpperCAmelCase						:				Dict	    =					model(inputs.pixel_values       )

					# verify outputs
					_UpperCAmelCase						:				List[str]	    =					torch.Size((1, 1_00, 92)       )
					self.assertEqual(outputs.logits.shape		,     lowerCamelCase__       )

					_UpperCAmelCase						:				List[Any]	    =					torch.tensor(
					    [[-2_4.0_2_4_8, -1_0.3_0_2_4, -1_4.8_2_9_0], [-4_2.0_3_9_2, -1_6.8_2_0_0, -2_7.4_3_3_4], [-2_7.2_7_4_3, -1_1.8_1_5_4, -1_8.7_1_4_8]]		,     device=lowerCamelCase__		,     )
					_UpperCAmelCase						:				str	    =					torch.tensor(
					    [[0.2_5_5_9, 0.5_4_5_5, 0.4_7_0_6], [0.2_9_8_9, 0.7_2_7_9, 0.1_8_7_5], [0.7_7_3_2, 0.4_0_1_7, 0.4_4_6_2]]		,     device=lowerCamelCase__       )
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3]		,     lowerCamelCase__		,     atol=1E-4       )       )
					self.assertTrue(torch.allclose(outputs.pred_boxes[0, :3, :3]		,     lowerCamelCase__		,     atol=1E-4       )       )

					# verify postprocessing
					_UpperCAmelCase						:				Any	    =					image_processor.post_process_object_detection(
					    lowerCamelCase__		,     threshold=0.3		,     target_sizes=[image.size[::-1]]       )[0]
					_UpperCAmelCase						:				Tuple	    =					torch.tensor([0.9_9_9_4, 0.9_7_9_0, 0.9_9_6_4, 0.9_9_7_2, 0.9_8_6_1]       ).to(lowerCamelCase__       )
					_UpperCAmelCase						:				Any	    =					[75, 75, 17, 63, 17]
					_UpperCAmelCase						:				Any	    =					torch.tensor([3_3_5.0_6_0_9, 7_9.3_8_4_8, 3_7_5.4_2_1_6, 1_8_7.2_4_9_5]       ).to(lowerCamelCase__       )

					self.assertEqual(len(results["scores"]       )		,     5       )
					self.assertTrue(torch.allclose(results["scores"]		,     lowerCamelCase__		,     atol=1E-4       )       )
					self.assertSequenceEqual(results["labels"].tolist()		,     lowerCamelCase__       )
					self.assertTrue(torch.allclose(results["boxes"][0, :]		,     lowerCamelCase__       )       )







'''simple docstring'''


from typing import Dict, List

from nltk.translate import gleu_score

import datasets
from datasets import MetricInfo


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

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

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




			def 							lowerCAmelCase__			(						self     :   int       )      ->MetricInfo:



					'''simple docstring'''







					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 							lowerCAmelCase__			(						self     :   Dict		,     lowerCamelCase__     :   List[List[List[str]]]		,     lowerCamelCase__     :   List[List[str]]		,     lowerCamelCase__     :   int = 1		,     lowerCamelCase__     :   int = 4		,     )      ->Dict[str, float]:



					'''simple docstring'''







					return {
					    "google_bleu": gleu_score.corpus_gleu(
					        list_of_references=lowerCamelCase__		,     hypotheses=lowerCamelCase__		,     min_len=lowerCamelCase__		,     max_len=lowerCamelCase__       )
					}



