metrics_list = list_metrics()

jy: 47

print(len(metrics_list))

print(metrics_list) “”” [‘accuracy’, ‘bertscore’, ‘bleu’, ‘bleurt’, ‘cer’, ‘chrf’, ‘code_eval’, ‘comet’, ‘competition_math’, ‘coval’, ‘cuad’, ‘exact_match’, ‘f1’, ‘frugalscore’, ‘glue’, ‘google_bleu’, ‘indic_glue’, ‘mae’, ‘mahalanobis’, ‘matthews_correlation’, ‘mauve’, ‘mean_iou’, ‘meteor’, ‘mse’, ‘pearsonr’, ‘perplexity’, ‘precision’, ‘recall’, ‘rl_reliability’, ‘roc_auc’, ‘rouge’, ‘sacrebleu’, ‘sari’, ‘seqeval’, ‘spearmanr’, ‘squad’, ‘squad_v2’, ‘super_glue’, ‘ter’, ‘trec_eval’, ‘wer’, ‘wiki_split’, ‘xnli’, ‘xtreme_s’, ‘jordyvl/ece’, ‘lvwerra/aweeesoooome_metric’, ‘lvwerra/test’] “””

  1. <a name="ZfRyP"></a>
  2. ## 1、Load metric
  3. - It is very easy to load a metric with Datasets. In fact, you will notice that it is very similar to loading a dataset!
  4. - Load a metric from the Hub with `load_metric()`:
  5. - `load_metric()`:[https://huggingface.co/docs/datasets/v2.2.1/en/package_reference/loading_methods#datasets.load_metric](https://huggingface.co/docs/datasets/v2.2.1/en/package_reference/loading_methods#datasets.load_metric)
  6. ```python
  7. from datasets import load_metric
  8. metric = load_metric('glue', 'mrpc')
  • This will load the metric associated with the MRPC dataset from the GLUE benchmark.

    2、Select a configuration

  • If you are using a benchmark dataset, you need to select a metric that is associated with the configuration you are using.

  • Select a metric configuration by providing the configuration name:

    1. metric = load_metric('glue', 'mrpc')

    3、Metrics object

  • Before you begin using a Metric object, you should get to know it a little better. As with a dataset, you can return some basic information about a metric. For example, access the inputs_description parameter in datasets.MetricInfo to get more information about a metrics expected input format and some usage examples:

    • Metrichttps://huggingface.co/docs/datasets/v2.2.1/en/package_reference/main_classes#datasets.Metric
    • datasets.MetricInfohttps://huggingface.co/docs/datasets/v2.2.1/en/package_reference/main_classes#datasets.MetricInfo
      1. print(metric.inputs_description)
      2. """
      3. Compute GLUE evaluation metric associated to each GLUE dataset.
      4. Args:
      5. predictions: list of predictions to score.
      6. Each translation should be tokenized into a list of tokens.
      7. references: list of lists of references for each translation.
      8. Each reference should be tokenized into a list of tokens.
      9. Returns: depending on the GLUE subset, one or several of:
      10. "accuracy": Accuracy
      11. "f1": F1 score
      12. "pearson": Pearson Correlation
      13. "spearmanr": Spearman Correlation
      14. "matthews_correlation": Matthew Correlation
      15. Examples:
      16. >>> glue_metric = datasets.load_metric('glue', 'sst2') # 'sst2' or any of ["mnli", "mnli_mismatched", "mnli_matched", "qnli", "rte", "wnli", "hans"]
      17. >>> references = [0, 1]
      18. >>> predictions = [0, 1]
      19. >>> results = glue_metric.compute(predictions=predictions, references=references)
      20. >>> print(results)
      21. {'accuracy': 1.0}
      22. ...
      23. >>> glue_metric = datasets.load_metric('glue', 'mrpc') # 'mrpc' or 'qqp'
      24. >>> references = [0, 1]
      25. >>> predictions = [0, 1]
      26. >>> results = glue_metric.compute(predictions=predictions, references=references)
      27. >>> print(results)
      28. {'accuracy': 1.0, 'f1': 1.0}
      29. ...
      30. """
  • Notice for the MRPC configuration, the metric expects the input format to be zero or one. For a complete list of attributes you can return with your metric, take a look at MetricInfo.

  • Once you have loaded a metric, you are ready to use it to evaluate a models predictions. Provide the model predictions and references to compute():