fix: handle a=0 as valid answer index in build_qa_turn #3488
+34
−2
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
Fixes #3452 - Performance decreasing when passing from 0 to few shots
Root Cause
In
build_qa_turn(), the conditionif a and not gen_prefixincorrectly treateda=0(a valid answer index) as falsy, causing thetarget_delimiterto be skipped for few-shot examples where the answer was the first choice.The Bug
When a few-shot example has
answer=0:Answer:A(no space - wrong)Answer: A(with space - correct)This inconsistency confused models because few-shot examples showed a different format than what the model was asked to predict.
The Fix
Changed truthiness check to explicit None/empty check:
Testing
Added 2 regression tests for answer index 0 and non-zero cases
All 48 fewshot context tests pass