





from sklearn.metrics import matthews_corrcoef

import datasets


UpperCAmelCase_ 							=       """
Compute the Matthews correlation coefficient (MCC)

The Matthews correlation coefficient is used in machine learning as a
measure of the quality of binary and multiclass classifications. It takes
into account true and false positives and negatives and is generally
regarded as a balanced measure which can be used even if the classes are of
very different sizes. The MCC is in essence a correlation coefficient value
between -1 and +1. A coefficient of +1 represents a perfect prediction, 0
an average random prediction and -1 an inverse prediction.  The statistic
is also known as the phi coefficient. [source: Wikipedia]
"""

UpperCAmelCase_ 							=       """
Args:
    predictions (list of int): Predicted labels, as returned by a model.
    references (list of int): Ground truth labels.
    sample_weight (list of int, float, or bool): Sample weights. Defaults to `None`.
Returns:
    matthews_correlation (dict containing float): Matthews correlation.
Examples:
    Example 1, a basic example with only predictions and references as inputs:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3])
        >>> print(round(results['matthews_correlation'], 2))
        0.54

    Example 2, the same example as above, but also including sample weights:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3],
        ...                                     sample_weight=[0.5, 3, 1, 1, 1, 2])
        >>> print(round(results['matthews_correlation'], 2))
        0.1

    Example 3, the same example as above, but with sample weights that cause a negative correlation:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3],
        ...                                     sample_weight=[0.5, 1, 0, 0, 0, 1])
        >>> print(round(results['matthews_correlation'], 2))
        -0.25
"""

UpperCAmelCase_ 							=       """\
@article{scikit-learn,
  title={Scikit-learn: Machine Learning in {P}ython},
  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
  journal={Journal of Machine Learning Research},
  volume={12},
  pages={2825--2830},
  year={2011}
}
"""
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION							,					_KWARGS_DESCRIPTION   )
class      UpperCamelCase_						(					datasets.Metric   ):




     def 		lowerCAmelCase     (						self					)						->							Optional[int]:
          return datasets.MetricInfo(
              description=_DESCRIPTION			,  citation=_CITATION			,  inputs_description=_KWARGS_DESCRIPTION			,  features=datasets.Features(
                  {
                      'predictions': datasets.Value('int32'					),
                      'references': datasets.Value('int32'					),
                  }					)			,  reference_urls=[
                  'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html'
              ]			,  )






     def 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_			,  lowerCAmelCase_=None					)						->							str:
          return {
              "matthews_correlation": float(matthews_corrcoef(lowerCAmelCase_			,  lowerCAmelCase_			,  sample_weight=lowerCAmelCase_					)					),
          }










from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast
from ...utils import logging


UpperCAmelCase_ 							=       logging.get_logger(__name__)

UpperCAmelCase_ 							=       {
    """EleutherAI/gpt-neo-1.3B""": """https://huggingface.co/EleutherAI/gpt-neo-1.3B/resolve/main/config.json""",
    # See all GPTNeo models at https://huggingface.co/models?filter=gpt_neo
}
class      UpperCamelCase_						(					_lowerCamelCase   ):
					lowerCAmelCase_							=		'''gpt_neo'''
					lowerCAmelCase_							=		['''past_key_values''']
					lowerCAmelCase_							=		{'''num_attention_heads''': '''num_heads''', '''num_hidden_layers''': '''num_layers'''}




					def __init__(						self			,  lowerCAmelCase_=5_0257			,  lowerCAmelCase_=2048			,  lowerCAmelCase_=2048			,  lowerCAmelCase_=24			,  lowerCAmelCase_=[[["global", "local"], 12]]			,  lowerCAmelCase_=16			,  lowerCAmelCase_=None			,  lowerCAmelCase_=256			,  lowerCAmelCase_="gelu_new"			,  lowerCAmelCase_=0.0			,  lowerCAmelCase_=0.0			,  lowerCAmelCase_=0.0			,  lowerCAmelCase_=0.1			,  lowerCAmelCase_=1E-5			,  lowerCAmelCase_=0.02			,  lowerCAmelCase_=True			,  lowerCAmelCase_=5_0256			,  lowerCAmelCase_=5_0256			,  **lowerCAmelCase_			,  )						->							Tuple:
										_snake_case													=			vocab_size
										_snake_case													=			max_position_embeddings
										_snake_case													=			hidden_size
										_snake_case													=			num_layers
										_snake_case													=			num_heads
										_snake_case													=			intermediate_size
										_snake_case													=			window_size
										_snake_case													=			activation_function
										_snake_case													=			resid_dropout
										_snake_case													=			embed_dropout
										_snake_case													=			attention_dropout
										_snake_case													=			classifier_dropout
										_snake_case													=			layer_norm_epsilon
										_snake_case													=			initializer_range
										_snake_case													=			use_cache

										_snake_case													=			bos_token_id
										_snake_case													=			eos_token_id

										_snake_case													=			attention_types
										_snake_case													=			self.expand_attention_types_params(lowerCAmelCase_					)

										if len(self.attention_layers					) != self.num_layers:
															raise ValueError(
															    'Configuration for convolutional module is incorrect. '
															    'It is required that `len(config.attention_layers)` == `config.num_layers` '
															    F'''but is `len(config.attention_layers) = {len(self.attention_layers					)}`, '''
															    F'''`config.num_layers = {self.num_layers}`. '''
															    '`config.attention_layers` is prepared using `config.attention_types`. '
															    'Please verify the value of `config.attention_types` argument.'					)

										super().__init__(bos_token_id=lowerCAmelCase_			,  eos_token_id=lowerCAmelCase_			,  **lowerCAmelCase_					)






					@staticmethod
					def 		lowerCAmelCase     (						lowerCAmelCase_					)						->							Any:
										_snake_case													=			[]
										for item in attention_types:
															for _ in range(item[1]					):
																				attentions.extend(item[0]					)
										return attentions





def   lowerCamelCase__       (       UpperCamelCase__     :    Tuple    ,      UpperCamelCase__     :    int    ,      UpperCamelCase__     :    Tuple    ,      UpperCamelCase__     :    Optional[int]  )     ->	Any:



					'''simple docstring'''




					import torch

					_snake_case													=			input.size()
					_snake_case													=			len(UpperCamelCase__  )
					_snake_case													=			shape[dimension]

					_snake_case													=			torch.arange(0    ,      UpperCamelCase__    ,      UpperCamelCase__  )
					_snake_case													=			torch.div(sizedim - size    ,      UpperCamelCase__    ,      rounding_mode='floor'  ) + 1
					_snake_case													=			torch.arange(UpperCamelCase__  ) + low_indices[:min_length][:, None]

					_snake_case													=			[slice(UpperCamelCase__  )] * rank
					_snake_case													=			indices
					_snake_case													=			input[s]

					_snake_case													=			list(range(0    ,      rank + 1  )  )
					perm.append(perm.pop(dimension + 1  )  )

					return sliced.permute(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    Tuple    ,      UpperCamelCase__     :    Dict  )     ->	str:



					'''simple docstring'''




					import torch

					_snake_case													=			torch.arange(1    ,      UpperCamelCase__  )
					_snake_case													=			torch.remainder(UpperCamelCase__    ,      UpperCamelCase__  )
					_snake_case													=			remainders == 0
					_snake_case													=			candidates[divisor_indices]
					_snake_case													=			torch.max(UpperCamelCase__  )
					return largest_divisor, torch.div(UpperCamelCase__    ,      UpperCamelCase__    ,      rounding_mode='floor'  )




class      UpperCamelCase_						(					_lowerCamelCase   ):




					@property
					def 		lowerCAmelCase     (						self					)						->							Mapping[str, Mapping[int, str]]:
										_snake_case													=			OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}					)
										if self.use_past:
															self.fill_with_past_key_values_(lowerCAmelCase_			,  direction='inputs'					)
															_snake_case													=			{0: 'batch', 1: 'past_sequence + sequence'}
										else:
															_snake_case													=			{0: 'batch', 1: 'sequence'}

										return common_inputs




					@property
					def 		lowerCAmelCase     (						self					)						->							int:
										return self._config.num_heads




					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_ = -1			,  lowerCAmelCase_ = -1			,  lowerCAmelCase_ = False			,  lowerCAmelCase_ = None			,  )						->							Mapping[str, Any]:
										_snake_case													=			super(lowerCAmelCase_			,  self					).generate_dummy_inputs(
										    lowerCAmelCase_			,  batch_size=lowerCAmelCase_			,  seq_length=lowerCAmelCase_			,  is_pair=lowerCAmelCase_			,  framework=lowerCAmelCase_					)

										# We need to order the input in the way they appears in the forward()
										_snake_case													=			OrderedDict({'input_ids': common_inputs['input_ids']}					)

										# Need to add the past_keys
										if self.use_past:
															if not is_torch_available():
																				raise ValueError('Cannot generate dummy past_keys inputs without PyTorch installed.'					)
															else:
																				import torch

																				_snake_case							,       _snake_case													=			common_inputs['input_ids'].shape
																				# Not using the same length for past_key_values
																				_snake_case													=			seqlen + 2
																				_snake_case													=			(
																				    batch,
																				    self.num_attention_heads,
																				    past_key_values_length,
																				    self._config.hidden_size // self.num_attention_heads,
																				)
																				_snake_case													=			[
																				    (torch.zeros(lowerCAmelCase_					), torch.zeros(lowerCAmelCase_					)) for _ in range(self.num_layers					)
																				]

										_snake_case													=			common_inputs['attention_mask']
										if self.use_past:
															_snake_case													=			ordered_inputs['attention_mask'].dtype
															_snake_case													=			torch.cat(
															    [ordered_inputs['attention_mask'], torch.ones(lowerCAmelCase_			,  lowerCAmelCase_			,  dtype=lowerCAmelCase_					)]			,  dim=1					)

										return ordered_inputs






					@property
					def 		lowerCAmelCase     (						self					)						->							int:
										return 13



