Core ML
legal
citation-verification
hallucination-detection
apple-neural-engine
hand-written-weights
File size: 1,480 Bytes
42b4a6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Citation-level labels from LePhantomCite (ai-law-society-lab/Legal_Phantom_Citation).

phantom  = citation tagged non_existent_citation
genuine  = citation with no hallucination tag at all
other    = tagged case_name_mismatch / wrong_pincite / misquote / content_misrepresentation
           (needs a case-law lookup; out of scope for a string-only model, reported separately)
'optional' tags (typos in the source brief) are dropped.
"""
import json, os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from citenet.text import normalize

ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "data")


def load(split):
    rows = [json.loads(l) for l in open(os.path.join(ROOT, split + ".jsonl"))]
    out = []
    for r in rows:
        tags = r.get("list_hallucination_types") or {}
        opt = {k for k, v in (r.get("list_hallucinations") or {}).items() if v == "optional"}
        cites = list(dict.fromkeys(list(r["citations_in_segment"]) + list(tags)))
        seen = set()
        for c in cites:
            key = normalize(c)
            if key in seen or c in opt:
                continue
            seen.add(key)
            ts = tags.get(c, [])
            if "optional" in ts:
                continue
            label = "phantom" if "non_existent_citation" in ts else ("other" if ts else "genuine")
            out.append(dict(cite=c, label=label, types=ts, file=r["filename"]))
    return out