



"""simple docstring"""
from scipy.stats import pearsonr

import datasets


__SCREAMING_SNAKE_CASE  :						Union[str, Any]    							=      '''\nPearson correlation coefficient and p-value for testing non-correlation.\nThe Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.\nThe p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.\n'''


__SCREAMING_SNAKE_CASE  :						Tuple    							=      '''\nArgs:\n    predictions (`list` of `int`): Predicted class labels, as returned by a model.\n    references (`list` of `int`): Ground truth labels.\n    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.\n\nReturns:\n    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.\n    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.\n\nExamples:\n\n    Example 1-A simple example using only predictions and references.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n\n    Example 2-The same as Example 1, but that also returns the `p-value`.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)\n        >>> print(sorted(list(results.keys())))\n        [\'p-value\', \'pearsonr\']\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n        >>> print(round(results[\'p-value\'], 2))\n        0.15\n'''


__SCREAMING_SNAKE_CASE  :						List[str]    							=      '''\n@article{2020SciPy-NMeth,\nauthor  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and\n      Haberland, Matt and Reddy, Tyler and Cournapeau, David and\n      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and\n      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and\n      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and\n      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and\n      Kern, Robert and Larson, Eric and Carey, C J and\n      Polat, Ilhan and Feng, Yu and Moore, Eric W. and\n      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and\n      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and\n      Harris, Charles R. and Archibald, Anne M. and\n      Ribeiro, Antonio H. and Pedregosa, Fabian and\n      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},\ntitle   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific\n      Computing in Python}},\njournal = {Nature Methods},\nyear    = {2020},\nvolume  = {17},\npages   = {261--272},\nadsurl  = {https://rdcu.be/b08Wh},\ndoi = {10.1038/s41592-019-0686-2},\n}\n'''


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





					'''simple docstring'''



					def 			snake_case__      (    self   ):
									return datasets.MetricInfo(
									    description=_DESCRIPTION				,       citation=_CITATION				,       inputs_description=_KWARGS_DESCRIPTION				,       features=datasets.Features(
									        {
									            '''predictions''': datasets.Value('''float'''   ),
									            '''references''': datasets.Value('''float'''   ),
									        }   )				,       reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.pearsonr.html''']				,       )





					def 			snake_case__      (    self				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__=False   ):
									if return_pvalue:
													_lowerCamelCase        =				pearsonr(UpperCAmelCase_				,       UpperCAmelCase_   )
													return {"pearsonr": results[0], "p-value": results[1]}
									else:
													return {"pearsonr": float(pearsonr(UpperCAmelCase_				,       UpperCAmelCase_   )[0]   )}











"""simple docstring"""
import unittest

from transformers import BigBirdConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
			import jax

			from transformers.models.big_bird.modeling_flax_big_bird import (
			    FlaxBigBirdForCausalLM,
			    FlaxBigBirdForMaskedLM,
			    FlaxBigBirdForMultipleChoice,
			    FlaxBigBirdForPreTraining,
			    FlaxBigBirdForQuestionAnswering,
			    FlaxBigBirdForSequenceClassification,
			    FlaxBigBirdForTokenClassification,
			    FlaxBigBirdModel,
			)


class 							lowerCamelCase_(   unittest.TestCase    ):





					'''simple docstring'''



					def __init__(    self				,       lowerCamelCase__				,       lowerCamelCase__=2				,       lowerCamelCase__=5_6				,       lowerCamelCase__=True				,       lowerCamelCase__=True				,       lowerCamelCase__=True				,       lowerCamelCase__=True				,       lowerCamelCase__=9_9				,       lowerCamelCase__=3_2				,       lowerCamelCase__=2				,       lowerCamelCase__=2				,       lowerCamelCase__=7				,       lowerCamelCase__="gelu_new"				,       lowerCamelCase__=0.1				,       lowerCamelCase__=0.1				,       lowerCamelCase__=5_1_2				,       lowerCamelCase__=1_6				,       lowerCamelCase__=2				,       lowerCamelCase__=0.0_2				,       lowerCamelCase__=4				,       lowerCamelCase__="block_sparse"				,       lowerCamelCase__=True				,       lowerCamelCase__=False				,       lowerCamelCase__=2				,       lowerCamelCase__=3				,       ):
									_lowerCamelCase        =				parent
									_lowerCamelCase        =				batch_size
									_lowerCamelCase        =				seq_length
									_lowerCamelCase        =				is_training
									_lowerCamelCase        =				use_attention_mask
									_lowerCamelCase        =				use_token_type_ids
									_lowerCamelCase        =				use_labels
									_lowerCamelCase        =				vocab_size
									_lowerCamelCase        =				hidden_size
									_lowerCamelCase        =				num_hidden_layers
									_lowerCamelCase        =				num_attention_heads
									_lowerCamelCase        =				intermediate_size
									_lowerCamelCase        =				hidden_act
									_lowerCamelCase        =				hidden_dropout_prob
									_lowerCamelCase        =				attention_probs_dropout_prob
									_lowerCamelCase        =				max_position_embeddings
									_lowerCamelCase        =				type_vocab_size
									_lowerCamelCase        =				type_sequence_label_size
									_lowerCamelCase        =				initializer_range
									_lowerCamelCase        =				num_choices

									_lowerCamelCase        =				rescale_embeddings
									_lowerCamelCase        =				attention_type
									_lowerCamelCase        =				use_bias
									_lowerCamelCase        =				block_size
									_lowerCamelCase        =				num_random_blocks

					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size   )

									_lowerCamelCase        =				None
									if self.use_attention_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        =				BigBirdConfig(
									    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				,       is_decoder=lowerCamelCase__				,       initializer_range=self.initializer_range				,       attention_type=self.attention_type				,       block_size=self.block_size				,       num_random_blocks=self.num_random_blocks				,       use_bias=self.use_bias				,       rescale_embeddings=self.rescale_embeddings				,       )

									return config, input_ids, token_type_ids, attention_mask





					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				self.prepare_config_and_inputs()
									_lowerCamelCase  ,     _lowerCamelCase  ,     _lowerCamelCase  ,     _lowerCamelCase        =				config_and_inputs
									_lowerCamelCase        =				{
									    '''input_ids''': input_ids,
									    '''token_type_ids''': token_type_ids,
									    '''attention_mask''': attention_mask,
									}
									return config, inputs_dict


@require_flax
class 							lowerCamelCase_(   A__,				unittest.TestCase    ):





					'''simple docstring'''



					lowercase__   :       List[str]										= (
					    (
					        FlaxBigBirdForCausalLM,
					        FlaxBigBirdModel,
					        FlaxBigBirdForPreTraining,
					        FlaxBigBirdForMaskedLM,
					        FlaxBigBirdForMultipleChoice,
					        FlaxBigBirdForQuestionAnswering,
					        FlaxBigBirdForSequenceClassification,
					        FlaxBigBirdForTokenClassification,
					    )
					    if is_flax_available()
					    else ()
					)

					lowercase__   :       Any										= False
					lowercase__   :       Optional[int]										= False

					def 			snake_case__      (    self   ):
									_lowerCamelCase        =				FlaxBigBirdModelTester(self   )

					@slow
					# copied from `test_modeling_flax_common` because it takes much longer than other models
					def 			snake_case__      (    self   ):
									super().test_from_pretrained_save_pretrained()

					@slow
					# copied from `test_modeling_flax_common` because it takes much longer than other models
					def 			snake_case__      (    self   ):
									super().test_from_pretrained_with_no_automatic_init()

					@slow
					# copied from `test_modeling_flax_common` because it takes much longer than other models
					def 			snake_case__      (    self   ):
									super().test_no_automatic_init()

					@slow
					# copied from `test_modeling_flax_common` because it takes much longer than other models
					def 			snake_case__      (    self   ):
									super().test_hidden_states_output()

					@slow
					def 			snake_case__      (    self   ):
									for model_class_name in self.all_model_classes:
													_lowerCamelCase        =				model_class_name.from_pretrained('''google/bigbird-roberta-base'''   )
													self.assertIsNotNone(lowerCamelCase__   )

					def 			snake_case__      (    self   ):
									if self.test_attn_probs:
													super().test_attention_outputs()

					@slow
					# copied from `test_modeling_flax_common` because it takes much longer than other models
					def 			snake_case__      (    self   ):
									_lowerCamelCase  ,     _lowerCamelCase        =				self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													with self.subTest(model_class.__name__   ):
																	_lowerCamelCase        =				self._prepare_for_class(lowerCamelCase__				,       lowerCamelCase__   )
																	_lowerCamelCase        =				model_class(lowerCamelCase__   )

																	@jax.jit
																	def model_jitted(lowerCamelCase__				,       lowerCamelCase__=None				,       **lowerCamelCase__   ):
																					return model(input_ids=lowerCamelCase__				,       attention_mask=lowerCamelCase__				,       **lowerCamelCase__   )

																	with self.subTest('''JIT Enabled'''   ):
																					_lowerCamelCase        =				model_jitted(**lowerCamelCase__   ).to_tuple()

																	with self.subTest('''JIT Disabled'''   ):
																					with jax.disable_jit():
																									_lowerCamelCase        =				model_jitted(**lowerCamelCase__   ).to_tuple()

																	self.assertEqual(len(lowerCamelCase__   )				,       len(lowerCamelCase__   )   )
																	for jitted_output, output in zip(lowerCamelCase__				,       lowerCamelCase__   ):
																					self.assertEqual(jitted_output.shape				,       output.shape   )





					def 			snake_case__      (    self				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__=1e-5				,       lowerCamelCase__="outputs"				,       lowerCamelCase__=None   ):
									# `bigbird_block_sparse_attention` in `FlaxBigBird` returns `attention_probs = None`, while in PyTorch version,
									# an effort was done to return `attention_probs` (yet to be verified).
									if name.startswith('''outputs.attentions'''   ):
													return
									else:
													super().check_pt_flax_outputs(lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__				,       lowerCamelCase__   )
