huggingface/evaluate
repository·main·Indexed 25 days ago
https://github.com/huggingface/evaluateA library designed to standardize the evaluation and comparison of machine learning models. It provides access to numerous popular metrics across NLP and Computer Vision, supports frameworks such as NumPy, PyTorch, and TensorFlow, and allows users to host and share custom metrics on the Hugging Face Hub. It includes specialized tools for model comparison (e.g., exact_match, McNemar's test, Wilcoxon signed-rank test) and measurements like HONEST for hurtful completions and label_distribution for dataset balance.
What's inside evaluate
- LightEval is a comprehensive and customizable library specifically designed for evaluating Large Language Models (LLMs). It is recommended for users looking for recent evaluation approaches currently popular on the Hugging Face Hub.
Use 🤗 Evaluate for machine learning evaluation
main🤗 Evaluate is a library designed for easily evaluating machine learning models and datasets across various domains like NLP, Computer Vision, and Reinforcement Learning. It provides access to dozens of evaluation methods in a consistent and reproducible way, suitable for both local machines and distributed training setups.CER Calculation Formula and Behavior
mainThe Character Error Rate (CER) is computed using the following formula:
CER = (S + D + I) / N = (S + D + I) / (S + D + C)Where:
S: Number of substitutionsD: Number of deletionsI: Number of insertionsC: Number of correct charactersN: Total number of characters in the reference (N = S + D + C)
Note on values > 1.0: Because insertions (
I) are included in the numerator but not the denominator (which is based on the reference lengthN), a high number of insertions can result in a CER greater than 1.0.Understand the EvaluationModule hierarchy
mainThe
EvaluationModuleis the core base class for all evaluation logic in the library. It is extended by three specific types of modules:Metric: Used for standard metric calculations.Comparison: Used for comparative evaluations.Measurement: Used for measurement-based evaluations.
Each of these functional modules has a corresponding information class (e.g.,
MetricInfo,ComparisonInfo,MeasurementInfo) that inherits fromEvaluationModuleInfoto handle metadata and descriptive logic.How the FEVER score and Evidence F1 are calculated
mainThe FEVER metric consists of three main evaluation components that serve different purposes:
- Label accuracy: Measures how often the predicted claim label (
SUPPORTED,REFUTED, orNOT ENOUGH INFO) matches the gold label. - FEVER score: A strict metric that considers a prediction correct only if the label is correct and at least one complete gold evidence set is retrieved. Partial evidence retrieval results in a score of 0 for that claim.
- Evidence F1: Computes the micro-averaged precision, recall, and F1 between predicted and gold evidence sentences, focusing on the quality of the retrieved evidence regardless of the label.
- Label accuracy: Measures how often the predicted claim label (
What are the different types of evaluations in 🤗 Evaluate?
main🤗 Evaluate categorizes its tools into three main types to cover different aspects of the machine learning pipeline:
- Metric: Evaluates model performance by comparing model predictions against ground truth labels (e.g.,
accuracy). - Comparison: Used to compare two different models (e.g., comparing their agreement with ground truth).
- Measurement: Used to investigate and describe properties of a dataset itself.
All these types are accessed through the same unified entry point:
evaluate.load.- Metric: Evaluates model performance by comparing model predictions against ground truth labels (e.g.,
Limitations of the Brier Score
mainThe Brier score is appropriate for binary and categorical outcomes that can be structured as true or false. It is inappropriate for ordinal variables which can take on three or more values.Understand ROC AUC output formats
mainThe metric returns a dictionary containing the
roc_aucscore.For binary, multiclass, or multilabel (with
average != None), the value is a singlefloat:{'roc_auc': 0.778}For multilabel with
average=None, the value is anumpy.arrayof floats (one per class):{'roc_auc': array([0.83333333, 0.375, 0.94444444])}
How the Evaluator works
mainThe
Evaluatorclasses allow you to evaluate a triplet of model, dataset, and metric. The models are wrapped in a pipeline that handles preprocessing and post-processing.Supported tasks include:
text-classification(usesTextClassificationEvaluator)token-classification(usesTokenClassificationEvaluator)question-answering(usesQuestionAnsweringEvaluator)image-classification(usesImageClassificationEvaluator)text-generation(usesTextGenerationEvaluator)text2text-generation(usesText2TextGenerationEvaluator)summarization(usesSummarizationEvaluator)translation(usesTranslationEvaluator)automatic-speech-recognition(usesAutomaticSpeechRecognitionEvaluator)audio-classification(usesAudioClassificationEvaluator)
To run evaluations across multiple tasks simultaneously, use the
EvaluationSuite.How distributed evaluation works in 🤗 Evaluate
mainEvaluating non-additive metrics (where $f(A \cup B) \neq f(A) + f(B)$, like F1 score) in a distributed environment is challenging because you cannot simply sum partial results.
🤗 Evaluate handles this by:
- Performing distributed predictions/references on multiple nodes.
- Storing these results temporarily in an Apache Arrow table to save memory.
- Gathering all predictions and references to the first node when
compute()is called. - Performing the final metric evaluation on that single node using the complete dataset.
This allows for high-speed distributed inference while maintaining the mathematical correctness of complex metrics.
Understand the R-squared (R²) metric
mainR-squared is a statistical measure of how well a regression model fits the data.
Mathematical Logic: It is calculated as
1 - (SSR / SST), where:- SSR (Sum of Squared Errors/Residuals): The sum of the squared differences between predicted and actual values.
- SST (Sum of Squared Total): The sum of the squared differences between actual values and the mean of the actual values.
Interpretation:
- 1.0: The model perfectly explains the variance.
- 0.0: The model explains none of the variance.
- Values between 0 and 1: Indicate the degree of variance explained (e.g., 0.75 means 75% of the variance is explained).
Limitations:
- It does not describe the nature of the relationship between variables.
- It is sensitive to irrelevant variables, which can lead to overfitting and artificially high R² values.
- It may be unreliable with small sample sizes.
Understand WER output values and interpretation
mainThe WER metric returns a
floatrepresenting the average number of errors per reference word.- A score of 0.0 indicates a perfect match between predictions and references.
- Lower values indicate better performance.
- A score of 1.0 (or higher in some cases depending on insertions) indicates no match or significant error.
Formula:
WER = (S + D + I) / NWhere:S: SubstitutionsD: DeletionsI: InsertionsN: Total words in reference (S + D + C)C: Correct words