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​∣mentionedc​∣∑c​∣hallucinatedc​∣​,CHAIRs​=#captions#{c:∣hallucinatedc​∣>0}​
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:
m = [["dog", "cat"], ["car"]] p = [["dog"], ["car", "tree"]] print(chair(m, p))
{'chair_i': 0.3333, 'chair_s': 0.5}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_iis0.0when there are no mentions.
1. Background Knowledge
Hallucination in Vision-Language Models (VLMs) refers to the generation of objects or attributes that are not present in the input image. Because VLMs are autoregressive, they can "confabulate" details to make captions sound coherent, even when the visual evidence is absent. Quantifying this behavior is essential for evaluating model reliability in safety-critical applications like medical imaging or autonomous driving.
CHAIR (Caption Hallucination Assessment with Image Reference) is a standard metric for this purpose. It distinguishes between two granularities:
- CHAIRi​ (Instance-level): Measures the density of errors. If a model mentions 10 objects and 2 are wrong, the error rate is 20%. This penalizes models that hallucinate frequently, regardless of how many objects they mention in total.
- CHAIRs​ (Sentence-level): Measures the frequency of errors. If 1 out of 5 captions contains any hallucination, the rate is 20%. This penalizes models that fail to produce even a single clean caption.
The distinction is crucial: a model might have a low CHAIRs​ (most captions are perfect) but a high CHAIRi​ (when it does hallucinate, it hallucinates many objects). Conversely, a model with low CHAIRi​ might still have a high CHAIRs​ if it rarely mentions objects but occasionally gets one wrong.
2. Algorithm Approach
This is a set-difference aggregation problem. The core logic involves:
- Per-caption analysis: For each caption, determine which mentioned objects are hallucinated. This is a set difference operation: hallucinatedc​=mentionedc​∖presentc​.
- Aggregation:
- For CHAIRi​, sum the sizes of all hallucinated sets and divide by the sum of all mentioned set sizes.
- For CHAIRs​, count how many captions have a non-empty hallucinated set and divide by the total number of captions.
The approach is linear in the number of captions and objects. There is no need for complex data structures beyond sets for efficient membership testing.
3. Step-by-Step Strategy
- Initialize accumulators:
- total_mentions = 0 (for CHAIRi​ denominator)
- total_hallucinations = 0 (for CHAIRi​ numerator)
- hallucinated_captions = 0 (for CHAIRs​ numerator)
- total_captions = len(mentioned)
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
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.