Fix `text` column: restore inter-word spaces lost in hOCR extraction

#2
by davanstrien HF Staff - opened
BigLAM: BigScience Libraries, Archives and Museums org

What

Rebuilds the text column from the Internet Archive's own OCR output.

Why

The current text column was produced by an hOCR β†’ plain-text step that joined
word spans with "" instead of " ". The result is that 453,006 of 453,006
text-bearing rows contain exactly zero space characters
:

current : Danville,MontourCounty,Pennsylvania.Acollectionofhistor-
IA text : Danville, Montour County, Pennsylvania. A collection of histor-

This is not a Tesseract or Internet Archive problem β€” IA's published text is
correct, and the characters in the current column are already right. Only the
spaces are missing. The practical effect is that keyword search over this column
cannot work (there are no word tokens), and any benchmark using it as an OCR
baseline is measuring the extraction bug rather than OCR quality.

Measured on a 500-card sample against three VLM transcriptions: the current
column scores 21.3% median CER, but 9.6% with whitespace removed β€” level with the
~9.4% the VLMs disagree with each other by. The characters were never the problem.

How

Rather than re-parsing hOCR (the step that introduced the bug), this reads IA's
per-item published text directly:

  • *_hocr_searchtext.txt.gz β€” one text blob per drawer
  • *_hocr_pageindex.json.gz β€” [start_char, end_char, ...] per page

Page order maps 1:1 onto card_number, verified across all drawers: page count
equals row count for 385/385 drawers, zero mismatches, zero missing items.

Effect

  • 838,023 rows rewritten (every row)
  • 99.3% of non-blank rows now contain spaces (the remainder are single-word cards)
  • 454,899 rows have text, up from 453,006 β€” space-stripping had collapsed ~1,893
    cards to empty strings
  • Images, column order, row order and schema are untouched

Note

dataset_info.num_bytes / dataset_size in the card are now marginally stale.
The delta is roughly 22 MB of restored spaces against 82 GB of images (~0.03%),
so I left the card alone to keep this diff reviewable.

davanstrien changed pull request status to open
davanstrien changed pull request status to merged

Sign up or log in to comment