PIXELBANKv9.1.0
Menu

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:

acc=#{i:answeri=truthi}N\text{acc} = \frac{\#\{i : \text{answer}_i = \text{truth}_i\}}{N}

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:

Input:
print(pope_accuracy(["yes", "No", "yes"], ["yes", "no", "no"]))
Output:
0.6667
Reasoning:
  • 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
  • Count the total number of matches: 22 out of 33 total items are correct.
  • Calculate the accuracy by dividing the number of correct answers by the total number of items: acc=23≈0.66666...\text{acc} = \frac{2}{3} \approx 0.66666...
  • Round the result to 4 decimal places as required: 0.66670.6667.
  • The final output is 0.6667

Constraints:

  • len(answers) == len(truths), 1 <= N <= 100000.
  • Compare case-insensitively after stripping whitespace.
  • Round to 4 decimals.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
POPE Object Hallucination Accuracy - Easy | PixelBank