Boxed Answer Extraction for Math Benchmarks
Text Generation & NLP Evaluation DS practice problem on Onlearn.
Difficulty: medium.
Topics: Boxed Answer Extraction for Math Benchmarks, LaTeX Delimiter Detection, Zero-shot Prompting, Post-processing Heuristics, F1-Score Calculation, Context Window Management, Natural Language Processing, Information Extraction, Automated Reasoning, Large Language Model Evaluation, Regex and Pattern Matching, Named Entity Recognition, Structured Output Parsing, Chain-of-Thought Verification, Tokenization Strategies, Prompt Engineering Frameworks.
Implement a function that extracts the final answer from a model's response in math benchmarks like MATH and GSM8K. In these benchmarks, models are expected to output their final answer enclosed in a LaTeX style \boxed{} command, for example: \boxed{42}. Your function should: 1. Find and extract the content within \boxed{...} from the response string 2. Handle nested braces correctly (e.g., \boxed{\frac{1}{2}} should extract \frac{1}{2}) 3. If multiple \boxed{} expressions exist, return the content from the last one 4. If no \boxed{} is found, return an empty string Note: The input string will contain the literal characters backslash boxed openbrace, not a LaTeX rendering.