80 header = json.loads(f.readline())
81 tensor_specs = [TensorSpec.from_dict(ts)
for ts
in header[
"features"]]
82 score_spec = TensorSpec.from_dict(header[
"score"])
if "score" in header
else None
83 advice_spec = TensorSpec.from_dict(header[
"advice"])
if "advice" in header
else None
84 return tensor_specs, score_spec, advice_spec
88 context: Optional[str],
91 tensor_specs: List[TensorSpec],
92 score_spec: Optional[TensorSpec],
94 event = json.loads(event_str)
95 if "context" in event:
96 context = event[
"context"]
97 event = json.loads(f.readline())
98 observation_id = int(event[
"observation"])
100 for ts
in tensor_specs:
104 if score_spec
is not None:
105 score_header = json.loads(f.readline())
106 assert int(score_header[
"outcome"]) == observation_id
109 return context, observation_id, features, score
113 with io.BufferedReader(io.FileIO(fname,
"rb"))
as f:
117 event_str = f.readline()
121 context, event_str, f, tensor_specs, score_spec
123 yield context, observation_id, features, score