# Report JSON Metrics This document explains every field emitted in an `overall_accuracy_report.json` produced by this kit (via `evaluate_from_hf.py` or `evaluation/measure_overall_accuracy.py`). The report is generated by, e.g.: ```bash python3 evaluate_from_hf.py \ --dataset RLALT/ACoPPer \ --predictions-dir path/to/your/evaluation_csvs \ --output-dir results/ ``` See [README.md](README.md) for the full pipeline explanation. The metrics below are computed primarily in `evaluation/measure_accuracy.py` and aggregated in `evaluation/measure_overall_accuracy.py`. ## Conventions - **Row**: one predicted OCR row (`group_row`) composed of multiple OCR word boxes. - **Word box**: one OCR detection box from the CSV (one row in the CSV file). - **Annotation box / GT box**: one labeled text box from the JSON annotations. - **Region**: a connected component of transcribed GT boxes according to which boxes are jointly touched by predicted rows. Isolated GT boxes also become one-box regions, even when no predicted row is assigned. - **CER**: character error rate, computed as `char_edit_distance / gt_char_count` with `safe_error_rate` behavior (see below). ### Rounding / safe helpers - `safe_rate(count, total)`: `round(count / total, 6)` (or `0.0` when `total == 0`). - `safe_mean(values)`: `round(sum(values) / len(values), 6)` (or `0.0` when empty). - `safe_error_rate(edit_distance, gt_len)`: - if `gt_len == 0`: returns `0.0` when `edit_distance == 0`, else `1.0` - else: `round(edit_distance / gt_len, 6)` ## Top-Level JSON Shape The file is a JSON object with these keys: - `summary`: aggregate metrics across all matched page pairs. - `pages`: list of per-page reports. - `split_line_groups`: all split-line groups across pages (already enriched with page metadata). - `ignored_rows`: all ignored watermark rows across pages (already enriched with page metadata). - `excluded_labels`: report-level label metadata used by filtered metrics. Written once at the end of the JSON object. ## `summary` (Aggregate Metrics) All fields below exist under `summary` at the top level. The same set (minus `pair_count`) exists under each `pages[i].summary`. - `pair_count`: number of matched `(csv,json)` page pairs processed. - `total_rows`: number of predicted rows evaluated (excluding ignored watermark rows). - `ignored_watermark_rows`: number of predicted rows ignored because they were classified as watermark. - `exactly_one_box`: count of predicted rows whose final status is `exactly_one_box`. Split-line postprocessing runs before this count, so rows reclassified as `split_line` are not included. - `exactly_one_box_rate`: `exactly_one_box / total_rows`. - `multiple_boxes`: count of predicted rows whose final status is `multiple_boxes`. - `multiple_boxes_rate`: `multiple_boxes / total_rows`. - `no_box`: count of predicted rows whose final status is `no_box`. - `no_box_rate`: `no_box / total_rows`. - `split_line`: number of split-line groups detected. Each group corresponds to one GT box whose text was split across multiple predicted row fragments. - `split_line_rate`: `split_line / total_rows`. This is group count over row count, so compare it carefully with `split_line_rows_rate`. - `split_line_rows`: number of predicted rows whose final status is `split_line`. - `split_line_rows_rate`: `split_line_rows / total_rows`. - `mean_best_coverage`: mean of `dominant_coverage` across evaluated rows (after watermark removal). Higher is better. ### OCR region metrics (`ocr_region_*`) These are computed over `ocr_regions` (regions are connected components of transcribed GT boxes). - `ocr_region_count`: number of OCR regions. - `multibox_region_count`: number of OCR regions containing more than one GT box. - `ocr_region_mean_cer`: simple mean of per-region CER (`mean(cer_i)`). - `ocr_region_cer`: corpus CER across all regions, computed as `(sum char_edit_distance) / (sum gt_char_count)`. - `ocr_region_cer_buckets`: compact CER bucket summary. Each bucket has `count` and `rate`, where `rate = count / ocr_region_count`. CER buckets: - `lt_0_1`: `cer < 0.1` - `0_1_to_0_3`: `0.1 <= cer < 0.3` - `0_3_to_0_6`: `0.3 <= cer < 0.6` - `0_6_to_1`: `0.6 <= cer <= 1.0` - `gt_1`: `cer > 1.0` (can happen when the predicted string has enough insertions that character edit distance exceeds GT character count). ### Normal single-box region metrics `normal_single_box_region` is computed over the subset of `ocr_regions` where the region is considered a "clean" box match: - `len(box_ids) == 1` (region corresponds to exactly one GT box) - the region has at least one assigned OCR row internally - every assigned OCR row has final `status == "exactly_one_box"` This filter excludes: - merged/multi-box regions - split-line rows - regions built from rows that end up `multiple_boxes` or `no_box` Fields inside `normal_single_box_region`: - `count`: number of regions that satisfy the filter. - `mean_cer`: simple mean of CER across filtered regions. - `cer`: corpus CER across filtered regions. Important: this is still a text OCR metric, not a pure layout metric. The filter says column/box separation worked cleanly; CER can still be high if recognition, line ordering, punctuation, or hyphenation failed inside the correct GT box. ### Optional filtered region mode By default, `measure_accuracy.py` and `measure_overall_accuracy.py` compute only the unfiltered `ocr_region_*` metrics. To evaluate filtered regions, pass a comma-separated `--filter` value, for example: - `--filter non-armenian` - `--filter graphics` - `--filter non-armenian,graphics` When filters are active, the primary `ocr_region_*` fields are computed from filtered regions. Excluded GT boxes are removed from region GT text, and predicted word fragments whose centers are inside excluded boxes are removed from region predicted text. Supported filters: - `non-armenian`: excludes GT text boxes where more than 90% of letters are Latin or Cyrillic. The ratio ignores digits, punctuation, and spaces. - `graphics`: excludes boxes labeled `Graphics`. - `photo`: excludes boxes labeled `Photo`. - `image`: excludes image-related labels: `Photo`, `Graphics`, `SealFigure`, `FrontPicture`. - `header`: excludes header/title-like labels: `Headline`, `Kicker`, `Banner`, `Deck`, `Subhead`, `Nameplate`, `Masthead`, `FrontStory`. - `image-header`: excludes both image-related and header/title-like labels. When filters are active, `summary.filter` contains: - `filters`: canonical filter names that were applied. - `text_box_count`: number of transcribed GT boxes. - `excluded_box_count`: number of transcribed GT boxes excluded by the active filters. - `excluded_box_rate`: `excluded_box_count / text_box_count`. - `included_box_count`: transcribed GT boxes remaining after exclusion. - `threshold`: present when `non-armenian` is active. - `labels`: present when label-based filters are active. Per-page and aggregate reports also include `filtered_text_boxes`, the excluded boxes with `box_id`, labels, normalized GT text, matched filters, and non-Armenian ratio fields. ### Empty-word-in-GT-box metric (`missing_text_*`) This measures a detection/recognition failure mode: the OCR CSV contained empty-text word boxes inside GT text areas. - `total_detected_word_boxes`: total number of OCR word boxes in the CSV(s), including boxes whose `text` is empty. - `missing_text_boxes`: number of OCR word boxes whose `text` is empty and whose center lies inside a GT box with non-empty transcription text. - `missing_text_box_rate`: `missing_text_boxes / total_detected_word_boxes`. ## `pages[i]` (Per-Page Report) Each element in `pages` has: - `page_name`: stem name used to match `page_name.csv` with `page_name.json`. - `predictions_csv`: path to the CSV used for that page. - `annotations_json`: path to the annotation JSON used for that page. - `summary`: per-page summary metrics (same meaning as top-level `summary`, but page-scoped and without `pair_count`). - `ocr_regions`: list of region records (see below). Aggregate reports keep all region records so downstream visualizations can use the report JSON as the region source. - `split_line_groups`: list of split-line groups for that page (see below). - `ignored_rows`: list of ignored watermark rows for that page (see below). ## `pages[i].ocr_regions[j]` (Region Record) Keys: - `region_id`: stable identifier for the region (currently the first GT box id in the ordered region). - `box_ids`: ordered GT box ids that belong to this region. - `box_types`: ordered GT box types, derived from the first rectangle label for each GT box, in the same order as `box_ids`; `null` when a box has no label. - `gt_boxes`: list of GT box rectangles for the region in `[x_min, y_min, x_max, y_max]` format (same order as `box_ids`). - `gt_box_details`: ordered GT box metadata. Each item has `box_id`, `box_type`, `labels`, and `box`. - `predicted_box`: merged bounding box of the predicted lines used for this region in `[x_min, y_min, x_max, y_max]` format (or `null` if none). - `predicted_line_count`: number of reconstructed predicted lines. - `normal_single_box_region`: boolean flag used by the summary `normal_single_box_region` metrics. It is true only for one-GT-box regions with at least one assigned row and only final `exactly_one_box` rows. - `text_metrics`: text-comparison metrics for normalized GT text vs normalized predicted text (see below). ### `text_metrics` (in region records) Keys: - `gt_normalized_text`: normalized GT text, with raw report text hidden. - `pr_normalized_text`: normalized predicted text, with raw report text hidden. - `gt_char_count`: `len(gt_normalized_text)`. - `predicted_char_count`: `len(pr_normalized_text)`. - `char_edit_distance`: Levenshtein distance over normalized strings. - `cer`: `safe_error_rate(char_edit_distance, gt_char_count)`. ## `split_line_groups` (Per-Page and Aggregate) A split-line group indicates that multiple predicted rows are fragments of the same GT box line and were reclassified to `split_line`. Keys: - `group_id`: stable group id. - `box_id`: GT box id the split-line group belongs to. - `box_text`: GT text for that box. - `fragment_count`: number of row fragments in the group. - `row_ids`: predicted row ids in reading order. - `row_texts`: the predicted text per row id. - `page_name`, `predictions_csv`, `annotations_json`: present in the aggregate `split_line_groups` list (and in per-page lists after enrichment). ## `ignored_rows` (Per-Page and Aggregate) Rows ignored as watermark. Keys: - `row_id`: predicted row id. - `row_text`: predicted row text. - `words`: list of word texts in the predicted row. - `reason`: currently `"watermark"`. - `page_name`, `predictions_csv`, `annotations_json`: present in the aggregate `ignored_rows` list (and in per-page lists after enrichment). ## Generating These Reports Against the RLALT/ACoPPer or RLALT/ACoPDoc Hugging Face dataset (see [README.md](README.md)): ```shell $ python3 evaluate_from_hf.py \ --dataset RLALT/ACoPPer \ --predictions-dir path/to/your/evaluation_csvs \ --output-dir results/ ``` This writes the standard four report files to `--output-dir`: ```text overall_accuracy_report.json overall_accuracy_filtered_non_armenian_report.json overall_accuracy_filtered_graphics_headers_images_photos_report.json overall_accuracy_filtered_all_report.json ``` The overlay PNGs and matching JSON legends are written under `region_overlays//` inside the selected results directory.