Exact Match Score with Normalization

Text Generation & NLP Evaluation DS practice problem on Onlearn.

Difficulty: medium.

Topics: Exact Match Score with Normalization, Unicode Case Folding, Levenshtein Distance, Whitespace Tokenization, Punctuation Stripping, Exact Match Accuracy, Natural Language Processing, Information Retrieval, Software Engineering, Data Preprocessing, Statistical Evaluation, Text Normalization, String Matching Algorithms, Evaluation Metrics, Corpus Cleaning, Regex Pattern Matching.

Implement a function that calculates the Exact Match (EM) score between a list of predicted strings and a list of reference (ground truth) strings. The Exact Match score is a common evaluation metric in NLP tasks like question answering and text generation. It measures the proportion of predictions that exactly match the corresponding references. To make the comparison more robust, your function should normalize both predictions and references before comparison. The normalization should: Convert text to lowercase Remove all punctuation characters Collapse multiple whitespace characters into single spaces and strip leading/trailing whitespace The function should return a float representing the proportion of exact matches (between 0.0 and 1.0). If both input lists are empty, return 0.0.