KatInterview

Detect Suspicious Annotators in Data Pipelines

SQL & DataModel answer
HardModel answerSQL & Datapandasdata-cleaningdata-analysis

Last updated

Process crowd-sourced label data to compute consensus metrics and flag underperforming annotators at scale.

You are building an evaluation pipeline to monitor label quality across a crowdsourced data labeling workflow. A dataset contains multi-worker annotations alongside reference ground-truth labels for a subset of images.

Write a function identify_low_quality_annotator(df) that processes a pandas DataFrame df and returns the annotator_id of the worker whose annotations demonstrate the poorest quality.

Input Schema

df contains the following columns:

  • annotator_id (str): Unique worker identifier.
  • image_id (str): Unique item identifier.
  • label (int): Class label (0 or 1).
  • is_ground_truth (bool): True if this row represents a validated gold-standard reference label; False if it is a submission from a general annotator.

Logic & Scoring Rules

  1. Gold Reference Definition: A ground-truth reference for an image_id is derived from rows where is_ground_truth == True. If an image has multiple conflicting gold rows (e.g., one row with label = 0 and another with label = 1), that image is considered ambiguous and must be completely excluded from evaluation.
  2. Annotator Accuracy Calculation:
    • An annotator's quality metric is calculated as their accuracy rate on distinct gold-standard images they labeled.
    • If a non-gold row shares an image_id and label value with the image's gold reference, it is scored as correct (1), otherwise incorrect (0).
    • If an annotator labeled the same gold image multiple times, drop duplicates to ensure each distinct image is counted at most once per annotator (keeping the first entry).
  3. Statistical Threshold: To prevent sample size noise, only include annotators who have evaluated at least 20 distinct valid ground-truth images. Workers with fewer than 20 evaluated gold images must be ignored. Annotators with zero gold interactions are automatically excluded.
  4. Tie-Breaking Order:
    • Primary metric: Lowest accuracy rate (correct_gold_labels / total_gold_images_evaluated).
    • First tie-breaker: Smallest total count of non-gold annotations submitted by the worker across the entire dataset.
    • Second tie-breaker: Lexicographically smallest annotator_id (ascending order).
  5. Null Handling: If no single annotator satisfies the 20-gold-image threshold (or if df contains no usable evaluation rows), return None.

Example

import pandas as pd

data = {
    'annotator_id': ['worker_1', 'worker_1', 'worker_2', 'worker_2', 'worker_3'],
    'image_id': ['img_1', 'img_2', 'img_1', 'img_2', 'img_1'],
    'label': [1, 0, 0, 1, 1],
    'is_ground_truth': [False, False, False, False, True]
}
df = pd.DataFrame(data)

# Calling identify_low_quality_annotator(df) returns None 
# because no worker has evaluated >= 20 ground-truth images.

Hints

Hint 1

Isolate the gold reference labels first by checking `is_ground_truth == True` and dropping images that contain conflicting reference values.

Hint 2

Join non-gold annotations with valid gold references using `image_id` to compute individual match scores.

Hint 3

Make sure total work counts consider all non-gold rows per worker, while accuracy evaluation is filtered only to qualified gold matches.