File size: 1,706 Bytes
4437ddb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Score context-switch diagnostics with templates held outside training."""
import csv

from build_data import ROOT, digest, json_file
from evidence_model import PortableModel, evaluate


def run():
    rows=[]
    with (ROOT/"corpus"/"context_challenge.tsv").open() as file:
        for record in csv.DictReader(file,delimiter="\t"):
            for label in ("asserted","attributed"):
                context=record[f"{label}_context"]
                cue=record[f"{label}_evidence"]
                offset=context.index(cue)
                rows.append({"unit_id":digest(record["event_id"]+"|"+label)[:18],
                             "event_id":record["event_id"],"family":"context_flip",
                             "text":record["passage"],"context":context,"label":label,
                             "origin":"fictional","annotation_status":"ai_provisional",
                             "reference_span":{"segment":"context","start":offset,"end":offset+len(cue),"quote":cue}})
    work=ROOT/"work"
    import pyarrow as pa
    import pyarrow.parquet as pq
    pq.write_table(pa.Table.from_pylist(rows),work/"context_challenge.parquet")
    model=PortableModel(work/"model.json")
    report={mode:evaluate(model,rows,mode) for mode in ("passage_only","with_context")}
    report["status"]="Fictional manual diagnostics added after model design. No tuning on them."
    json_file(work/"challenge_results.json",report)
    for mode in ("passage_only","with_context"):
        stats=report[mode]
        print(mode,stats["paired_both_correct"],"/",stats["paired_context_switches"],
              "both decisions correct", round(stats["coverage"],3),"coverage")


if __name__=="__main__":
    run()