schemacast.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, and optionally pick.yaml: for an
episode's staged mentions, the candidates a resolver would gather, the entities
the record names and the pick a careful reader makes. 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.
Beside the graph a text states, expected.yaml may give forbidden
items a cast must not write and allowed items it may write without being
required to; an outside corpus in the same layout loads with
:func:corpus_dirs.
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 = '6a293a0455ccd4ea0dc59fe0583fe0a53db232a710949f83b48e2dd2fbdd7e97'
module-attribute
¶
CORPUS_VERSION = '1.3.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 schemacast/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
¶
picks = Field(default_factory=dict)
class-attribute
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 schemacast/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 schemacast/bench/corpus.py
ExpectedCandidate
¶
Bases: BaseModel
An entity offered to a pick, as graflo's EntityCandidate holds it.
anchor names an expected vertex handle of the same episode.
Source code in schemacast/bench/corpus.py
Attributes¶
anchor = None
class-attribute
instance-attribute
¶
key
instance-attribute
¶
label = None
class-attribute
instance-attribute
¶
lane = 'metadata'
class-attribute
instance-attribute
¶
matched = None
class-attribute
instance-attribute
¶
model_config = ConfigDict(extra='forbid')
class-attribute
instance-attribute
¶
relation = None
class-attribute
instance-attribute
¶
role = None
class-attribute
instance-attribute
¶
type
instance-attribute
¶
ExpectedEdge
¶
Bases: BaseModel
A relation the text states, between two vertex handles.
Source code in schemacast/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, what a cast of it must not write, and what it may 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.
allowed holds items a cast may produce without being required to: an
entity or relation the text implies but does not state. A produced item
matching one counts neither as right nor as wrong. The edges of either may
use handles of the expected graph; their own handles must differ from its.
Source code in schemacast/bench/corpus.py
ExpectedGraph
¶
Bases: BaseModel
Vertices keyed by a handle local to the episode, and edges between handles.
Source code in schemacast/bench/corpus.py
ExpectedPickMention
¶
Bases: BaseModel
One staged mention's candidates and the right pick (null: none fits).
Source code in schemacast/bench/corpus.py
ExpectedPicks
¶
Bases: BaseModel
pick.yaml for one episode: mentions by expected vertex handle.
Source code in schemacast/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 schemacast/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 schemacast/bench/corpus.py
Attributes¶
mention = Field(default=False, description='The text only refers to it: written by its key, or looked up by a secondary 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 schemacast/bench/corpus.py
corpus_dirs(root)
¶
root/cases and root/schemas: a corpus laid out like the bundled one.
Raises:
| Type | Description |
|---|---|
ValueError
|
root has no |
Source code in schemacast/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 schemacast/bench/corpus.py
load_corpus(cases_dir=CASES_DIR, schemas_dir=SCHEMAS_DIR)
¶
Every case, sorted by name.
Source code in schemacast/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.