off-allergenqa-jp8 / README.md
syun1013kate's picture
Add OFF snapshot date to dataset card
8638aad verified
|
Raw History Blame Contribute Delete
15.8 kB
metadata
pretty_name: OFF-AllergenQA-JP8
language:
  - en
license: odbl
task_categories:
  - text-classification
tags:
  - text
  - tabular
  - food
  - allergens
  - english
  - safety
  - evaluation

OFF-AllergenQA-JP8

Dataset Summary

OFF-AllergenQA-JP8 is a curated benchmark derived from Open Food Facts (OFF) product data for evaluating allergen detection under an abstention-aware, safety-oriented setting.

The released examples are restricted to U.S.-market packaged multi-ingredient foods whose raw ingredients_text is in English.

For this draft release, the underlying OFF source data snapshot was acquired on March 17, 2026.

Each record represents a (product_id, allergen) pair for one of the Japanese 8 priority allergens (JP8). The "JP8" part refers to the target allergen set, not to the language of the product label:

  • egg
  • milk
  • wheat
  • buckwheat
  • peanuts
  • walnuts
  • shrimp
  • crab

The dataset is designed for evaluating systems that read ingredient text, normalize ingredient mentions to taxonomy IDs, trace evidence through a taxonomy graph, and output one of the following labels:

  • PRESENT
  • TRACE
  • ABSENT
  • UNKNOWN
  • CONFLICT

This is an evaluation dataset, not a consumer-facing food safety database.

What Is Included

The final dataset package contains:

  • products.jsonl: one row per product, with product_id, lang, English ingredients_text, and selected OFF metadata tags
  • gold.jsonl: one row per (product_id, allergen) gold label
  • examples.jsonl: one joined row per example with context, label, and provenance fields
  • splits/train, splits/calib, splits/test: fixed reproducible splits
  • DATASET_MANIFEST.json: build-time metadata and file hashes

Source Data

This dataset is derived from the public Open Food Facts database.

From each OFF product, we extract only the fields needed for allergen evaluation:

  • product_id
  • lang
  • ingredients_text
  • allergens_tags
  • traces_tags
  • labels_tags

We do not rely on OFF tags alone as final ground truth. OFF metadata is used as one source of evidence and as part of candidate selection for human review.

For the released benchmark, we additionally restrict the pool to:

  • U.S.-market products
  • packaged multi-ingredient foods
  • raw English ingredients_text only
  • rows without HTML-tagged ingredient text

How We Built the Dataset

The dataset was built in five stages.

1. Fixed-snapshot download

We first downloaded a date-pinned OFF snapshot so that the source data is reproducible.

Example command:

export OFF_USER_AGENT="YourProjectName/0.1 (your-email@example.com)"
python scripts/download_off_snapshot.py --date YYYY-MM-DD --write_latest

This creates a snapshot directory containing:

  • the products dump
  • OFF taxonomies such as ingredients.json
  • a MANIFEST.json file used for traceability

2. Compact product extraction

We then extracted a compact product table from the OFF products dump, keeping only ingredient text and the metadata fields needed for allergen experiments.

Example command:

python scripts/extract_off_products.py --date YYYY-MM-DD --mode primary

3. Candidate mining

From the extracted product table, we automatically mined difficult or informative candidate examples. Candidate selection is based on:

  • ingredient text
  • OFF metadata tags
  • deterministic normalization to taxonomy IDs
  • taxonomy traversal
  • abstention-aware decision logic

Before mining, the pool is filtered to U.S.-market packaged multi-ingredient foods with English raw ingredients_text.

The candidate miner prioritizes cases such as:

  • apparent allergen evidence in text but missing OFF tags
  • positive OFF tags without matching taxonomy evidence
  • conflicting evidence between text and metadata
  • empty or incomplete inputs
  • low-confidence normalization cases

Example command:

python benchmarks/off_allergenqa_jp8/build_candidates.py \
  --snapshot data/snapshots/YYYY-MM-DD \
  --out runs/off_allergenqa/candidates.jsonl \
  --summary_out runs/off_allergenqa/candidates_summary.csv

Important: candidates.jsonl is not gold data. It is a queue for human annotation.

Rule-Based Provisional Labels Used During Candidate Mining

Before human annotation, each (product_id, allergen) pair may receive a provisional 3-way class used only for candidate mining and balanced selection:

  • 0: Absent / Trap
  • 1: Warning / Trace
  • 2: Intentional ingredient

These provisional classes are not the released gold labels. The final public labels are the 5-way human-reviewed labels (PRESENT, TRACE, ABSENT, UNKNOWN, CONFLICT), so there is no direct one-to-one mapping from 0/1/2 to the released labels.

The rule-based candidate miner applies the following decision order:

  1. If a Contains ... summary explicitly names the target allergen, assign provisional class 2.
  2. Else if warning wording such as may contain, traces of, processed in a facility, or shared equipment names the target allergen, assign provisional class 1.
  3. Else if only a lexical trap is found, such as eggplant for egg, coconut milk for milk, or buckwheat for wheat, assign provisional class 0.
  4. Else if an ingredient term, synonym, or derivative indicates intentional inclusion, assign provisional class 2.
  5. Else if OFF traces_tags contains a target-specific trace hit, assign provisional class 1.
  6. Else if the target allergen is absent but the example is useful as a negative control because other allergen signals or category hints are present, assign provisional class 0.

Additional mining rules and flags:

  • The scope of Contains is cut off at the next May contain, Traces of, ., or ; boundary so that warning text is not incorrectly absorbed into intentional-ingredient evidence.
  • Generic warnings such as may contain tree nuts, may contain shellfish, or contains gluten are separated into a generic warning / abstention slice instead of the main benchmark.
  • Contradictions between raw text and OFF metadata are flagged during mining, for example tag-present but text-not-intentional, text-intentional but tag-missing, or text-warning but trace-tag-missing.
  • Candidate mining artifacts may include audit fields such as proposed_class, reason, evidence, contradiction, and difficulty_tag.

How a Small Annotation Set Was Selected from a Large OFF Pool

The implemented curation pipeline does not sample rows uniformly from all OFF products. It first reduces the search space deterministically, then mines (product, allergen) pairs, then performs balanced hard-case selection.

At a high level, the implemented pipeline is:

  1. Start from a large OFF parquet export.
  2. Apply coarse deterministic filters:
    • U.S.-market products only
    • packaged multi-ingredient foods only
    • raw English ingredients_text only
    • no HTML-tagged ingredient text
    • minimum normalized ingredient length
  3. Perform exact deduplication on normalized ingredient text.
  4. Expand each retained product into up to 8 (product, allergen) candidate pairs, one for each JP8 allergen.
  5. Assign a provisional mining class (0/1/2), hard-case tags, contradiction flags, and evidence snippets.
  6. Split the pool into:
    • a core snack-centric pool used for all allergens
    • a supplement pool used only for rare allergens such as buckwheat, shrimp, and crab when the core pool is insufficient
  7. Select a balanced subset over 8 allergens x 3 provisional classes = 24 cells.

In the documented annotation_hf_v2 run, the pipeline recorded:

  • 4,401,229 raw OFF rows scanned
  • 49,691 eligible products kept after filtering and exact deduplication
  • 269,877 mined (product, allergen) candidates
  • 86,187 hard candidates
  • 77,661 text-grounded hard candidates
  • 1,714 generic warning candidates separated into a distinct slice

The balanced selector then targeted 25 examples per cell (the 600 preset), while allowing shortfalls for cells that are genuinely sparse.

The code prioritizes candidates in this order:

  1. text-grounded hard cases
  2. lower-signal hard cases
  3. easy backfill only when needed

Within each cell, the selection logic further tries to preserve diversity by:

  • limiting how many selected pairs can come from the same barcode
  • limiting how many selected pairs can share the same normalized product name
  • limiting how many examples from the same brand can appear in a single cell
  • suppressing near-duplicate ingredient texts within a cell
  • interleaving different selection_family buckets so that one wording pattern does not dominate
  • using deterministic seed-based tie-breaking

This means the final annotation set is intentionally difficult and diverse, not population-representative.

The curation was also iterative. One intermediate run summary reports 561 selected rows, while a later curated annotation package in annotation_hf_v2_584 contains 584 selected rows derived from a retained base subset plus 41 curated additions. For publication, the count reported in the dataset card should match the final packaged release artifact rather than an intermediate run summary.

4. Double annotation and adjudication

Candidate examples were manually reviewed, ideally by two annotators independently, followed by adjudication for disagreements.

The current annotation tooling is implemented around Label Studio. Each task shown to annotators includes:

  • example_id
  • product_id
  • lang
  • allergen
  • category
  • raw ingredients_text
  • OFF reference metadata fields such as allergens_tags, traces_tags, and labels_tags

The current UI requires a final 5-way label and optionally collects:

  • source_type for the evidence (ingredients_text, off_tags, allergen_statement, or packaging_image)
  • evidence confidence (high, medium, low)
  • a free-text evidence excerpt
  • annotator notes

To reduce bias, model outputs are excluded from exported annotation tasks by default.

The implemented review workflow is:

  1. Export mined candidates to Label Studio tasks.
  2. Have two annotators label the same (product, allergen) items independently.
  3. Accept exact label agreements automatically.
  4. Send mismatches or one-sided missing labels to an adjudication sheet.
  5. Have a human adjudicator fill the final label and optional adjudication evidence/notes.
  6. Build annotations_final.jsonl, an adjudication audit log, and a QA report.

The adjudication template includes enough context to resolve disagreements without reloading the full mining pipeline, including:

  • candidate metadata and category
  • raw ingredients_text
  • OFF metadata tags
  • both annotators' labels
  • both annotators' notes
  • both annotators' evidence summaries

The adjudication outputs include:

  • annotations_final.jsonl
  • adjudication_audit.jsonl
  • qa_report.json
  • QA tables such as disagreement counts and confusion matrices

The QA code computes agreement statistics including raw agreement and Cohen's kappa, and can break disagreements down by allergen and candidate category.

Current implementation note: the Label Studio path stores evidence primarily as free-text excerpts plus source/confidence metadata. Exact character offsets are not collected by default and are stored as [-1, -1] unless added externally.

Label set:

  • PRESENT: the allergen is present
  • TRACE: trace contamination or may-contain style evidence
  • ABSENT: the allergen is absent based on available evidence
  • UNKNOWN: evidence is insufficient to decide
  • CONFLICT: available signals contradict each other

Example commands:

python benchmarks/off_allergenqa_jp8/merge_double_annotations.py \
  --ann_a annotation/exports/annotations_a.jsonl \
  --ann_b annotation/exports/annotations_b.jsonl \
  --merged_out annotation/exports/annotations_merged_agreement.jsonl \
  --disagreements_out annotation/exports/disagreements.csv
python benchmarks/off_allergenqa_jp8/apply_adjudication.py \
  --agreements annotation/exports/annotations_merged_agreement.jsonl \
  --adjudication annotation/exports/adjudication_filled.csv \
  --ann_a annotation/exports/annotations_a.jsonl \
  --ann_b annotation/exports/annotations_b.jsonl \
  --candidates runs/off_allergenqa/candidates.jsonl \
  --out_final annotation/exports/annotations_final.jsonl

5. Final dataset packaging

Finally, we packaged the reviewed examples into a reproducible dataset artifact with fixed splits.

Example command:

python benchmarks/off_allergenqa_jp8/build_dataset.py \
  --candidates runs/off_allergenqa/candidates.jsonl \
  --annotations_final annotation/exports/annotations_final.jsonl \
  --out_dir runs/off_allergenqa/dataset \
  --seed 0 \
  --train_ratio 0.7 \
  --calib_ratio 0.1 \
  --test_ratio 0.2

Label Semantics

PRESENT

The target allergen is explicitly present in the product based on ingredient text or equivalent evidence.

TRACE

The product indicates possible trace contamination or may-contain style evidence, but not confirmed direct inclusion.

ABSENT

The available evidence supports absence of the target allergen.

UNKNOWN

The available evidence is insufficient to decide.

CONFLICT

The available evidence is internally inconsistent, for example if different fields suggest incompatible conclusions.

Important Limitations

  • This dataset is not a random sample of all OFF products. It is intentionally curated toward informative or difficult cases.
  • The label distribution is therefore not representative of population prevalence.
  • OFF entries may be incomplete, inconsistent, or user-contributed.
  • Although the released dataset filters to English ingredients_text, OFF metadata can still be noisy or inconsistent.
  • Human annotation reduces noise, but does not eliminate all ambiguity.
  • TRACE, UNKNOWN, and CONFLICT reflect epistemic uncertainty and data quality issues, not only product properties.

Disclaimer

  • This dataset is provided for research and evaluation purposes only.
  • It does not guarantee food safety.
  • A label of ABSENT or a model output such as SAFE should not be interpreted as a guarantee that a product is safe for people with allergies.
  • When evidence is missing, ambiguous, or contradictory, the correct operational response may be to abstain rather than to predict safety.
  • Users are responsible for checking current product labels, manufacturer disclosures, and jurisdiction-specific regulations before any real-world use.

License and Attribution

This dataset is derived from Open Food Facts data.

According to the official Open Food Facts knowledge base, the OFF database is available under the Open Database License (ODbL), and the two key conditions are attribution and share-alike.

For that reason:

  • please attribute Open Food Facts clearly in the dataset card and any derivative releases
  • do not assume that raw OFF dumps can be republished in arbitrary form
  • if you combine OFF data with other databases, review the share-alike implications carefully

Suggested attribution text:

This dataset is derived in part from Open Food Facts data. Open Food Facts data is made available under the Open Database License (ODbL). Please see the Open Food Facts terms and reuse guidance for details.

Suggested links:

  • Open Food Facts API/data reuse guidance: https://support.openfoodfacts.org/help/en-gb/12-api-data-reuse/94-are-there-conditions-to-use-the-api
  • Open Food Facts terms of use: https://world.openfoodfacts.org/terms-of-use

If your release includes only curated derived rows and human annotations, you may still want to add a repository-level LICENSE file explaining how the released artifact relates to OFF's ODbL terms.