File size: 1,359 Bytes
24918f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Training rows: `lycaon-debug decide export` output, pw-decide-row/1.
row.schema.json beside this file describes the shape. A row is one turn
decision: the state the engine read, the candidates the turn offered, what
the engine answered, and what the session then did. Every consumer reads
option sets from the row's `offered` candidates and option texts from the
corpus, so a label is always read against the options the host had.
"""
import json
SCHEMA = "pw-decide-row/1"
def load(path):
"""Every row of a JSON-lines file, refusing any row of another shape."""
rows = []
with open(path, encoding="utf-8") as fh:
for n, line in enumerate(fh, 1):
if not line.strip():
continue
row = json.loads(line)
if row.get("schema") != SCHEMA:
raise ValueError("%s:%d: schema %r, want %r" % (path, n, row.get("schema"), SCHEMA))
rows.append(row)
return rows
def engine_answered(row):
"""The engine chose what this turn carried, so a tool it preloaded and the session
then called is not an independent label."""
return row["engine"]["state"] == "answered"
def truth_tools(row):
"""The loadable tools the turn needed: the ones it called or asked for by name."""
return set(row["labels"]["tools"]) | set(row["labels"]["requested_names"])
|