






from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import (
     TFRoFormerForCausalLM,
     TFRoFormerForMaskedLM,
     TFRoFormerForMultipleChoice,
     TFRoFormerForQuestionAnswering,
     TFRoFormerForSequenceClassification,
     TFRoFormerForTokenClassification,
     TFRoFormerModel,
 )
 from transformers.models.roformer.modeling_tf_roformer import (
     TFRoFormerSelfAttention,
     TFRoFormerSinusoidalPositionalEmbedding,
 )



class 							_UpperCamelCase			:


      def __init__(	self					,						__UpperCamelCase					,						__UpperCamelCase=1_3					,						__UpperCamelCase=7					,						__UpperCamelCase=True					,						__UpperCamelCase=True					,						__UpperCamelCase=True					,						__UpperCamelCase=True					,						__UpperCamelCase=9_9					,						__UpperCamelCase=3_2					,						__UpperCamelCase=2					,						__UpperCamelCase=4					,						__UpperCamelCase=3_7					,						__UpperCamelCase="gelu"					,						__UpperCamelCase=0.1					,						__UpperCamelCase=0.1					,						__UpperCamelCase=5_1_2					,						__UpperCamelCase=1_6					,						__UpperCamelCase=2					,						__UpperCamelCase=0.0_2					,						__UpperCamelCase=3					,						__UpperCamelCase=4					,						__UpperCamelCase=None					,						)->	Any:
           __lowerCAmelCase								=					parent
           __lowerCAmelCase								=					1_3
           __lowerCAmelCase								=					7
           __lowerCAmelCase								=					True
           __lowerCAmelCase								=					True
           __lowerCAmelCase								=					True
           __lowerCAmelCase								=					True
           __lowerCAmelCase								=					9_9
           __lowerCAmelCase								=					3_2
           __lowerCAmelCase								=					2
           __lowerCAmelCase								=					4
           __lowerCAmelCase								=					3_7
           __lowerCAmelCase								=					"gelu"
           __lowerCAmelCase								=					0.1
           __lowerCAmelCase								=					0.1
           __lowerCAmelCase								=					5_1_2
           __lowerCAmelCase								=					1_6
           __lowerCAmelCase								=					2
           __lowerCAmelCase								=					0.0_2
           __lowerCAmelCase								=					3
           __lowerCAmelCase								=					4
           __lowerCAmelCase								=					None


      def  __UpperCAmelCase		(	self	)->	List[str]:
           __lowerCAmelCase								=					ids_tensor([self.batch_size, self.seq_length]					,						self.vocab_size	)

           __lowerCAmelCase								=					None
           if self.use_input_mask:
                __lowerCAmelCase								=					random_attention_mask([self.batch_size, self.seq_length]	)

           __lowerCAmelCase								=					None
           if self.use_token_type_ids:
                __lowerCAmelCase								=					ids_tensor([self.batch_size, self.seq_length]					,						self.type_vocab_size	)

           __lowerCAmelCase								=					None
           __lowerCAmelCase								=					None
           __lowerCAmelCase								=					None
           if self.use_labels:
                __lowerCAmelCase								=					ids_tensor([self.batch_size]					,						self.type_sequence_label_size	)
                __lowerCAmelCase								=					ids_tensor([self.batch_size, self.seq_length]					,						self.num_labels	)
                __lowerCAmelCase								=					ids_tensor([self.batch_size]					,						self.num_choices	)

           __lowerCAmelCase								=					RoFormerConfig(
               vocab_size=self.vocab_size					,						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					,						max_position_embeddings=self.max_position_embeddings					,						type_vocab_size=self.type_vocab_size					,						initializer_range=self.initializer_range					,						return_dict=__UpperCamelCase					,						)

           return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Optional[Any]:
           __lowerCAmelCase								=					TFRoFormerModel(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

           __lowerCAmelCase								=					[input_ids, input_mask]
           __lowerCAmelCase								=					model(__UpperCamelCase	)

           __lowerCAmelCase								=					model(__UpperCamelCase	)

           self.parent.assertEqual(result.last_hidden_state.shape					,						(self.batch_size, self.seq_length, self.hidden_size)	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Dict:
           __lowerCAmelCase								=					True
           __lowerCAmelCase								=					TFRoFormerForCausalLM(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{
               "input_ids": input_ids,
               "attention_mask": input_mask,
               "token_type_ids": token_type_ids,
           }
           __lowerCAmelCase								=					model(__UpperCamelCase	)["logits"]
           self.parent.assertListEqual(
               list(prediction_scores.numpy().shape	)					,						[self.batch_size, self.seq_length, self.vocab_size]	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Tuple:
           __lowerCAmelCase								=					TFRoFormerForMaskedLM(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{
               "input_ids": input_ids,
               "attention_mask": input_mask,
               "token_type_ids": token_type_ids,
           }
           __lowerCAmelCase								=					model(__UpperCamelCase	)
           self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.seq_length, self.vocab_size)	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Tuple:
           __lowerCAmelCase								=					self.num_labels
           __lowerCAmelCase								=					TFRoFormerForSequenceClassification(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{
               "input_ids": input_ids,
               "attention_mask": input_mask,
               "token_type_ids": token_type_ids,
           }

           __lowerCAmelCase								=					model(__UpperCamelCase	)
           self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.num_labels)	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Optional[int]:
           __lowerCAmelCase								=					self.num_choices
           __lowerCAmelCase								=					TFRoFormerForMultipleChoice(config=__UpperCamelCase	)
           __lowerCAmelCase								=					tf.tile(tf.expand_dims(__UpperCamelCase					,						1	)					,						(1, self.num_choices, 1)	)
           __lowerCAmelCase								=					tf.tile(tf.expand_dims(__UpperCamelCase					,						1	)					,						(1, self.num_choices, 1)	)
           __lowerCAmelCase								=					tf.tile(tf.expand_dims(__UpperCamelCase					,						1	)					,						(1, self.num_choices, 1)	)
           __lowerCAmelCase								=					{
               "input_ids": multiple_choice_inputs_ids,
               "attention_mask": multiple_choice_input_mask,
               "token_type_ids": multiple_choice_token_type_ids,
           }
           __lowerCAmelCase								=					model(__UpperCamelCase	)
           self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.num_choices)	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Tuple:
           __lowerCAmelCase								=					self.num_labels
           __lowerCAmelCase								=					TFRoFormerForTokenClassification(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{
               "input_ids": input_ids,
               "attention_mask": input_mask,
               "token_type_ids": token_type_ids,
           }
           __lowerCAmelCase								=					model(__UpperCamelCase	)
           self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.seq_length, self.num_labels)	)


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	Tuple:
           __lowerCAmelCase								=					TFRoFormerForQuestionAnswering(config=__UpperCamelCase	)
           __lowerCAmelCase								=					{
               "input_ids": input_ids,
               "attention_mask": input_mask,
               "token_type_ids": token_type_ids,
           }

           __lowerCAmelCase								=					model(__UpperCamelCase	)
           self.parent.assertEqual(result.start_logits.shape					,						(self.batch_size, self.seq_length)	)
           self.parent.assertEqual(result.end_logits.shape					,						(self.batch_size, self.seq_length)	)


      def  __UpperCAmelCase		(	self	)->	Any:
           __lowerCAmelCase								=					self.prepare_config_and_inputs()
           (
               (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, (
               __lowerCAmelCase
           )			, 
           )								=					config_and_inputs
           __lowerCAmelCase								=					{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
           return config, inputs_dict



@require_tf
class 							_UpperCamelCase			(a_							,		a_							,		unittest.TestCase			):
      snake_case_  =							(
          (
              TFRoFormerModel,
              TFRoFormerForCausalLM,
              TFRoFormerForMaskedLM,
              TFRoFormerForQuestionAnswering,
              TFRoFormerForSequenceClassification,
              TFRoFormerForTokenClassification,
              TFRoFormerForMultipleChoice,
          )
          if is_tf_available()
          else ()
      )
      snake_case_  =							(
          {
              """feature-extraction""": TFRoFormerModel,
              """fill-mask""": TFRoFormerForMaskedLM,
              """question-answering""": TFRoFormerForQuestionAnswering,
              """text-classification""": TFRoFormerForSequenceClassification,
              """text-generation""": TFRoFormerForCausalLM,
              """token-classification""": TFRoFormerForTokenClassification,
              """zero-shot""": TFRoFormerForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )

      snake_case_  =							False
      snake_case_  =							False


      def  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)->	str:
           if pipeline_test_casse_name == "TextGenerationPipelineTests":
                return True

           return False


      def  __UpperCAmelCase		(	self	)->	Union[str, Any]:
           __lowerCAmelCase								=					TFRoFormerModelTester(self	)
           __lowerCAmelCase								=					ConfigTester(self					,						config_class=__UpperCamelCase					,						hidden_size=3_7	)


      def  __UpperCAmelCase		(	self	)->	Dict:
           self.config_tester.run_common_tests()


      def  __UpperCAmelCase		(	self	)->	Optional[int]:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	Any:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	Any:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_lm_head(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	Tuple:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	str:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	str:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase	)


      def  __UpperCAmelCase		(	self	)->	Optional[Any]:
           __lowerCAmelCase								=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*__UpperCamelCase	)


      @slow
      def  __UpperCAmelCase		(	self	)->	Dict:
           __lowerCAmelCase								=					TFRoFormerModel.from_pretrained("junnyu/roformer_chinese_base"	)
           self.assertIsNotNone(__UpperCamelCase	)



@require_tf
class 							_UpperCamelCase			(unittest.TestCase			):


      @slow
      def  __UpperCAmelCase		(	self	)->	Optional[int]:
           __lowerCAmelCase								=					TFRoFormerForMaskedLM.from_pretrained("junnyu/roformer_chinese_base"	)
           __lowerCAmelCase								=					tf.constant([[0, 1, 2, 3, 4, 5]]	)
           __lowerCAmelCase								=					model(__UpperCamelCase	)[0]

           # TODO Replace vocab size
           __lowerCAmelCase								=					5_0_0_0_0

           __lowerCAmelCase								=					[1, 6, vocab_size]
           self.assertEqual(output.shape					,						__UpperCamelCase	)

           print(output[:, :3, :3]	)

           # TODO Replace values below with what was printed above.
           __lowerCAmelCase								=					tf.constant(
               [
                   [
                       [-0.1_2_0_5_3_3_4_1, -1.0_2_6_4_9_0_1, 0.2_9_2_2_1_9_4_6],
                       [-1.5_1_3_3_7_8_3, 0.1_9_7_4_3_3, 0.1_5_1_9_0_6_0_7],
                       [-5.0_1_3_5_4_0_3, -3.9_0_0_2_5_6, -0.8_4_0_3_8_7_6_4],
                   ]
               ]	)
           tf.debugging.assert_near(output[:, :3, :3]					,						__UpperCamelCase					,						atol=1e-4	)



@require_tf
class 							_UpperCamelCase			(unittest.TestCase			):
      snake_case_  =							1E-4


      def  __UpperCAmelCase		(	self	)->	List[str]:
           __lowerCAmelCase								=					tf.constant([[4, 1_0]]	)
           __lowerCAmelCase								=					TFRoFormerSinusoidalPositionalEmbedding(num_positions=6					,						embedding_dim=6	)

           __lowerCAmelCase								=					emba(input_ids.shape	)
           __lowerCAmelCase								=					tf.constant(
               [[0.0_0_0_0, 0.0_0_0_0, 0.0_0_0_0, 1.0_0_0_0, 1.0_0_0_0, 1.0_0_0_0], [0.8_4_1_5, 0.0_4_6_4, 0.0_0_2_2, 0.5_4_0_3, 0.9_9_8_9, 1.0_0_0_0]]	)

           tf.debugging.assert_near(__UpperCamelCase					,						__UpperCamelCase					,						atol=self.tolerance	)


      def  __UpperCAmelCase		(	self	)->	Optional[Any]:
           __lowerCAmelCase								=					tf.constant(
               [
                   [0.0_0_0_0, 0.0_0_0_0, 0.0_0_0_0, 0.0_0_0_0, 0.0_0_0_0],
                   [0.8_4_1_5, 0.8_2_1_9, 0.8_0_2_0, 0.7_8_1_9, 0.7_6_1_7],
                   [0.9_0_9_3, 0.9_3_6_4, 0.9_5_8_1, 0.9_7_4_9, 0.9_8_7_0],
               ]	)
           __lowerCAmelCase								=					TFRoFormerSinusoidalPositionalEmbedding(num_positions=5_1_2					,						embedding_dim=5_1_2	)
           emba([2, 1_6, 5_1_2]	)
           __lowerCAmelCase								=					emba.weight[:3, :5]

           tf.debugging.assert_near(__UpperCamelCase					,						__UpperCamelCase					,						atol=self.tolerance	)



@require_tf
class 							_UpperCamelCase			(unittest.TestCase			):
      snake_case_  =							1E-4


      def  __UpperCAmelCase		(	self	)->	Optional[Any]:
           # 2,12,16,64
           __lowerCAmelCase								=					tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4					,						dtype=tf.floataa	)					,						shape=(2, 1_2, 1_6, 6_4)	) / 1_0_0

           __lowerCAmelCase								=					-tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4					,						dtype=tf.floataa	)					,						shape=(2, 1_2, 1_6, 6_4)	) / 1_0_0

           __lowerCAmelCase								=					TFRoFormerSinusoidalPositionalEmbedding(num_positions=3_2					,						embedding_dim=6_4	)
           __lowerCAmelCase								=					embed_positions([2, 1_6, 7_6_8]	)[None, None, :, :]

           __lowerCAmelCase			, __lowerCAmelCase								=					TFRoFormerSelfAttention.apply_rotary_position_embeddings(
               __UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase	)

           __lowerCAmelCase								=					tf.constant(
               [
                   [0.0_0_0_0, 0.0_1_0_0, 0.0_2_0_0, 0.0_3_0_0, 0.0_4_0_0, 0.0_5_0_0, 0.0_6_0_0, 0.0_7_0_0],
                   [-0.2_0_1_2, 0.8_8_9_7, 0.0_2_6_3, 0.9_4_0_1, 0.2_0_7_4, 0.9_4_6_3, 0.3_4_8_1, 0.9_3_4_3],
                   [-1.7_0_5_7, 0.6_2_7_1, -1.2_1_4_5, 1.3_8_9_7, -0.6_3_0_3, 1.7_6_4_7, -0.1_1_7_3, 1.8_9_8_5],
                   [-2.1_7_3_1, -1.6_3_9_7, -2.7_3_5_8, 0.2_8_5_4, -2.1_8_4_0, 1.7_1_8_3, -1.3_0_1_8, 2.4_8_7_1],
                   [0.2_7_1_7, -3.6_1_7_3, -2.9_2_0_6, -2.1_9_8_8, -3.6_6_3_8, 0.3_8_5_8, -2.9_1_5_5, 2.2_9_8_0],
                   [3.9_8_5_9, -2.1_5_8_0, -0.7_9_8_4, -4.4_9_0_4, -4.1_1_8_1, -2.0_2_5_2, -4.4_7_8_2, 1.1_2_5_3],
               ]	)
           __lowerCAmelCase								=					tf.constant(
               [
                   [0.0_0_0_0, -0.0_1_0_0, -0.0_2_0_0, -0.0_3_0_0, -0.0_4_0_0, -0.0_5_0_0, -0.0_6_0_0, -0.0_7_0_0],
                   [0.2_0_1_2, -0.8_8_9_7, -0.0_2_6_3, -0.9_4_0_1, -0.2_0_7_4, -0.9_4_6_3, -0.3_4_8_1, -0.9_3_4_3],
                   [1.7_0_5_7, -0.6_2_7_1, 1.2_1_4_5, -1.3_8_9_7, 0.6_3_0_3, -1.7_6_4_7, 0.1_1_7_3, -1.8_9_8_5],
                   [2.1_7_3_1, 1.6_3_9_7, 2.7_3_5_8, -0.2_8_5_4, 2.1_8_4_0, -1.7_1_8_3, 1.3_0_1_8, -2.4_8_7_1],
                   [-0.2_7_1_7, 3.6_1_7_3, 2.9_2_0_6, 2.1_9_8_8, 3.6_6_3_8, -0.3_8_5_8, 2.9_1_5_5, -2.2_9_8_0],
                   [-3.9_8_5_9, 2.1_5_8_0, 0.7_9_8_4, 4.4_9_0_4, 4.1_1_8_1, 2.0_2_5_2, 4.4_7_8_2, -1.1_2_5_3],
               ]	)

           tf.debugging.assert_near(query_layer[0, 0, :6, :8]					,						__UpperCamelCase					,						atol=self.tolerance	)
           tf.debugging.assert_near(key_layer[0, 0, :6, :8]					,						__UpperCamelCase					,						atol=self.tolerance	)














from typing import Dict, List

from nltk.translate import gleu_score

import datasets
from datasets import MetricInfo


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

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

lowerCamelCase			:					List[str]         =	'''\
Computes corpus-level Google BLEU (GLEU) score of translated segments against one or more references.
Instead of averaging the sentence level GLEU scores (i.e. macro-average precision), Wu et al. (2016) sum up the matching
tokens and the max of hypothesis and reference tokens for each sentence, then compute using the aggregate values.

Args:
    predictions (list of str): list of translations to score.
        Each translation should be tokenized into a list of tokens.
    references (list of list of str): list of lists of references for each translation.
        Each reference should be tokenized into a list of tokens.
    min_len (int): The minimum order of n-gram this function should extract. Defaults to 1.
    max_len (int): The maximum order of n-gram this function should extract. Defaults to 4.

Returns:
    \'google_bleu\': google_bleu score

Examples:
    Example 1:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)
        >>> print(round(results["google_bleu"], 2))
        0.44

    Example 2:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references)
        >>> print(round(results["google_bleu"], 2))
        0.61

    Example 3:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses, references=list_of_references, min_len=2)
        >>> print(round(results["google_bleu"], 2))
        0.53

    Example 4:
        >>> hyp1 = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'which\',
        ...         \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'always\',
        ...         \'disobeys\', \'the\', \'commands\', \'of\', \'the\', \'cat\']
        >>> ref1a = [\'It\', \'is\', \'the\', \'guiding\', \'principle\', \'which\',
        ...          \'guarantees\', \'the\', \'rubber\', \'duck\', \'forces\', \'never\',
        ...          \'being\', \'under\', \'the\', \'command\', \'of\', \'the\', \'cat\']
        >>> ref1b = [\'It\', \'is\', \'a\', \'guide\', \'to\', \'action\', \'that\',
        ...          \'ensures\', \'that\', \'the\', \'rubber\', \'duck\', \'will\', \'never\',
        ...          \'heed\', \'the\', \'cat\', \'commands\']
        >>> ref1c = [\'It\', \'is\', \'the\', \'practical\', \'guide\', \'for\', \'the\',
        ...          \'rubber\', \'duck\', \'army\', \'never\', \'to\', \'heed\', \'the\', \'directions\',
        ...          \'of\', \'the\', \'cat\']

        >>> hyp2 = [\'he\', \'read\', \'the\', \'book\', \'because\', \'he\', \'was\',
        ...         \'interested\', \'in\', \'world\', \'history\']
        >>> ref2a = [\'he\', \'was\', \'interested\', \'in\', \'world\', \'history\',
        ...          \'because\', \'he\', \'read\', \'the\', \'book\']

        >>> list_of_references = [[ref1a, ref1b, ref1c], [ref2a]]
        >>> hypotheses = [hyp1, hyp2]
        >>> google_bleu = datasets.load_metric("google_bleu")
        >>> results = google_bleu.compute(predictions=hypotheses,references=list_of_references, min_len=2, max_len=6)
        >>> print(round(results["google_bleu"], 2))
        0.4
'''



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


      def  __UpperCAmelCase		(	self	)->	MetricInfo:
           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  __UpperCAmelCase		(	self					,						__UpperCamelCase					,						__UpperCamelCase					,						__UpperCamelCase = 1					,						__UpperCamelCase = 4					,						)->	Dict[str, float]:
           return {
               "google_bleu": gleu_score.corpus_gleu(
                   list_of_references=__UpperCamelCase					,						hypotheses=__UpperCamelCase					,						min_len=__UpperCamelCase					,						max_len=__UpperCamelCase	)
           }






