AsamAce commited on
Commit
dd4a61e
Β·
verified Β·
1 Parent(s): 6ef3526

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +132 -0
README.md ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pharmaceutical-supply-chain
5
+ - traceability
6
+ - anomaly-detection
7
+ - tabular-classification
8
+ - logistic-regression
9
+ pipeline_tag: tabular-classification
10
+ ---
11
+
12
+ # ZigoTrace Pharma β€” Diversion Anomaly Model
13
+
14
+ A locked, validated logistic model that scores **grey-market diversion** on a
15
+ pharmaceutical serialization graph β€” engine: [zigo-pharma](https://github.com/Davedave001/zigo-pharma).
16
+
17
+ ## Intended use β€” read this first
18
+
19
+ - **Advisory only.** This model outputs a suspicion score that is fused as **one
20
+ reliability-capped evidence source** into a larger Dempster-Shafer authenticity
21
+ confidence, alongside deterministic rule-based gaps. **It never gates a
22
+ dispense/release decision by itself** β€” the deterministic layer (recall, expiry,
23
+ cold-chain, cloned-serial, aggregation, mass-balance) is the authoritative safety
24
+ path, always.
25
+ - **Scope: diversion only.** Trained to catch route/ring diversion β€” units that are
26
+ *individually* unremarkable but statistically anomalous in their custody path or
27
+ their aggregation-case neighbourhood. It is **not** trained to catch expired,
28
+ recalled, or cold-chain-excursion stock; those are deterministic gaps, on purpose
29
+ (rules validate cleanly; this model is the layer for what rules cannot express).
30
+ - **Abstains under uncertainty.** Low model certainty collapses its contribution toward
31
+ "unknown" rather than guessing β€” see `uncertainty` in the output.
32
+ - **Not (yet) validated on real data.** Trained and evaluated on the synthetic dataset
33
+ `zigotrace/pharma-serialized-events`. See Limitations.
34
+
35
+ ## How to use
36
+
37
+ Input is an **already-extracted 8-feature vector** β€” this model does not accept or
38
+ parse a raw event graph. Feature extraction is intentionally single-sourced in the TS
39
+ engine (`packages/intelligence/src/features.ts`) to avoid two implementations of graph
40
+ traversal silently drifting apart; see `docs/huggingface-model-plan.md` Β§0.
41
+
42
+ ```python
43
+ from huggingface_hub import hf_hub_download
44
+ import json, sys
45
+ sys.path.insert(0, ".") # scorer.py ships alongside model.json in this repo
46
+ from scorer import load_model, score_features
47
+
48
+ model = load_model(hf_hub_download("zigotrace/pharma-authenticity-model", "model.json"))
49
+ features = [0.83, 1, 1, 1, 1, 1, 4, 0.0] # route_rarity, num_receives, num_dispenses,
50
+ # distinct_receive_locations, aggregation_consistent,
51
+ # attestation_ok, hop_count, case_dispense_anomaly
52
+ out = score_features(model, features)
53
+ print(out) # AnomalyOutput(score=..., uncertainty=..., explanation="...")
54
+ ```
55
+
56
+ Or via an Inference Endpoint running `handler.py`:
57
+
58
+ ```json
59
+ POST / {"inputs": {"features": [0.83, 1, 1, 1, 1, 1, 4, 0.0]}}
60
+ ```
61
+
62
+ ## Training
63
+
64
+ - **Algorithm:** logistic regression, full-batch gradient descent, fixed
65
+ initialization and iteration count β†’ **deterministic** (same events produce an
66
+ identical artifact β€” required for GxP change control; see
67
+ `packages/intelligence/src/train.ts`).
68
+ - **Labels:** **weak supervision** β€” labeling functions over model-observable signals
69
+ (rare custody route, duplicate dispense, weak attestation, case-sibling funnelling),
70
+ not ground truth. Realistic for a domain where confirmed-counterfeit labels are
71
+ scarce.
72
+ - **Data:** `zigotrace/pharma-serialized-events` (synthetic, seed 7, 420 train / 180
73
+ test rows).
74
+
75
+ ## Evaluation (this artifact, `test.jsonl`, standalone at a raw 0.5 threshold)
76
+
77
+ | Metric | Value |
78
+ |---|---|
79
+ | Diversion detection (route + ring) | 7/7 β€” **100%** |
80
+ | Brier score | **0.021** |
81
+ | False-positive rate (standalone, 0.5 threshold) | 2.3% (4/173) |
82
+
83
+ Reproduce: `python hf/local_dry_run.py` (after `node hf/generate_fixtures.mjs`).
84
+
85
+ > **The false-positive rate above is a property of this model scored in isolation.**
86
+ > In the shipped engine it is capped by a reliability weight inside the
87
+ > Dempster-Shafer fusion and can only ever *add suspicion*, never override a
88
+ > deterministic "authentic" verdict β€” so it does not translate into a real
89
+ > false-quarantine rate. The shipped engine's actual false-quarantine rate (with this
90
+ > model fused in, evaluated by `intel-validate`) is **0%**. See
91
+ > `validation/model-card.md` in the source repo for the fused-system numbers.
92
+
93
+ ## Model internals (inspectable β€” this is why logistic-first)
94
+
95
+ ```
96
+ featureNames: route_rarity, num_receives, num_dispenses, distinct_receive_locations,
97
+ aggregation_consistent, attestation_ok, hop_count, case_dispense_anomaly
98
+ weights: [1.596, 0.026, 0.567, 0.026, 2.117, -0.567, 0.2, 1.095]
99
+ bias: -2.329
100
+ ```
101
+
102
+ Weights act on **standardized** features (`(x - mean) / std`, per-feature `mean`/`std`
103
+ shipped in `model.json`). `case_dispense_anomaly` (the relational feature) and
104
+ `route_rarity` carry meaningful weight, consistent with the model's diversion-specific
105
+ training signal.
106
+
107
+ ## Limitations
108
+
109
+ - Synthetic training/eval data only β€” real-world generalization is unverified pending
110
+ a lighthouse distributor dataset (planned, gated dataset repo).
111
+ - Linear model β€” cannot capture more complex relational patterns (e.g. multi-hop
112
+ laundering rings); a GNN track exists (`ml/` in the source repo) for that, not yet
113
+ outperforming this baseline on available data.
114
+ - `aggregation_consistent`'s weight sign should not be over-interpreted causally β€” it
115
+ has low variance in the synthetic generator (aggregation mismatches are a separate,
116
+ rare injected pattern), so its fitted coefficient is not strongly constrained by this
117
+ dataset.
118
+
119
+ ## Governance
120
+
121
+ - **Change control:** training is deterministic; any retrain is a new artifact with a
122
+ new sha256, which is the locked version id (anchored on Hedera in the deployed
123
+ engine). No silent model updates.
124
+ - **Human authority:** a pharmacist/QP/auditor retains override, with recorded
125
+ provenance, regardless of this model's output.
126
+ - Full GxP validation pack: `validation/` in the
127
+ [source repo](https://github.com/Davedave001/zigo-pharma).
128
+
129
+ ## License
130
+
131
+ MIT (this model + code). The synthetic dataset it's trained on is MIT-licensed
132
+ generated data β€” see the dataset card for details.