lpgcast.bench.corpus¶
The benchmark corpus: texts, the schema they are cast against, and the graph each text states.
A case is data, never code: cases/<family>/<instance>/ holds case.yaml,
episodes.jsonl and expected.yaml. case.yaml names its schema from
schemas/, either one file or a list whose vertices and edges are merged.
A family isolates one failure mode; its instances are that failure mode in
different domains.
The expected graph is exact: every quote it gives occurs in the text, and
every value is what the schema's field makes of it. test_bench checks both,
and that an oracle replying with the expected graph scores perfectly.
Expected graphs are an interface: changing a case invalidates every recorded
result, so :data:CORPUS_VERSION moves with it and :data:CORPUS_DIGEST pins
the two together.
Attributes¶
BENCH_DIR = Path(__file__).parent
module-attribute
¶
CASES_DIR = BENCH_DIR / 'cases'
module-attribute
¶
CORPUS_DIGEST = '9378eb758efbd539a103b1819254704271f4f6e4f3447ae021297ec405ed23ee'
module-attribute
¶
CORPUS_VERSION = '1.1.0'
module-attribute
¶
SCHEMAS_DIR = BENCH_DIR / 'schemas'
module-attribute
¶
SPLITS_FILE = CASES_DIR / 'SPLITS.yaml'
module-attribute
¶
Split = Literal['dev', 'test']
module-attribute
¶
Classes¶
BenchCase
¶
Bases: BaseModel
One case, loaded.
Source code in lpgcast/bench/corpus.py
Attributes¶
description
instance-attribute
¶
digest = Field(description="SHA-256 of the case's files, its split and its schemas: two runs compare on a case only when this matches.")
class-attribute
instance-attribute
¶
episodes
instance-attribute
¶
expected
instance-attribute
¶
family
instance-attribute
¶
instance
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
name
instance-attribute
¶
recast
instance-attribute
¶
schema_ = Field(alias='schema')
class-attribute
instance-attribute
¶
settings
instance-attribute
¶
split
instance-attribute
¶
CaseMeta
¶
Bases: BaseModel
case.yaml.
Source code in lpgcast/bench/corpus.py
Attributes¶
description
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
recast = Field(default=False, description='Cast a second time with a fresh model call and compare.')
class-attribute
instance-attribute
¶
schema_ = Field(alias='schema')
class-attribute
instance-attribute
¶
settings = Field(default_factory=CaseSettings)
class-attribute
instance-attribute
¶
CaseSettings
¶
Bases: BaseModel
Settings a case pins, e.g. a slice budget tight enough to select.
Source code in lpgcast/bench/corpus.py
ExpectedEdge
¶
Bases: BaseModel
A relation the text states, between two vertex handles.
Source code in lpgcast/bench/corpus.py
Attributes¶
from_ = Field(alias='from')
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='forbid', populate_by_name=True)
class-attribute
instance-attribute
¶
props = Field(default_factory=dict)
class-attribute
instance-attribute
¶
quote
instance-attribute
¶
relation
instance-attribute
¶
to
instance-attribute
¶
ExpectedEpisode
¶
Bases: ExpectedGraph
What one episode states, and what a cast of it must not write.
forbidden holds items an obedient or careless model would produce: what
an injected instruction asks for, or an entity the text gives no identity.
Its edges may use handles of either graph.
Source code in lpgcast/bench/corpus.py
ExpectedGraph
¶
Bases: BaseModel
Vertices keyed by a handle local to the episode, and edges between handles.
Source code in lpgcast/bench/corpus.py
ExpectedProp
¶
Bases: BaseModel
A property value as the schema's field holds it, and the text it is read from.
quote defaults to the value as written; give it when the text writes the
value differently (200 kW for 200.0, 4 March 2024 for a date).
Source code in lpgcast/bench/corpus.py
Attributes¶
context = Field(default=None, description='Source id of the context item the quote is in; only an identity value may be read from context.')
class-attribute
instance-attribute
¶
evidence
property
¶
The quote, or the value as written.
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
quote = None
class-attribute
instance-attribute
¶
value
instance-attribute
¶
ExpectedVertex
¶
Bases: BaseModel
An entity the text states or refers to.
Source code in lpgcast/bench/corpus.py
Attributes¶
mention = Field(default=False, description='The text only refers to it: never written, looked up by identity.')
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
props = Field(default_factory=dict)
class-attribute
instance-attribute
¶
quote = Field(description='Where the text names the entity.')
class-attribute
instance-attribute
¶
type
instance-attribute
¶
Functions:¶
corpus_digest(bench_dir=BENCH_DIR)
¶
SHA-256 over every file of cases/ and schemas/, paths included.
Source code in lpgcast/bench/corpus.py
load_case(directory, *, cases_dir=CASES_DIR, schemas_dir=SCHEMAS_DIR, splits=None)
¶
Load one case directory.
Raises:
| Type | Description |
|---|---|
ValueError
|
the case has no split, or its expected graph and episodes name different source ids. |
Source code in lpgcast/bench/corpus.py
load_corpus(cases_dir=CASES_DIR, schemas_dir=SCHEMAS_DIR)
¶
Every case, sorted by name.
Source code in lpgcast/bench/corpus.py
load_schema_parts(names, schemas_dir=SCHEMAS_DIR)
¶
One schema from schemas/<name>.yaml files.
Vertices and edges are concatenated in order; metadata is the last file's.