





from sklearn.metrics import matthews_corrcoef

import datasets


A   : List[Any]			=			'''
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]
'''

A   : List[str]			=			'''
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
'''

A   : Dict			=			'''\
@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   A      (datasets.Metric   ):
			'''simple docstring'''




			def        a_	(      self       :   List[Any]       )     ->     List[str]:







					"""simple docstring"""






					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        a_	(      self       :   List[Any]							,     __lowerCAmelCase       :   Tuple							,     __lowerCAmelCase       :   List[str]							,     __lowerCAmelCase       :   List[str]=None       )     ->     Tuple:







					"""simple docstring"""






					return {
					    "matthews_correlation": float(matthews_corrcoef(__lowerCAmelCase							,     __lowerCAmelCase							,     sample_weight=__lowerCAmelCase       )       ),
					}










import os
import re
import shutil
import sys
import tempfile
import unittest

import black


A   : Dict			=				os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If BertLMPredictionHead is changed in modeling_bert.py, this code needs to be manually updated.
A   : Optional[int]			=				'''    def __init__(self, config):
        super().__init__()
        self.transform = BertPredictionHeadTransform(config)

        # The output weights are the same as the input embeddings, but there is
        # an output-only bias for each token.
        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)

        self.bias = nn.Parameter(torch.zeros(config.vocab_size))

        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
        self.decoder.bias = self.bias

    def forward(self, hidden_states):
        hidden_states = self.transform(hidden_states)
        hidden_states = self.decoder(hidden_states)
        return hidden_states
'''


class   A      (unittest.TestCase   ):
			'''simple docstring'''




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







					"""simple docstring"""






					A__  				=       tempfile.mkdtemp()
					os.makedirs(os.path.join(self.transformer_dir							,     """models/bert/"""       )       )
					A__  				=       self.transformer_dir
					shutil.copy(
					    os.path.join(__lowerCAmelCase							,     """src/transformers/models/bert/modeling_bert.py"""       )							,     os.path.join(self.transformer_dir							,     """models/bert/modeling_bert.py"""       )							,     )






			def        a_	(      self       :   str       )     ->     Optional[int]:







					"""simple docstring"""






					A__  				=       """src/transformers"""
					shutil.rmtree(self.transformer_dir       )






			def        a_	(      self       :   List[str]							,     __lowerCAmelCase       :   List[Any]							,     __lowerCAmelCase       :   Optional[int]							,     __lowerCAmelCase       :   int							,     __lowerCAmelCase       :   Tuple=None       )     ->     Dict:







					"""simple docstring"""






					A__  				=       comment + f'\nclass {class_name}(nn.Module):\n' + class_code
					if overwrite_result is not None:
							A__  				=       comment + f'\nclass {class_name}(nn.Module):\n' + overwrite_result
					A__  				=       black.Mode(target_versions={black.TargetVersion.PYaa}							,     line_length=1_19       )
					A__  				=       black.format_str(__lowerCAmelCase							,     mode=__lowerCAmelCase       )
					A__  				=       os.path.join(self.transformer_dir							,     """new_code.py"""       )
					with open(__lowerCAmelCase							,     """w"""							,     newline="""\n"""       ) as f:
							f.write(__lowerCAmelCase       )
					if overwrite_result is None:
							self.assertTrue(len(check_copies.is_copy_consistent(__lowerCAmelCase       )       ) == 0       )
					else:
							check_copies.is_copy_consistent(f.name							,     overwrite=__lowerCAmelCase       )
							with open(__lowerCAmelCase							,     """r"""       ) as f:
									self.assertTrue(f.read()							,     __lowerCAmelCase       )






			def        a_	(      self       :   Tuple       )     ->     List[Any]:







					"""simple docstring"""






					A__  				=       check_copies.find_code_in_transformers("""models.bert.modeling_bert.BertLMPredictionHead"""       )
					self.assertEqual(__lowerCAmelCase							,     __lowerCAmelCase       )






			def        a_	(      self       :   Tuple       )     ->     Any:







					"""simple docstring"""






					self.check_copy_consistency(
					    """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""							,     """BertLMPredictionHead"""							,     REFERENCE_CODE + """\n"""							,     )

					# With no empty line at the end
					self.check_copy_consistency(
					    """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""							,     """BertLMPredictionHead"""							,     __lowerCAmelCase							,     )

					# Copy consistency with rename
					self.check_copy_consistency(
					    """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""							,     """TestModelLMPredictionHead"""							,     re.sub("""Bert"""							,     """TestModel"""							,     __lowerCAmelCase       )							,     )

					# Copy consistency with a really long name
					A__  				=       """TestModelWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason"""
					self.check_copy_consistency(
					    f'# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->{long_class_name}'							,     f'{long_class_name}LMPredictionHead'							,     re.sub("""Bert"""							,     __lowerCAmelCase							,     __lowerCAmelCase       )							,     )

					# Copy consistency with overwrite
					self.check_copy_consistency(
					    """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""							,     """TestModelLMPredictionHead"""							,     __lowerCAmelCase							,     overwrite_result=re.sub("""Bert"""							,     """TestModel"""							,     __lowerCAmelCase       )							,     )







			def        a_	(      self       :   Optional[int]       )     ->     Optional[int]:







					"""simple docstring"""






					A__  				=       check_copies.LOCALIZED_READMES["""README_zh-hans.md"""]

					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
					    """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
					    """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
					    """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.\n1."""
					    """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (from HuggingFace),"""
					    """ released together with the paper [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
					    """ lighter](https://arxiv.org/abs/1910.01108) by Victor Sanh, Lysandre Debut and Thomas Wolf. The same"""
					    """ method has been applied to compress GPT2 into"""
					    """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
					    """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
					    """ Multilingual BERT into"""
					    """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
					    """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)**"""
					    """ (from Google Research/Stanford University) released with the paper [ELECTRA: Pre-training text encoders"""
					    """ as discriminators rather than generators](https://arxiv.org/abs/2003.10555) by Kevin Clark, Minh-Thang"""
					    """ Luong, Quoc V. Le, Christopher D. Manning."""
					)
					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
					    """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
					    """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
					    """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
					)
					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
					    """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
					    """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
					    """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n1."""
					    """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (来自 HuggingFace) 伴随论文"""
					    """ [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
					    """ lighter](https://arxiv.org/abs/1910.01108) 由 Victor Sanh, Lysandre Debut and Thomas Wolf 发布。 The same"""
					    """ method has been applied to compress GPT2 into"""
					    """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
					    """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
					    """ Multilingual BERT into"""
					    """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
					    """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)** (来自"""
					    """ Google Research/Stanford University) 伴随论文 [ELECTRA: Pre-training text encoders as discriminators rather"""
					    """ than generators](https://arxiv.org/abs/2003.10555) 由 Kevin Clark, Minh-Thang Luong, Quoc V. Le,"""
					    """ Christopher D. Manning 发布。\n"""
					)

					A__				,      A__  				=       check_copies.convert_to_localized_md(
					    __lowerCAmelCase							,     __lowerCAmelCase							,     localized_readme["""format_model_list"""]       )

					self.assertFalse(__lowerCAmelCase       )
					self.assertEqual(__lowerCAmelCase							,     __lowerCAmelCase       )

					A__				,      A__  				=       check_copies.convert_to_localized_md(
					    __lowerCAmelCase							,     __lowerCAmelCase							,     localized_readme["""format_model_list"""]       )

					# Check whether the number of models is equal to README.md after conversion.
					self.assertTrue(__lowerCAmelCase       )

					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
					    """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
					    """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
					    """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut."""
					)
					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/main/model_doc/albert.html)** (来自 Google Research and"""
					    """ the Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
					    """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
					    """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
					)
					A__  				=       (
					    """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
					    """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
					    """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
					    """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
					)

					A__				,      A__  				=       check_copies.convert_to_localized_md(
					    __lowerCAmelCase							,     __lowerCAmelCase							,     localized_readme["""format_model_list"""]       )

					# Check if the model link is synchronized.
					self.assertEqual(__lowerCAmelCase							,     __lowerCAmelCase       )



