






'''simple docstring'''




import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
		import jax.numpy as jnp

		from transformers.models.roberta_prelayernorm.modeling_flax_roberta_prelayernorm import (
		    FlaxRobertaPreLayerNormForCausalLM,
		    FlaxRobertaPreLayerNormForMaskedLM,
		    FlaxRobertaPreLayerNormForMultipleChoice,
		    FlaxRobertaPreLayerNormForQuestionAnswering,
		    FlaxRobertaPreLayerNormForSequenceClassification,
		    FlaxRobertaPreLayerNormForTokenClassification,
		    FlaxRobertaPreLayerNormModel,
		)







class    A_	(unittest.TestCase							):
							"""simple docstring"""




							def __init__(		self			:List[Any]       ,							lowerCAmelCase__			:int       ,							lowerCAmelCase__			:List[Any]=13       ,							lowerCAmelCase__			:List[str]=7       ,							lowerCAmelCase__			:Dict=True       ,							lowerCAmelCase__			:str=True       ,							lowerCAmelCase__			:int=True       ,							lowerCAmelCase__			:Any=True       ,							lowerCAmelCase__			:List[Any]=99       ,							lowerCAmelCase__			:Union[str, Any]=32       ,							lowerCAmelCase__			:int=5       ,							lowerCAmelCase__			:int=4       ,							lowerCAmelCase__			:str=37       ,							lowerCAmelCase__			:Tuple="gelu"       ,							lowerCAmelCase__			:int=0.1       ,							lowerCAmelCase__			:Optional[int]=0.1       ,							lowerCAmelCase__			:Any=512       ,							lowerCAmelCase__			:Any=16       ,							lowerCAmelCase__			:Optional[Any]=2       ,							lowerCAmelCase__			:Dict=0.0_2       ,							lowerCAmelCase__			:str=4       ,							)				->  List[str]:


										'''simple docstring'''




										snake_case_				:					Optional[int]   =       parent
										snake_case_				:					Any   =       batch_size
										snake_case_				:					Union[str, Any]   =       seq_length
										snake_case_				:					Any   =       is_training
										snake_case_				:					Optional[Any]   =       use_attention_mask
										snake_case_				:					str   =       use_token_type_ids
										snake_case_				:					Any   =       use_labels
										snake_case_				:					int   =       vocab_size
										snake_case_				:					Dict   =       hidden_size
										snake_case_				:					str   =       num_hidden_layers
										snake_case_				:					str   =       num_attention_heads
										snake_case_				:					List[str]   =       intermediate_size
										snake_case_				:					str   =       hidden_act
										snake_case_				:					int   =       hidden_dropout_prob
										snake_case_				:					Union[str, Any]   =       attention_probs_dropout_prob
										snake_case_				:					Dict   =       max_position_embeddings
										snake_case_				:					Tuple   =       type_vocab_size
										snake_case_				:					Optional[int]   =       type_sequence_label_size
										snake_case_				:					Optional[int]   =       initializer_range
										snake_case_				:					Union[str, Any]   =       num_choices

							def 							_A	(		self			:Optional[Any]				)				->  Any:


										'''simple docstring'''




										snake_case_				:					Any   =       ids_tensor([self.batch_size, self.seq_length]       ,							self.vocab_size				)

										snake_case_				:					Tuple   =       None
										if self.use_attention_mask:
													snake_case_				:					Dict   =       random_attention_mask([self.batch_size, self.seq_length]				)

										snake_case_				:					Union[str, Any]   =       None
										if self.use_token_type_ids:
													snake_case_				:					Tuple   =       ids_tensor([self.batch_size, self.seq_length]       ,							self.type_vocab_size				)

										snake_case_				:					List[Any]   =       RobertaPreLayerNormConfig(
										    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       ,							)

										return config, input_ids, token_type_ids, attention_mask

							def 							_A	(		self			:Optional[Any]				)				->  Optional[Any]:


										'''simple docstring'''




										snake_case_				:					int   =       self.prepare_config_and_inputs()
										snake_case_,	snake_case_,	snake_case_,	snake_case_				:					Union[str, Any]   =       config_and_inputs
										snake_case_				:					Tuple   =       {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
										return config, inputs_dict






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


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       self.prepare_config_and_inputs()
										snake_case_,	snake_case_,	snake_case_,	snake_case_				:					List[Any]   =       config_and_inputs

										snake_case_				:					Optional[int]   =       True
										snake_case_				:					Optional[Any]   =       floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
										snake_case_				:					Union[str, Any]   =       ids_tensor([self.batch_size, self.seq_length]       ,							vocab_size=2				)

										return (
										    config,
										    input_ids,
										    token_type_ids,
										    encoder_hidden_states,
										    encoder_attention_mask,
										)







@require_flax
# Copied from tests.models.roberta.test_modelling_flax_roberta.FlaxRobertaPreLayerNormModelTest with ROBERTA->ROBERTA_PRELAYERNORM,Roberta->RobertaPreLayerNorm,roberta-base->andreasmadsen/efficient_mlm_m0.40
class    A_	(a_						,					unittest.TestCase							):
							"""simple docstring"""




							a__   		=	True

							a__   		=	(
							    (
							        FlaxRobertaPreLayerNormModel,
							        FlaxRobertaPreLayerNormForCausalLM,
							        FlaxRobertaPreLayerNormForMaskedLM,
							        FlaxRobertaPreLayerNormForSequenceClassification,
							        FlaxRobertaPreLayerNormForTokenClassification,
							        FlaxRobertaPreLayerNormForMultipleChoice,
							        FlaxRobertaPreLayerNormForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)

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


										'''simple docstring'''




										snake_case_				:					Dict   =       FlaxRobertaPreLayerNormModelTester(self				)






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


										'''simple docstring'''




										for model_class_name in self.all_model_classes:
													snake_case_				:					Dict   =       model_class_name.from_pretrained("andreasmadsen/efficient_mlm_m0.40"       ,							from_pt=lowerCAmelCase__				)
													snake_case_				:					Any   =       model(np.ones((1, 1)				)				)
													self.assertIsNotNone(lowerCAmelCase__				)







@require_flax
class    A_	(unittest.TestCase							):
							"""simple docstring"""




							@slow
							def 							_A	(		self			:Dict				)				->  Tuple:


										'''simple docstring'''




										snake_case_				:					List[Any]   =       FlaxRobertaPreLayerNormForMaskedLM.from_pretrained("andreasmadsen/efficient_mlm_m0.40"       ,							from_pt=lowerCAmelCase__				)

										snake_case_				:					str   =       np.array([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]       ,							dtype=jnp.intaa				)
										snake_case_				:					Optional[Any]   =       model(lowerCAmelCase__				)[0]
										snake_case_				:					Optional[int]   =       [1, 11, 50_265]
										self.assertEqual(list(output.shape				)       ,							lowerCAmelCase__				)
										# compare the actual values for a slice.
										snake_case_				:					Union[str, Any]   =       np.array(
										    [[[4_0.4_8_8_0, 1_8.0_1_9_9, -5.2_3_6_7], [-1.8_8_7_7, -4.0_8_8_5, 1_0.7_0_8_5], [-2.2_6_1_3, -5.6_1_1_0, 7.2_6_6_5]]]       ,							dtype=np.floataa				)
										self.assertTrue(np.allclose(output[:, :3, :3]       ,							lowerCAmelCase__       ,							atol=1E-4				)				)






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


										'''simple docstring'''




										snake_case_				:					List[Any]   =       FlaxRobertaPreLayerNormModel.from_pretrained("andreasmadsen/efficient_mlm_m0.40"       ,							from_pt=lowerCAmelCase__				)

										snake_case_				:					List[Any]   =       np.array([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]       ,							dtype=jnp.intaa				)
										snake_case_				:					Union[str, Any]   =       model(lowerCAmelCase__				)[0]
										# compare the actual values for a slice.
										snake_case_				:					Union[str, Any]   =       np.array(
										    [[[0.0_2_0_8, -0.0_3_5_6, 0.0_2_3_7], [-0.1_5_6_9, -0.0_4_1_1, -0.2_6_2_6], [0.1_8_7_9, 0.0_1_2_5, -0.0_0_8_9]]]       ,							dtype=np.floataa				)
										self.assertTrue(np.allclose(output[:, :3, :3]       ,							lowerCAmelCase__       ,							atol=1E-4				)				)












'''simple docstring'''




from scipy.stats import spearmanr

import datasets


__lowerCamelCase   :					str   							=					'''
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
'''

__lowerCamelCase   :					int   							=					'''
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {\'spearmanr\': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results[\'spearmanr\'])
        -0.7
        >>> print(round(results[\'spearmanr_pvalue\'], 2))
        0.19
'''

__lowerCamelCase   :					List[str]   							=					R'''\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
'''







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,					_KWARGS_DESCRIPTION							)
class    A_	(datasets.Metric							):
							"""simple docstring"""




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


										'''simple docstring'''




										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.spearmanr.html"]       ,							)






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


										'''simple docstring'''




										snake_case_				:					Optional[Any]   =       spearmanr(lowerCAmelCase__       ,							lowerCAmelCase__				)
										if return_pvalue:
													return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
										else:
													return {"spearmanr": results[0]}




