DefExtra hydration
Overview
This dataset cannot ship excerpts. We ship markers only. Users supply PDFs and run hydration to reconstruct the definitions and contexts.
See README.md for the high‑level overview and examples.
Requirements
Python 3.10+
A running GROBID server (default:
http://localhost:8070).Example Docker run:
docker run --rm -p 8070:8070 grobid/grobid:0.8.0Python packages used by scripts:
grobid-client-python,lxml,pdfplumber,pdfminer.six,PyPDF2,pyarrow
UV usage
This repo ships a pyproject.toml, so you can run:
uv run python scripts/hydrate_defextra.py ...
Getting PDFs
See docs/get_pdfs.md for sources and a helper script that lists required PDFs.
Quickstart (run GROBID)
- Place your PDFs in
pdfs/. - Hydrate (runs GROBID unless
--skip-grobid):
uv run python scripts/hydrate_defextra.py \
--legal-csv data/defextra_legal.csv \
--pdf-dir pdfs \
--grobid-out grobid_out \
--output-csv defextra_hydrated.csv \
--report defextra_hydrated_report.txt \
--require-complete
Quickstart (skip GROBID, use existing TEI)
If you already have TEI XML files (e.g., produced by your own GROBID run), point
--grobid-out to that TEI folder and add --skip-grobid:
uv run python scripts/hydrate_defextra.py \
--legal-csv data/defextra_legal.csv \
--pdf-dir pdfs \
--grobid-out /path/to/tei_xml_dir \
--output-csv defextra_hydrated.csv \
--report defextra_hydrated_report.txt \
--require-complete \
--skip-grobid
File naming expectations
- Preferred:
<paper_id>.pdf(thepaper_idin the CSV). - DOI/arXiv/PII aliases are supported for common cases.
- Hash IDs are often Semantic Scholar IDs; many PDFs can be downloaded from there.
GROBID configuration
- By default,
scripts/pdf_to_grobid.pygenerates a temporary config that points tohttp://localhost:8070. - Use
--grobid-config config.jsonto override the URL/timeout/batch size.
Hash mismatch behavior
- The legal CSV includes hash markers to verify that the PDF content matches the paper version.
- Default: skip PDFs with hash mismatches and report them.
- Optional:
--allow-pdf-hash-mismatchto continue anyway (use only after manual inspection).
Interpretation of warnings
Error initializing GROBID clientorGROBID server ... does not appear up and running: GROBID is not reachable. Start the server (or Docker) or pass--grobid-configwith the correct URL. If you already have TEI files, rerun with--skip-grobid.Processing failed ... [BAD_INPUT_DATA] ... error code: 139orpdfaltoerrors: GROBID could not parse a PDF (often a damaged or unusual file). Hydration may still succeed via PDF text fallback, but TEI will be missing. Try a different PDF version.Warning: PDF hash markers did not match ... skipping PDF: The PDF content differs from the expected version. Replace the PDF with the correct version or rerun with--allow-pdf-hash-mismatchand manually inspect outputs.Warning: PDF text extraction failed ...: The PDF text fallback failed (pdfplumber/pdfminer/PyPDF2). Hydration then relies on TEI only. Try a different PDF or a different extraction backend.incorrect startxref pointeror similar PDF syntax warnings: The PDF appears malformed. Often recoverable, but if hydration fails, obtain a clean copy.Summary lines:
Missing TEI for N papers: GROBID output missing for those PDFs.Missing definition spans/Missing context spans: nothing matched after TEI + hash + anchor + PDF fallback.Hydrated from PDF fallback: spans were reconstructed from PDF text (not TEI).
Legal CSV schema (marker columns)
definition_char_start,definition_char_end: exact TEI substring span (optional).definition_match:exact/hash/missingindicating how the TEI span was found.definition_hash64,definition_sha256,definition_token_count: full span hash.definition_head_*,definition_mid_*,definition_tail_*: anchor hashes (window size 12).definition_head_alt_*,definition_mid_alt_*,definition_tail_alt_*: anchor hashes (window size 6).- Same fields exist for
context_*. definition_preserve_linebreaks,context_preserve_linebreaks: keep line breaks when present in the manual copy (tables).definition_preserve_hyphenation,context_preserve_hyphenation: preserve line-break hyphenation when present.definition_has_bracket_citation,context_has_bracket_citation: whether the manual copy included[12]‑style citations.definition_has_paren_citation,context_has_paren_citation: whether the manual copy included(Author, 2019)‑style citations.definition_has_letter_digit,context_has_letter_digit: whether the manual copy contained letter‑digit runs likebias4.definition_end_punct,context_end_punct: trailing punctuation marker captured from the manual copy.
Legal CSV columns (full)
| Column | Description |
|---|---|
paper_id |
Paper identifier (often a Semantic Scholar ID, DOI, or arXiv ID). |
paper_title |
Paper title. |
paper_doi |
DOI (if available). |
paper_arxiv |
arXiv ID or URL (if available). |
concept |
Term / concept being defined. |
definition_type |
Definition type (e.g., explicit / implicit). |
source_file |
Source JSON filename used during curation. |
is_out_of_domain |
Boolean flag for out‑of‑domain papers. |
definition_preserve_linebreaks |
Whether line breaks should be preserved in the definition. |
context_preserve_linebreaks |
Whether line breaks should be preserved in the context. |
definition_preserve_hyphenation |
Whether hyphenation should be preserved in the definition. |
context_preserve_hyphenation |
Whether hyphenation should be preserved in the context. |
definition_has_bracket_citation |
Definition contains bracket‑style citations (e.g., [12]). |
definition_has_paren_citation |
Definition contains parenthetical citations (e.g., (Smith, 2020)). |
definition_has_letter_digit |
Definition contains letter–digit patterns (e.g., bias4). |
context_has_bracket_citation |
Context contains bracket‑style citations. |
context_has_paren_citation |
Context contains parenthetical citations. |
context_has_letter_digit |
Context contains letter–digit patterns. |
definition_end_punct |
Expected trailing punctuation for definition. |
context_end_punct |
Expected trailing punctuation for context. |
marker_version |
Marker format version. |
hash_version |
Hashing scheme version. |
definition_char_start |
Character start offset (TEI) for definition (if available). |
definition_char_end |
Character end offset (TEI) for definition (if available). |
definition_match |
Debug marker: reference string used to compute definition hashes. |
definition_hash64 |
64‑bit hash of definition token sequence. |
definition_sha256 |
SHA‑256 hash of definition token sequence. |
definition_token_count |
Token count for definition span. |
definition_head_hash64 |
Head‑anchor 64‑bit hash for definition. |
definition_head_sha256 |
Head‑anchor SHA‑256 hash for definition. |
definition_head_token_count |
Head‑anchor token count for definition. |
definition_mid_hash64 |
Mid‑anchor 64‑bit hash for definition. |
definition_mid_sha256 |
Mid‑anchor SHA‑256 hash for definition. |
definition_mid_token_count |
Mid‑anchor token count for definition. |
definition_tail_hash64 |
Tail‑anchor 64‑bit hash for definition. |
definition_tail_sha256 |
Tail‑anchor SHA‑256 hash for definition. |
definition_tail_token_count |
Tail‑anchor token count for definition. |
definition_head_alt_hash64 |
Alternate head‑anchor 64‑bit hash for definition. |
definition_head_alt_sha256 |
Alternate head‑anchor SHA‑256 hash for definition. |
definition_head_alt_token_count |
Alternate head‑anchor token count for definition. |
definition_mid_alt_hash64 |
Alternate mid‑anchor 64‑bit hash for definition. |
definition_mid_alt_sha256 |
Alternate mid‑anchor SHA‑256 hash for definition. |
definition_mid_alt_token_count |
Alternate mid‑anchor token count for definition. |
definition_tail_alt_hash64 |
Alternate tail‑anchor 64‑bit hash for definition. |
definition_tail_alt_sha256 |
Alternate tail‑anchor SHA‑256 hash for definition. |
definition_tail_alt_token_count |
Alternate tail‑anchor token count for definition. |
context_char_start |
Character start offset (TEI) for context (if available). |
context_char_end |
Character end offset (TEI) for context (if available). |
context_match |
Debug marker: reference string used to compute context hashes. |
context_hash64 |
64‑bit hash of context token sequence. |
context_sha256 |
SHA‑256 hash of context token sequence. |
context_token_count |
Token count for context span. |
context_head_hash64 |
Head‑anchor 64‑bit hash for context. |
context_head_sha256 |
Head‑anchor SHA‑256 hash for context. |
context_head_token_count |
Head‑anchor token count for context. |
context_mid_hash64 |
Mid‑anchor 64‑bit hash for context. |
context_mid_sha256 |
Mid‑anchor SHA‑256 hash for context. |
context_mid_token_count |
Mid‑anchor token count for context. |
context_tail_hash64 |
Tail‑anchor 64‑bit hash for context. |
context_tail_sha256 |
Tail‑anchor SHA‑256 hash for context. |
context_tail_token_count |
Tail‑anchor token count for context. |
context_head_alt_hash64 |
Alternate head‑anchor 64‑bit hash for context. |
context_head_alt_sha256 |
Alternate head‑anchor SHA‑256 hash for context. |
context_head_alt_token_count |
Alternate head‑anchor token count for context. |
context_mid_alt_hash64 |
Alternate mid‑anchor 64‑bit hash for context. |
context_mid_alt_sha256 |
Alternate mid‑anchor SHA‑256 hash for context. |
context_mid_alt_token_count |
Alternate mid‑anchor token count for context. |
context_tail_alt_hash64 |
Alternate tail‑anchor 64‑bit hash for context. |
context_tail_alt_sha256 |
Alternate tail‑anchor SHA‑256 hash for context. |
context_tail_alt_token_count |
Alternate tail‑anchor token count for context. |
Notes
- Small mismatches are expected due to PDF/GROBID text normalization.
- Missing exact TEI spans do not block hydration; hash/anchor markers are used as fallback.
- Exact TEI spans are validated against stored hashes; if they do not match, citation‑stripped hash/anchor matching is used instead.
- See
docs/mismatch_examples.mdfor concrete mismatch types with short excerpts.