Download htr/data/schema.py from spboucher04/htr-tiny: direct link, hf CLI and curl.
- Browser
- Download file 5.23 kB
-
https://huggingface.co/spboucher04/htr-tiny/resolve/main/htr/data/schema.py
- Command line
-
hf download hf://spboucher04/htr-tiny/htr/data/schema.py
-
curl -L -o schema.py https://huggingface.co/spboucher04/htr-tiny/resolve/main/htr/data/schema.py
5.23 kB
| """Versioned data schema (pydantic v2) for documents, passages, rewrites, pairs and splits. | |
| All identifiers are deterministic and immutable (see ``htr.utils.hashing.short_id``). Offsets refer to the | |
| normalised document text stored next to the parsed record so that every passage is traceable to its | |
| source bytes. | |
| """ | |
| from __future__ import annotations | |
| from typing import Literal, Optional | |
| from pydantic import BaseModel, Field | |
| SCHEMA_VERSION = "htr-data-1.0" | |
| SourceName = Literal["pmc", "arxiv", "crossref", "bookshelf", "openstax", "gutenberg", "local", "mock"] | |
| SectionRole = Literal["abstract", "introduction", "background", "methods", "results", "discussion", "conclusion", "related_work", "theory", "data", "limitations", "other", "caption", "chapter", "preface"] | |
| DocType = Literal["article", "review", "book_chapter", "book", "preprint", "lecture_notes", "other"] | |
| class LicenseInfo(BaseModel): | |
| code: str | |
| uri: Optional[str] = None | |
| evidence: Optional[str] = None | |
| raw: Optional[str] = None | |
| tier: str | |
| permitted: list[str] | |
| class Document(BaseModel): | |
| schema_version: str = SCHEMA_VERSION | |
| doc_id: str | |
| source: SourceName | |
| source_ids: dict[str, str] = Field(default_factory=dict) # pmcid, pmid, doi, arxiv_id, isbn, gutenberg_id... | |
| title: Optional[str] = None | |
| authors: list[str] = Field(default_factory=list) | |
| author_group: Optional[str] = None # normalised first-author surname + initial, used for author-safe splits | |
| venue: Optional[str] = None | |
| publisher: Optional[str] = None | |
| doc_type: DocType = "article" | |
| pub_date: Optional[str] = None # ISO date (YYYY, YYYY-MM or YYYY-MM-DD) | |
| pub_year: Optional[int] = None | |
| pub_date_evidence: Optional[str] = None # e.g. "jats pub-date[pub-type=ppub]", "arxiv v1 submitted" | |
| pre2018_verified: bool = False | |
| subject_area: Optional[str] = None # coarse discipline label (see htr.data.taxonomy) | |
| subject_raw: list[str] = Field(default_factory=list) | |
| language: Optional[str] = None | |
| source_url: str | |
| license: LicenseInfo | |
| acquired_at: str | |
| raw_path: Optional[str] = None | |
| raw_sha256: Optional[str] = None | |
| raw_bytes: Optional[int] = None | |
| raw_format: Literal["jats", "bits", "latex", "pdf", "txt", "html", "epub", "json"] = "jats" | |
| provider_md5: Optional[str] = None | |
| provider_md5_ok: Optional[bool] = None | |
| retracted: Optional[bool] = None | |
| notes: list[str] = Field(default_factory=list) | |
| class Passage(BaseModel): | |
| schema_version: str = SCHEMA_VERSION | |
| passage_id: str | |
| doc_id: str | |
| section_id: str | |
| section_title: Optional[str] = None | |
| section_role: SectionRole = "other" | |
| section_depth: int = 1 | |
| para_index: int # index of the paragraph within the document body | |
| text: str # normalised paragraph text with protected spans kept verbatim | |
| char_start: int # offsets into the parsed document text file | |
| char_end: int | |
| n_words: int | |
| n_sentences: int | |
| language: Optional[str] = None | |
| quality: float = 0.0 | |
| flags: list[str] = Field(default_factory=list) | |
| protected: dict[str, list[str]] = Field(default_factory=dict) # citations / math / numbers / urls found | |
| text_sha256: str | |
| eligible: bool = False | |
| class RewriteRequest(BaseModel): | |
| request_id: str | |
| passage_id: str | |
| variant: str # A..E | |
| sample_index: int = 0 | |
| provider: str | |
| model: str | |
| prompt_version: str | |
| params: dict = Field(default_factory=dict) | |
| class Rewrite(BaseModel): | |
| schema_version: str = SCHEMA_VERSION | |
| rewrite_id: str | |
| request_id: str | |
| passage_id: str | |
| doc_id: str | |
| variant: str | |
| sample_index: int = 0 | |
| provider: str | |
| model: str | |
| prompt_version: str | |
| text: Optional[str] = None | |
| status: Literal["ok", "refused", "error", "empty", "truncated"] = "ok" | |
| error: Optional[str] = None | |
| provider_request_id: Optional[str] = None | |
| usage: dict = Field(default_factory=dict) | |
| cost_usd: Optional[float] = None | |
| stop_reason: Optional[str] = None | |
| created_at: str | |
| latency_s: Optional[float] = None | |
| cached: bool = False | |
| batch_id: Optional[str] = None | |
| protect_version: str = "1.0" # version of the placeholder protocol applied to the passage sent to the LLM | |
| prompt_input_sha256: Optional[str] = None # hash of the exact (protected) passage text sent | |
| class PairValidation(BaseModel): | |
| passed: bool | |
| checks: dict[str, bool] | |
| scores: dict[str, float] | |
| reasons: list[str] = Field(default_factory=list) | |
| validator_version: str | |
| class Pair(BaseModel): | |
| schema_version: str = SCHEMA_VERSION | |
| pair_id: str | |
| passage_id: str | |
| doc_id: str | |
| rewrite_id: str | |
| variant: str | |
| sample_index: int | |
| source_text: str # the LLM rewrite (model INPUT) | |
| target_text: str # the original human passage (model TARGET) | |
| metadata: dict = Field(default_factory=dict) # discipline, pub_year, era, section_role, source, license | |
| validation: Optional[PairValidation] = None | |
| quarantined: bool = False | |
| class SplitAssignment(BaseModel): | |
| doc_id: str | |
| split: Literal["train", "val", "test", "heldout_domain", "heldout_period", "heldout_author", "quarantine"] | |
| group_keys: dict[str, str] = Field(default_factory=dict) | |