|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""HTER metric.""" |
|
|
|
import datasets |
|
|
|
|
|
import evaluate |
|
|
|
|
|
_DESCRIPTION = """ |
|
HTER (Half Total Error Rate) is a metric that combines the False Accept Rate (FAR) and False Reject Rate (FRR) to provide a comprehensive evaluation of a system's performance. It can be computed with: |
|
HTER = (FAR + FRR) / 2 |
|
Where: |
|
FAR (False Accept Rate) = FP / (FP + TN) |
|
FRR (False Reject Rate) = FN / (FN + TP) |
|
TP: True positive |
|
TN: True negative |
|
FP: False positive |
|
FN: False negative |
|
""" |
|
|
|
|
|
_KWARGS_DESCRIPTION = """ |
|
Args: |
|
predictions (`list` of `int`): Predicted labels. |
|
references (`list` of `int`): Ground truth labels. |
|
|
|
Returns: |
|
HTER (`float` or `int`): HTER score. Minimum possible value is 0. Maximum possible value is 1.0. |
|
|
|
Examples: |
|
|
|
Example 1-A simple example |
|
>>> hter_metric = evaluate.load("murinj/hter") |
|
>>> results = hter_metric.compute(references=[0, 0], predictions=[0, 1]) |
|
>>> print(results) |
|
{'HTER': 0.25} |
|
|
|
""" |
|
|
|
|
|
_CITATION = """ |
|
} |
|
""" |
|
|
|
|
|
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION) |
|
class Hter(evaluate.Metric): |
|
def _info(self): |
|
return evaluate.MetricInfo( |
|
description=_DESCRIPTION, |
|
citation=_CITATION, |
|
inputs_description=_KWARGS_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"predictions": datasets.Value("int32"), |
|
"references": datasets.Value("int32"), |
|
} |
|
), |
|
) |
|
|
|
def _compute(self, predictions, references): |
|
TP = 0 |
|
TN = 0 |
|
FP = 0 |
|
FN = 0 |
|
|
|
for pred, ref in zip(predictions, references): |
|
if pred == 1 and ref == 1: |
|
TP += 1 |
|
elif pred == 0 and ref == 0: |
|
TN += 1 |
|
elif pred == 1 and ref == 0: |
|
FP += 1 |
|
elif pred == 0 and ref == 1: |
|
FN += 1 |
|
|
|
|
|
FAR = FN / (TP + FN) if (TP + FN) > 0 else 0 |
|
|
|
FRR = FP / (TN + FP) if (TN + FP) > 0 else 0 |
|
|
|
HTER = (FAR + FRR) / 2.0 |
|
|
|
|
|
HTER = (FAR + FRR) / 2.0 |
|
return { |
|
"HTER": HTER |
|
} |
|
|