

'''simple docstring'''

import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata




def  UpperCamelCase(	UpperCAmelCase_      ):
 UpperCAmelCase			:      Any		   =					min(re.search('^ +'    ,			UpperCAmelCase_      ).end() if t.startswith(' '      ) else 0 for t in string.splitlines()      )
 return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(UpperCAmelCase_      )]      )


lowercase__            =     "\\n---\nlanguage:\n- zh\n- en\ntask_ids:\n- sentiment-classification\n---\n# Begin of markdown\n\nSome cool dataset card\n"

lowercase__            =     "\\n---\n---\n# Begin of markdown\n\nSome cool dataset card\n"


lowercase__            =     "\\n# Begin of markdown\n\nSome cool dataset card\n"




class 			A_					(							unittest.TestCase				):






     '''simple docstring'''



     def   UpperCAmelCase_			(						self					:	int			)		->      Tuple:
      with tempfile.TemporaryDirectory() as tmp_dir:
       UpperCAmelCase			:      List[Any]		   =					Path(lowercase_			) / 'README.md'
       with open(lowercase_	,     'w+'			) as readme_file:
        readme_file.write(lowercase_			)
       UpperCAmelCase			:      Union[str, Any]		   =					DatasetMetadata.from_readme(lowercase_			)
       self.assertDictEqual(lowercase_	,     {'language': ['zh', 'en'], 'task_ids': ['sentiment-classification']}			)

       with open(lowercase_	,     'w+'			) as readme_file:
        readme_file.write(lowercase_			)
       UpperCAmelCase			:      List[Any]		   =					DatasetMetadata.from_readme(lowercase_			)
       self.assertDictEqual(lowercase_	,     {}			)

       with open(lowercase_	,     'w+'			) as readme_file:
        readme_file.write(lowercase_			)
       UpperCAmelCase			:      Optional[Any]		   =					DatasetMetadata.from_readme(lowercase_			)
       self.assertEqual(lowercase_	,     {}			)




     def   UpperCAmelCase_			(						self					:	Union[str, Any]			)		->      str:
      UpperCAmelCase			:      Tuple		   =					_dedent(
          '\\n            annotations_creators:\n            - found\n            language_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - question-answering\n            task_ids:\n            - open-domain-qa\n            '			)
      assert DatasetMetadata.from_yaml_string(lowercase_			)

      UpperCAmelCase			:      Any		   =					_dedent(
          '\\n            annotations_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - question-answering\n            task_ids:\n            - open-domain-qa\n            task_ids:\n            - open-domain-qa\n            '			)
      with self.assertRaises(lowercase_			):
       DatasetMetadata.from_yaml_string(lowercase_			)

      UpperCAmelCase			:      List[Any]		   =					_dedent(
          '\\n            annotations_creators:\n            - found\n            language_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - text-classification\n            task_ids:\n            - multi-class-classification\n            paperswithcode_id:\n            - squad\n            configs:\n            - en\n            train-eval-index:\n            - config: en\n              task: text-classification\n              task_id: multi_class_classification\n              splits:\n                train_split: train\n                eval_split: test\n              col_mapping:\n                text: text\n                label: target\n              metrics:\n                - type: accuracy\n                  name: Accuracy\n            extra_gated_prompt: |\n              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:\n              [RESEARCHER_FULLNAME] (the "Researcher") has requested permission to use the ImageNet database (the "Database") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:\n              1. Researcher shall use the Database only for non-commercial research and educational purposes.\n            extra_gated_fields:\n              Company: text\n              Country: text\n              I agree to use this model for non-commerical use ONLY: checkbox\n            '			)
      assert DatasetMetadata.from_yaml_string(lowercase_			)







'''simple docstring'''

from sklearn.metrics import accuracy_score

import datasets


lowercase__            =     "\nAccuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:\nAccuracy = (TP + TN) / (TP + TN + FP + FN)\n Where:\nTP: True positive\nTN: True negative\nFP: False positive\nFN: False negative\n"


lowercase__            =     "\nArgs:\n    predictions (`list` of `int`): Predicted labels.\n    references (`list` of `int`): Ground truth labels.\n    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.\n    sample_weight (`list` of `float`): Sample weights Defaults to None.\n\nReturns:\n    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.\n\nExamples:\n\n    Example 1-A simple example\n        >>> accuracy_metric = datasets.load_metric(\"accuracy\")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])\n        >>> print(results)\n        {'accuracy': 0.5}\n\n    Example 2-The same as Example 1, except with `normalize` set to `False`.\n        >>> accuracy_metric = datasets.load_metric(\"accuracy\")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)\n        >>> print(results)\n        {'accuracy': 3.0}\n\n    Example 3-The same as Example 1, except with `sample_weight` set.\n        >>> accuracy_metric = datasets.load_metric(\"accuracy\")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])\n        >>> print(results)\n        {'accuracy': 0.8778625954198473}\n"


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




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






     '''simple docstring'''



     def   UpperCAmelCase_			(						self					:	int			)		->      str:
      return datasets.MetricInfo(
          description=_DESCRIPTION	,     citation=_CITATION	,     inputs_description=_KWARGS_DESCRIPTION	,     features=datasets.Features(
              {
                  'predictions': datasets.Sequence(datasets.Value('int32'			)			),
                  'references': datasets.Sequence(datasets.Value('int32'			)			),
              }
              if self.config_name == 'multilabel'
              else {
                  'predictions': datasets.Value('int32'			),
                  'references': datasets.Value('int32'			),
              }			)	,     reference_urls=['https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html']	,     )




     def   UpperCAmelCase_			(						self					:	str	,     lowercase_					:	Union[str, Any]	,     lowercase_					:	Any	,     lowercase_					:	Tuple=True	,     lowercase_					:	Union[str, Any]=None			)		->      Dict:
      return {
          "accuracy": float(
              accuracy_score(lowercase_	,     lowercase_	,     normalize=lowercase_	,     sample_weight=lowercase_			)			)
      }




