
"""simple docstring"""



import numpy as np
from nltk.translate import meteor_score

import datasets
from datasets.config import importlib_metadata, version


UpperCAmelCase__        =					version.parse(importlib_metadata.version('nltk'))
if NLTK_VERSION >= version.Version('3.6.4'):
 from nltk import word_tokenize


UpperCAmelCase__        =					"\\n@inproceedings{banarjee2005,\n  title     = {{METEOR}: An Automatic Metric for {MT} Evaluation with Improved Correlation with Human Judgments},\n  author    = {Banerjee, Satanjeev  and Lavie, Alon},\n  booktitle = {Proceedings of the {ACL} Workshop on Intrinsic and Extrinsic Evaluation Measures for Machine Translation and/or Summarization},\n  month     = jun,\n  year      = {2005},\n  address   = {Ann Arbor, Michigan},\n  publisher = {Association for Computational Linguistics},\n  url       = {https://www.aclweb.org/anthology/W05-0909},\n  pages     = {65--72},\n}\n"

UpperCAmelCase__        =					"\\nMETEOR, an automatic metric for machine translation evaluation\nthat is based on a generalized concept of unigram matching between the\nmachine-produced translation and human-produced reference translations.\nUnigrams can be matched based on their surface forms, stemmed forms,\nand meanings; furthermore, METEOR can be easily extended to include more\nadvanced matching strategies. Once all generalized unigram matches\nbetween the two strings have been found, METEOR computes a score for\nthis matching using a combination of unigram-precision, unigram-recall, and\na measure of fragmentation that is designed to directly capture how\nwell-ordered the matched words in the machine translation are in relation\nto the reference.\n\nMETEOR gets an R correlation value of 0.347 with human evaluation on the Arabic\ndata and 0.331 on the Chinese data. This is shown to be an improvement on\nusing simply unigram-precision, unigram-recall and their harmonic F1\ncombination.\n"

UpperCAmelCase__        =					"\nComputes METEOR score of translated segments against one or more references.\nArgs:\n    predictions: list of predictions to score. Each prediction\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.\n    alpha: Parameter for controlling relative weights of precision and recall. default: 0.9\n    beta: Parameter for controlling shape of penalty as a function of fragmentation. default: 3\n    gamma: Relative weight assigned to fragmentation penalty. default: 0.5\nReturns:\n    'meteor': meteor score.\nExamples:\n\n    >>> meteor = datasets.load_metric('meteor')\n    >>> predictions = [\"It is a guide to action which ensures that the military always obeys the commands of the party\"]\n    >>> references = [\"It is a guide to action that ensures that the military will forever heed Party commands\"]\n    >>> results = meteor.compute(predictions=predictions, references=references)\n    >>> print(round(results[\"meteor\"], 4))\n    0.6944\n"

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







     def 	lowercase      (				self     :     Union[str, Any]     ):
       return datasets.MetricInfo(
           description=_DESCRIPTION       , citation=_CITATION       , inputs_description=_KWARGS_DESCRIPTION       , features=datasets.Features(
               {
                   '''predictions''': datasets.Value('''string'''       , id='''sequence'''     ),
                   '''references''': datasets.Value('''string'''       , id='''sequence'''     ),
               }     )       , codebase_urls=['''https://github.com/nltk/nltk/blob/develop/nltk/translate/meteor_score.py''']       , reference_urls=[
               '''https://www.nltk.org/api/nltk.translate.html#module-nltk.translate.meteor_score''',
               '''https://en.wikipedia.org/wiki/METEOR''',
           ]       , )







     def 	lowercase      (				self     :     Optional[Any]       , _lowerCamelCase     :     List[Any]     ):
       import nltk

       nltk.download('''wordnet'''     )
       if NLTK_VERSION >= version.Version('''3.6.5'''     ):
         nltk.download('''punkt'''     )
       if NLTK_VERSION >= version.Version('''3.6.6'''     ):
         nltk.download('''omw-1.4'''     )







     def 	lowercase      (				self     :     str       , _lowerCamelCase     :     Optional[Any]       , _lowerCamelCase     :     Dict       , _lowerCamelCase     :     int=0.9       , _lowerCamelCase     :     int=3       , _lowerCamelCase     :     Optional[Any]=0.5     ):
       if NLTK_VERSION >= version.Version('''3.6.5'''     ):
         _snake_case   	=			[
             meteor_score.single_meteor_score(
                 word_tokenize(__UpperCAmelCase     )       , word_tokenize(__UpperCAmelCase     )       , alpha=__UpperCAmelCase       , beta=__UpperCAmelCase       , gamma=__UpperCAmelCase     )
             for ref, pred in zip(__UpperCAmelCase       , __UpperCAmelCase     )
         ]
       else:
         _snake_case   	=			[
             meteor_score.single_meteor_score(__UpperCAmelCase       , __UpperCAmelCase       , alpha=__UpperCAmelCase       , beta=__UpperCAmelCase       , gamma=__UpperCAmelCase     )
             for ref, pred in zip(__UpperCAmelCase       , __UpperCAmelCase     )
         ]

       return {"meteor": np.mean(__UpperCAmelCase     )}






from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
		    TFFunnelBaseModel,
		    TFFunnelForMaskedLM,
		    TFFunnelForMultipleChoice,
		    TFFunnelForPreTraining,
		    TFFunnelForQuestionAnswering,
		    TFFunnelForSequenceClassification,
		    TFFunnelForTokenClassification,
		    TFFunnelModel,
		)







class 					__lowercase  :





							"""simple docstring"""

							def __init__(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase=13    ,						__UpperCAmelCase=7    ,						__UpperCAmelCase=True    ,						__UpperCAmelCase=True    ,						__UpperCAmelCase=True    ,						__UpperCAmelCase=True    ,						__UpperCAmelCase=99    ,						__UpperCAmelCase=[1, 1, 2]    ,						__UpperCAmelCase=1    ,						__UpperCAmelCase=32    ,						__UpperCAmelCase=4    ,						__UpperCAmelCase=8    ,						__UpperCAmelCase=37    ,						__UpperCAmelCase="gelu_new"    ,						__UpperCAmelCase=0.1    ,						__UpperCAmelCase=0.1    ,						__UpperCAmelCase=0.0    ,						__UpperCAmelCase=5_12    ,						__UpperCAmelCase=3    ,						__UpperCAmelCase=0.0_2    ,						__UpperCAmelCase=3    ,						__UpperCAmelCase=4    ,						__UpperCAmelCase=None    ,						__UpperCAmelCase=False    ,						)		->       Tuple:
														A      :					Optional[int]      		=					parent
														A      :					int      		=					batch_size
														A      :					Union[str, Any]      		=					seq_length
														A      :					Optional[Any]      		=					is_training
														A      :					int      		=					use_input_mask
														A      :					List[Any]      		=					use_token_type_ids
														A      :					Optional[int]      		=					use_labels
														A      :					List[Any]      		=					vocab_size
														A      :					int      		=					block_sizes
														A      :					Optional[int]      		=					num_decoder_layers
														A      :					int      		=					d_model
														A      :					Dict      		=					n_head
														A      :					Tuple      		=					d_head
														A      :					int      		=					d_inner
														A      :					Tuple      		=					hidden_act
														A      :					Tuple      		=					hidden_dropout
														A      :					Any      		=					attention_dropout
														A      :					Any      		=					activation_dropout
														A      :					List[Any]      		=					max_position_embeddings
														A      :					int      		=					type_vocab_size
														A      :					Dict      		=					2
														A      :					List[str]      		=					num_labels
														A      :					Optional[int]      		=					num_choices
														A      :					int      		=					scope
														A      :					int      		=					initializer_std

														# Used in the tests to check the size of the first attention layer
														A      :					Optional[int]      		=					n_head
														# Used in the tests to check the size of the first hidden state
														A      :					List[Any]      		=					self.d_model
														# Used in the tests to check the number of output hidden states/attentions
														A      :					Dict      		=					sum(self.block_sizes						) + (0 if base else self.num_decoder_layers)
														# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
														# the last hidden state of the first block (which is the first hidden state of the decoder).
														if not base:
																					A      :					Union[str, Any]      		=					self.num_hidden_layers + 2




							def       snake_case			(					self						)		->       List[Any]:
														A      :					int      		=					ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size						)

														A      :					Any      		=					None
														if self.use_input_mask:
																					A      :					List[Any]      		=					random_attention_mask([self.batch_size, self.seq_length]						)

														A      :					List[str]      		=					None
														if self.use_token_type_ids:
																					A      :					List[Any]      		=					ids_tensor([self.batch_size, self.seq_length]    ,						self.type_vocab_size						)

														A      :					Any      		=					None
														A      :					Union[str, Any]      		=					None
														A      :					Optional[Any]      		=					None
														if self.use_labels:
																					A      :					Tuple      		=					ids_tensor([self.batch_size]    ,						self.type_sequence_label_size						)
																					A      :					Union[str, Any]      		=					ids_tensor([self.batch_size, self.seq_length]    ,						self.num_labels						)
																					A      :					List[Any]      		=					ids_tensor([self.batch_size]    ,						self.num_choices						)

														A      :					List[str]      		=					FunnelConfig(
														    vocab_size=self.vocab_size    ,						block_sizes=self.block_sizes    ,						num_decoder_layers=self.num_decoder_layers    ,						d_model=self.d_model    ,						n_head=self.n_head    ,						d_head=self.d_head    ,						d_inner=self.d_inner    ,						hidden_act=self.hidden_act    ,						hidden_dropout=self.hidden_dropout    ,						attention_dropout=self.attention_dropout    ,						activation_dropout=self.activation_dropout    ,						max_position_embeddings=self.max_position_embeddings    ,						type_vocab_size=self.type_vocab_size    ,						initializer_std=self.initializer_std    ,						)

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




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       Optional[int]:
														A      :					str      		=					TFFunnelModel(config=__UpperCAmelCase						)
														A      :					str      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					Tuple      		=					model(__UpperCAmelCase						)

														A      :					str      		=					[input_ids, input_mask]
														A      :					Optional[Any]      		=					model(__UpperCAmelCase						)

														A      :					List[str]      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, self.seq_length, self.d_model)						)

														A      :					str      		=					False
														A      :					List[str]      		=					TFFunnelModel(config=__UpperCAmelCase						)
														A      :					str      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, self.seq_length, self.d_model)						)

														A      :					Union[str, Any]      		=					False
														A      :					Tuple      		=					TFFunnelModel(config=__UpperCAmelCase						)
														A      :					Any      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, self.seq_length, self.d_model)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       Union[str, Any]:
														A      :					Dict      		=					TFFunnelBaseModel(config=__UpperCAmelCase						)
														A      :					Optional[int]      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					List[str]      		=					model(__UpperCAmelCase						)

														A      :					Union[str, Any]      		=					[input_ids, input_mask]
														A      :					Optional[Any]      		=					model(__UpperCAmelCase						)

														A      :					Union[str, Any]      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, 2, self.d_model)						)

														A      :					List[Any]      		=					False
														A      :					Union[str, Any]      		=					TFFunnelBaseModel(config=__UpperCAmelCase						)
														A      :					Union[str, Any]      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, 3, self.d_model)						)

														A      :					int      		=					False
														A      :					Tuple      		=					TFFunnelBaseModel(config=__UpperCAmelCase						)
														A      :					Tuple      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.last_hidden_state.shape    ,						(self.batch_size, 2, self.d_model)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       List[Any]:
														A      :					List[str]      		=					TFFunnelForPreTraining(config=__UpperCAmelCase						)
														A      :					Any      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					Optional[Any]      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       List[Any]:
														A      :					str      		=					TFFunnelForMaskedLM(config=__UpperCAmelCase						)
														A      :					int      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					str      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.vocab_size)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       Union[str, Any]:
														A      :					Tuple      		=					self.num_labels
														A      :					List[Any]      		=					TFFunnelForSequenceClassification(config=__UpperCAmelCase						)
														A      :					List[str]      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					Any      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.num_labels)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       Dict:
														A      :					Union[str, Any]      		=					self.num_choices
														A      :					Tuple      		=					TFFunnelForMultipleChoice(config=__UpperCAmelCase						)
														A      :					Tuple      		=					tf.tile(tf.expand_dims(__UpperCAmelCase    ,						1						)    ,						(1, self.num_choices, 1)						)
														A      :					List[Any]      		=					tf.tile(tf.expand_dims(__UpperCAmelCase    ,						1						)    ,						(1, self.num_choices, 1)						)
														A      :					Any      		=					tf.tile(tf.expand_dims(__UpperCAmelCase    ,						1						)    ,						(1, self.num_choices, 1)						)
														A      :					str      		=					{
														    '''input_ids''': multiple_choice_inputs_ids,
														    '''attention_mask''': multiple_choice_input_mask,
														    '''token_type_ids''': multiple_choice_token_type_ids,
														}
														A      :					Any      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.num_choices)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       str:
														A      :					Optional[Any]      		=					self.num_labels
														A      :					List[str]      		=					TFFunnelForTokenClassification(config=__UpperCAmelCase						)
														A      :					int      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					Optional[Any]      		=					model(__UpperCAmelCase						)
														self.parent.assertEqual(result.logits.shape    ,						(self.batch_size, self.seq_length, self.num_labels)						)




							def       snake_case			(					self    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						__UpperCAmelCase    ,						)		->       Any:
														A      :					Dict      		=					TFFunnelForQuestionAnswering(config=__UpperCAmelCase						)
														A      :					str      		=					{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
														A      :					List[Any]      		=					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       snake_case			(					self						)		->       str:
														A      :					Union[str, Any]      		=					self.prepare_config_and_inputs()
														(
														    (
														    A
														)		,		(
														    A
														)		,		(
														    A
														)		,		(
														    A
														)		,		(
														    A
														)		,		(
														    A
														)		,		(
														    A
														)		,		
														)      :					Optional[Any]      		=					config_and_inputs
														A      :					Union[str, Any]      		=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
														return config, inputs_dict







@require_tf
class 					__lowercase  (						_SCREAMING_SNAKE_CASE		,       _SCREAMING_SNAKE_CASE		,       unittest.TestCase				):





							"""simple docstring"""

							UpperCAmelCase_						:		Any								=	(
							    (
							        TFFunnelModel,
							        TFFunnelForMaskedLM,
							        TFFunnelForPreTraining,
							        TFFunnelForQuestionAnswering,
							        TFFunnelForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							UpperCAmelCase_						:		Optional[Any]								=	(
							    {
							        '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
							        '''fill-mask''': TFFunnelForMaskedLM,
							        '''question-answering''': TFFunnelForQuestionAnswering,
							        '''text-classification''': TFFunnelForSequenceClassification,
							        '''token-classification''': TFFunnelForTokenClassification,
							        '''zero-shot''': TFFunnelForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							UpperCAmelCase_						:		Optional[Any]								=	False
							UpperCAmelCase_						:		Optional[Any]								=	False




							def       snake_case			(					self						)		->       str:
														A      :					Dict      		=					TFFunnelModelTester(self						)
														A      :					int      		=					ConfigTester(self    ,						config_class=__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Tuple:
														self.config_tester.run_common_tests()




							def       snake_case			(					self						)		->       List[str]:
														A      :					Tuple      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Union[str, Any]:
														A      :					Optional[Any]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_pretraining(*__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[Any]:
														A      :					List[Any]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase						)




							def       snake_case			(					self						)		->       Optional[Any]:
														A      :					List[Any]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase						)






							def       snake_case			(					self						)		->       Optional[int]:
														A      :					List[str]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase						)







@require_tf
class 					__lowercase  (						_SCREAMING_SNAKE_CASE		,       unittest.TestCase				):





							"""simple docstring"""

							UpperCAmelCase_						:		Any								=	(
							    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
							)
							UpperCAmelCase_						:		str								=	False
							UpperCAmelCase_						:		Union[str, Any]								=	False




							def       snake_case			(					self						)		->       int:
														A      :					Optional[int]      		=					TFFunnelModelTester(self    ,						base=__UpperCAmelCase						)
														A      :					Optional[Any]      		=					ConfigTester(self    ,						config_class=__UpperCAmelCase						)




							def       snake_case			(					self						)		->       str:
														self.config_tester.run_common_tests()




							def       snake_case			(					self						)		->       Tuple:
														A      :					Optional[Any]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_base_model(*__UpperCAmelCase						)




							def       snake_case			(					self						)		->       int:
														A      :					Union[str, Any]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase						)






							def       snake_case			(					self						)		->       Tuple:
														A      :					List[str]      		=					self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase						)






