common¶
knowledge_graph.common
JSON and JSONL I/O, precision/recall/F1, early stopping, and text normalization helpers.
load_json(path)
¶
Source code in src/knowledge_graph/common.py
7 8 | |
write_json(path, obj, *, indent=1)
¶
Source code in src/knowledge_graph/common.py
11 12 13 14 | |
read_jsonl(path)
¶
Source code in src/knowledge_graph/common.py
17 18 19 | |
write_jsonl(path, rows)
¶
Source code in src/knowledge_graph/common.py
22 23 24 25 | |
count_metrics(tp, gold, predicted)
¶
Counts, tp/fp/fn, and precision/recall/f1 from the true-positive, gold, and predicted counts.
Source code in src/knowledge_graph/common.py
28 29 30 31 32 33 34 | |
precision_recall_f1(gold, predicted)
¶
Set sizes, tp/fp/fn counts, and precision/recall/f1 of two sets.
Source code in src/knowledge_graph/common.py
37 38 39 | |
normalize_space(text)
¶
Source code in src/knowledge_graph/common.py
42 43 | |
normalize_label(text)
¶
Source code in src/knowledge_graph/common.py
46 47 | |
EarlyStopping
¶
Keep the checkpoint with the best validation score; stop after patience epochs without improvement
(never when patience is None).
Source code in src/knowledge_graph/common.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
update(score, save)
¶
Call save() when the score improves; return True once patience is exhausted.
Source code in src/knowledge_graph/common.py
57 58 59 60 61 62 63 64 | |