POPE Object Hallucination Accuracy
Problem Statement
POPE probes object hallucination with yes/no questions ("Is there a chair in the image?"). Score a batch of the model's yes/no answers against the ground truth.
Background
Each item has a ground-truth label ("yes" if the object is present, "no" if not) and the model's answer. Accuracy is the fraction of matching answers:
A model that hallucinates says "yes" to absent objects, tanking accuracy on the "no" questions.
Your Task
Implement:
def pope_accuracy(answers, truths):
Return the accuracy as a float rounded to 4 decimals. Comparison is case-insensitive and ignores surrounding whitespace.
Input Format
- answers: list of strings (the model's answers).
- truths: list of strings (ground truth), same length.
Output Format
- A float rounded to 4 decimals.
Sample
print(pope_accuracy(["yes", "No", "yes"], ["yes", "no", "no"]))
Output:
0.6667
Example
print(pope_accuracy(["yes", "No", "yes"], ["yes", "no", "no"]))
0.6667
- Normalize the inputs by stripping whitespace and converting to lowercase to ensure case-insensitive comparison: the answers become
["yes", "no", "yes"]and the truths become["yes", "no", "no"]. - Compare each pair of normalized strings to determine correctness:
- Pair 1:
"yes"vs"yes"→ Match - Pair 2:
"no"vs"no"→ Match - Pair 3:
"yes"vs"no"→ Mismatch
- Pair 1:
- Count the total number of matches: out of total items are correct.
- Calculate the accuracy by dividing the number of correct answers by the total number of items:
- Round the result to 4 decimal places as required: .
- The final output is 0.6667
Constraints
len(answers) == len(truths),1 <= N <= 100000.- Compare case-insensitively after stripping whitespace.
- Round to 4 decimals.