Monday, June 24, 2024

Regex Match Evaluator

Code is like this below somewhat 

def regex_match_evaluator():

   evaluator = RegexMatchStringEvaluator()

   score = evaluator.evaluate_strings(

    prediction="The delivery will be made on 2024-01-05",

    reference=".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*",

   )

   print("Score from first check ", score)

   # Check for the presence of a MM-DD-YYYY string or YYYY-MM-DD

   score = evaluator.evaluate_strings(

        prediction="The delivery will be made on 01-05-2024",

        reference="|".join(

            [".*\\b\\d{4}-\\d{2}-\\d{2}\\b.*", ".*\\b\\d{2}-\\d{2}-\\d{4}\\b.*"]

        ),

    )

   print("Score from second check ", score)

   evaluator = RegexMatchStringEvaluator(flags=re.IGNORECASE)

   score = evaluator.evaluate_strings(

    prediction="I LOVE testing",

    reference="I love testing",

   )

   print("Score evaluation for regex match fianl ", score)



References:

https://python.langchain.com/v0.1/docs/guides/productionization/evaluation/string/regex_match/


No comments:

Post a Comment