Add M1: OCR hub import, WITSML, labels T1-T3, T4 questions, trial raters, draft protocol

- OCR: match the colleague's full-set Dataset Hub export to the DDRs by content
  (3,059/3,066 pages) and QC it against the HTML (CER 2.40%, exact 0.9181).
- WITSML parser and formation tops: 21 DDR wellbores with time logs, 1,384
  reports; WITSML 15/9-F-15 S is DDR 15/9-F-15.
- Deterministic labels T1-T3 (configs/labels.yaml), 1,662 T4 questions with SQL,
  pandas and raw-XML answers in full agreement.
- Trial label validation by three blind LLM raters (not an author or expert audit)
  and rater agreement script; draft protocol_v1 (not locked): split by well.
- Literature notes and BibTeX; docs, report and run_m1.sh synchronised.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 08:34:35 +00:00
parent a3c175638f
commit 17916650a5
37 changed files with 11098 additions and 415 deletions

View File

@@ -1,6 +1,7 @@
"""OCR fidelity: does chandra read from the PDF what the publisher HTML prints?
python scripts/05_ocr_qc.py # after 04_ocr.py; every report whose pages are all read
python scripts/05_ocr_qc.py # after 04_ocr.py; every report whose pages are all read
python scripts/05_ocr_qc.py --source hub # after 04_ocr_hub.py: the Dataset Hub OCR export
ref = the publisher HTML (`rendered.parse_html`), hyp = chandra's blocks of the PDF (`rendered.parse_ocr`), compared
with `qc.exact` (whitespace collapsed, nothing else forgiven). The PDF is a render of the HTML, so the HTML is the
@@ -10,12 +11,13 @@ fields, texts and tables that chandra read but the HTML does not print) as inser
counted on near misses only (edits at most `NEAR` of the reference characters): a cell read into the wrong row or
column is a structure error, not a character error.
Writes outputs/ocr_qc/{items.parquet, doc_metrics.csv, by_field.csv, by_column.csv, confusions.csv, examples.csv,
summary.json, summary.md}.
Writes outputs/ocr_qc/ (outputs/ocr_qc_hub/ with --source hub): items.parquet, doc_metrics.csv, by_field.csv,
by_column.csv, confusions.csv, examples.csv, summary.json, summary.md.
"""
from __future__ import annotations
import argparse
import collections
import json
import sys
@@ -23,7 +25,7 @@ import sys
import pandas as pd
from rapidfuzz.distance import Levenshtein
from volve_dia import ocr, paths
from volve_dia import ocr, ocr_hub, paths
from volve_dia.ddr import qc
from volve_dia.ddr.rendered import parse_html, parse_ocr
@@ -56,17 +58,29 @@ def confusions(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame([{"op": t, "ref": a, "hyp": b, "n": n} for (t, a, b), n in c.most_common()])
SOURCES = {"service": ("ddr_docs.csv", "ocr_qc", "chandra OCR of the PDF (OCR service)"),
"hub": ("hub_docs.csv", "ocr_qc_hub", "chandra OCR of the PDF (Dataset Hub export)")}
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("--source", choices=sorted(SOURCES), default="service")
args = ap.parse_args()
docs_csv, out_name, title = SOURCES[args.source]
cfg = ocr.load_config()
docs = pd.read_csv(paths.outputs_dir() / "ocr" / "ddr_docs.csv")
def load(sha: str, n: int):
return ocr_hub.load_blocks(sha, n) if args.source == "hub" else ocr.load_blocks(sha, n, cfg)
docs = pd.read_csv(paths.outputs_dir() / "ocr" / docs_csv)
complete = docs[docs["ok"] == docs["n_pages"]]
out = paths.outputs_dir() / "ocr_qc"
out = paths.outputs_dir() / out_name
out.mkdir(parents=True, exist_ok=True)
rows, metrics = [], []
for d in complete.to_dict("records"):
html = (paths.ddr_html_dir() / f"{d['report_id']}.html").read_text(encoding="utf-8")
blocks, _ = ocr.load_blocks(d["doc_sha256"], int(d["n_pages"]), cfg)
blocks, _ = load(d["doc_sha256"], int(d["n_pages"]))
hyp = parse_ocr(blocks)
its = [{"doc": d["report_id"], **it} for it in qc.compare(parse_html(html), hyp)]
rows += its
@@ -104,7 +118,8 @@ def main() -> int:
by_table = table((("cell", t, ""), g) for t, g in df[df["part"] == "cell"].groupby("table"))
notes = collections.Counter(n.split(":")[0] for s in dm["notes"] for n in s.split(" | ") if n)
summary = {
"docs": len(dm), "docs_partly_read": int(((docs["ok"] > 0) & (docs["ok"] < docs["n_pages"])).sum()),
"source": args.source, "docs": len(dm), "docs_not_complete": int((docs["ok"] < docs["n_pages"]).sum()),
"docs_partly_read": int(((docs["ok"] > 0) & (docs["ok"] < docs["n_pages"])).sum()),
"pages": int(dm["pages"].sum()),
"content": rates(content),
"by_part": {p: rates(g) for p, g in df.groupby("part")},
@@ -118,7 +133,7 @@ def main() -> int:
(out / "summary.json").write_text(json.dumps(summary, indent=1, ensure_ascii=False) + "\n", encoding="utf-8")
c = summary["content"]
lines = ["# OCR fidelity: publisher HTML vs chandra OCR of the PDF", "",
lines = [f"# OCR fidelity: publisher HTML vs {title}", "",
f"{summary['docs']} reports, {summary['pages']} pages. Content items (header, fields, texts, table "
f"cells and column heads): {c['n']:,}, exact {c['exact_rate']:.4f}, CER {pct(c['cer'])}, "
f"WER {pct(c['wer'])}.", "", "| part | items | exact rate | CER | WER |", "|---|---:|---:|---:|---:|"]