PIXELBANKv9.1.0
Menu

CHAIR-i and CHAIR-s Hallucination Rates

Problem Statement

CHAIR measures caption hallucination two ways: per-instance (what fraction of mentioned objects are wrong) and per-sentence (what fraction of captions contain any hallucination). Compute both over a set of captions.

Background

For each caption you get the set of objects the model mentioned and the set of objects actually present (the ground truth). An object is hallucinated if it was mentioned but is not present. Then:

CHAIRi=∑c∣hallucinatedc∣∑c∣mentionedc∣,CHAIRs=#{c:∣hallucinatedc∣>0}#captions\text{CHAIR}_i = \frac{\sum_c |\text{hallucinated}_c|}{\sum_c |\text{mentioned}_c|}, \qquad \text{CHAIR}_s = \frac{\#\{c : |\text{hallucinated}_c| > 0\}}{\#\text{captions}}

Lower is better for both. A caption that mentions nothing contributes 0 to both numerators (and 0 mentions to the CHAIR-i denominator).

Your Task

Implement:

def chair(mentioned, present):
  • mentioned[c], present[c]: lists of object names (treat as sets) for caption c.

Return a dict with "chair_i" and "chair_s", each rounded to 4 decimals. If total mentions is 0, chair_i is 0.0.

Input Format

  • mentioned: list of lists of object names.
  • present: list of lists of object names, same length.

Output Format

  • A dict of two floats.

Sample

m = [["dog", "cat"], ["car"]]
p = [["dog"], ["car", "tree"]]
print(chair(m, p))

Output:

{'chair_i': 0.3333, 'chair_s': 0.5}

Example:

Input:
m = [["dog", "cat"], ["car"]]
p = [["dog"], ["car", "tree"]]
print(chair(m, p))
Output:
{'chair_i': 0.3333, 'chair_s': 0.5}
Reasoning:

Caption 0 mentions {dog,cat}, present {dog}: cat hallucinated (1 of 2). Caption 1 mentions {car}, present {car,tree}: 0 hallucinated. CHAIR-i = 1/3 = 0.3333; CHAIR-s = 1 of 2 captions = 0.5.

Constraints:

  • len(mentioned) == len(present), 1 <= num_captions <= 100000.
  • Treat each list as a set (ignore duplicates within a caption).
  • A hallucinated object is mentioned but not present.
  • Round both to 4 decimals; chair_i is 0.0 when there are no mentions.
🔒

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.
CHAIR-i and CHAIR-s Hallucination Rates - Medium | PixelBank