Repository navigation
fix(ifeval): align C++ implementation with Python reference (char counting & whitespace stripping) - #47
Open
AhmedTElthakeb wants to merge 2 commits into
Open
fix(ifeval): align C++ implementation with Python reference (char counting & whitespace stripping)#47AhmedTElthakeb wants to merge 2 commits into
AhmedTElthakeb wants to merge 2 commits into
Conversation
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR brings the C++ IFEval implementation in line with the Python reference by fixing two discrepancies that caused different scoring behavior.
Changes
1. Count characters, not bytes, in tolerance checks
Problem: The
ends_with,starts_with, andConstrainedResponsechecks usedstd::string::size()which counts bytes, while the Python reference useslen()which counts characters. Any non-ASCII character in the tolerance window caused the C++ check to fail where Python would pass.Example:
"My answer is no. ⁇ "is 19 characters (passes Python limit of 16+3) but 21 bytes (fails in C++).Fix:
utf8_len()to count UTF-8 characters (lead bytes only)utf8_offset()to get byte offset of the n-th characterends_with(),starts_with(), andConstrainedResponse::verify_()to use character counting2. Strip whitespace to match Python reference behavior
Problem: The C++ implementation didn't strip whitespace in places where the Python reference does, causing responses with leading/trailing whitespace or blank lines to score differently.
Fix:
transform_response()to trim after removing first/last lines (matching Python order)IsFollowed()to prevent blank text from counting as following (strict and loose modes)Quotation::verify_()to trim the response before checking for quotesFiles Modified
common.h: Added UTF-8 helper functions, updatedends_with(),starts_with(), andtransform_response()types.h: UpdatedInstruction::IsFollowed(),ConstrainedResponse::verify_(), andQuotation::verify_()