in src/fmeval/eval_algorithms/classification_accuracy.py [0:0]
def evaluate_sample(self, target_output: str, model_output: str) -> List[EvalScore]:
"""Compute classification accuracy metrics for a single sample.
:param target_output: The expected/desired model output.
:param model_output: The actual model output.
:returns: A single-element list with an EvalScore for the classification accuracy score.
"""
util.require(
self.valid_labels,
"ClassificationAccuracy evaluate_sample method requires the `valid_labels` "
"attribute of the ClassificationAccuracy instance to be set.",
)
sample = {
DatasetColumns.TARGET_OUTPUT.value.name: target_output,
DatasetColumns.MODEL_OUTPUT.value.name: model_output,
}
pipeline = self._build_pipeline(self.valid_labels)
result = pipeline.execute_record(sample)
return [
EvalScore(
name=CLASSIFICATION_ACCURACY_SCORE,
value=result[CLASSIFICATION_ACCURACY_SCORE], # type: ignore
)
]