Views
No views yet
[N1], [/N1], [N2], [/N2]). Given a journal entry and two candidate nodes, predicts whether they are connected.relation_map.json), not from this model.<s> {entry text} </s></s>
[N1] {label} ({type}, {polarity}, {time}) [/N1] </s>
[N2] {label} ({type}, {polarity}, {time}) [/N2] </s>{time} is the node's time anchor (e.g. "today", "yesterday", "this morning"). The suffix is never truncated; the entry text is right-truncated if the total exceeds 256 tokens.1import json, torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4tok = AutoTokenizer.from_pretrained("Niklas1102/mentalkg-xlmr-edge")
5model = AutoModelForSequenceClassification.from_pretrained("Niklas1102/mentalkg-xlmr-edge").eval()
6meta = json.loads(open(tok.name_or_path + "/meta.json").read())
7
8def suffix(marker, node):
9 ta = node["time_anchor"]["text"]
10 return f"[{marker}] {node['label']} ({node['type']}, {node['polarity']}, {ta}) [/{marker}]"
11
12text = "..."
13a, b = {...}, {...} # two candidate nodes
14bos, sep = tok.bos_token_id, tok.sep_token_id
15body = tok(text, add_special_tokens=False)["input_ids"]
16suf = (tok(suffix("N1", a), add_special_tokens=False)["input_ids"]
17 + [sep]
18 + tok(suffix("N2", b), add_special_tokens=False)["input_ids"])
19ids = [bos] + body[: 256 - len(suf) - 4] + [sep, sep] + suf + [sep]
20with torch.no_grad():
21 p = torch.sigmoid(model(input_ids=torch.tensor([ids])).logits[0, 0])
22connected = float(p) >= meta["threshold"]meta["threshold"] (0.39).| arm | F1 (mean ± range) | ROC-AUC (mean ± range) | Accuracy |
|---|---|---|---|
| with entry text | 0.7488 [0.7483, 0.7492] | 0.8124 [0.8108, 0.8142] | 0.7646 |
no-text ablation (entry_text = "entry") | 0.7408 [0.7407, 0.7410] | 0.8038 [0.8038, 0.8039] | 0.7448 |
relation_map.json in this repo maps each ordered type-pair (e.g. stressor|emotion) to the majority relation observed in the 47,714 source graphs. 35 ordered type pairs. Unknown pairs default to linked_to.mentalkg-xlmr-node: 41,315 accepted samples, hard-negative edge sampling (within-graph negatives matched by type-pair distribution to positives, TV distance ~0.26). See mentalkg. Full training protocol in the code repo.