[docs]classExactMatchStringEvaluator(StringEvaluator):"""Compute an exact match between the prediction and the reference. Examples ---------- >>> evaluator = ExactMatchChain() >>> evaluator.evaluate_strings( prediction="Mindy is the CTO", reference="Mindy is the CTO", ) # This will return {'score': 1.0} >>> evaluator.evaluate_strings( prediction="Mindy is the CTO", reference="Mindy is the CEO", ) # This will return {'score': 0.0} """
@propertydefrequires_input(self)->bool:""" This evaluator does not require input. """returnFalse@propertydefrequires_reference(self)->bool:""" This evaluator requires a reference. """returnTrue@propertydefinput_keys(self)->List[str]:""" Get the input keys. Returns: List[str]: The input keys. """return["reference","prediction"]@propertydefevaluation_name(self)->str:""" Get the evaluation name. Returns: str: The evaluation name. """return"exact_match"def_evaluate_strings(# type: ignore[arg-type,override]self,*,prediction:str,reference:str,**kwargs:Any,)->dict:""" Evaluate the exact match between the prediction and the reference. Args: prediction (str): The prediction string. reference (Optional[str], optional): The reference string. Returns: dict: The evaluation results containing the score. """ifself.ignore_case:prediction=prediction.lower()reference=reference.lower()ifself.ignore_punctuation:prediction=prediction.translate(str.maketrans("","",string.punctuation))reference=reference.translate(str.maketrans("","",string.punctuation))ifself.ignore_numbers:prediction=prediction.translate(str.maketrans("","",string.digits))reference=reference.translate(str.maketrans("","",string.digits))return{"score":int(prediction==reference)}