infon/extract.py
with a learned multilingual model.| Head | Classes |
|---|---|
| polarity | affirmed · negated · uncertain |
| tense | past · present · future · conditional |
| conditional | yes · no |
| relation_type | causal · temporal · spatial · attributive · none |
| spatial | containment · proximity · direction · movement · none |
| direction | increase · decrease · stable · target · none |
npm install @cp500/infon-heads onnxruntime-web1import { InfonHeadsModel } from '@cp500/infon-heads';
2
3const model = await InfonHeadsModel.fromHub('cp500/infon-heads', {
4 precision: 'fp16', // 224 MB (default) — vs 448 MB for fp32
5 device: 'auto',
6});
7
8const r = await model.classify(
9 'Toyota did not raise battery output last quarter because demand fell.'
10);
11
12console.log(r.polarity); // 'negated'
13console.log(r.tense); // 'past'
14console.log(r.relationType); // 'causal'
15console.log(r.comparativeDirection); // 'decrease'js/ for
self-contained installs.1import torch
2from transformers import AutoModel, AutoTokenizer
3from infon.heads import InfonHeads
4
5backbone = AutoModel.from_pretrained("./backbone/")
6tokenizer = AutoTokenizer.from_pretrained("./backbone/")
7heads = InfonHeads.load(".") # loads heads.pttext ─▶ tokenize ─▶ heads_backbone.onnx (MiniLM-L12, 117M, 224 MB FP16)
│
▼ cls (B, H=384)
heads_classifiers.onnx (6 tiny MLPs, 144 KB FP16)
│
▼
6 logit tensors → argmax + softmax → labels + confidenceonnx/heads_backbone.onnx — paraphrase-multilingual-MiniLM-L12-v2
with the CLS token surfaced as the only output. One forward per
document.onnx/heads_classifiers.onnx — six small MLPs sharing CLS input.
Each emits its own logit tensor named <head>_logits. The cost of
additional heads is essentially zero, so the bundle stays compact.| Head | Validation acc |
|---|---|
| polarity | 0.947 |
| tense | 0.743 |
| conditional | 0.949 |
| relation_type | 0.477 |
| spatial | 0.912 |
| direction | 0.914 |
| Language | macro | pol | ten | con | rel | spa | dir |
|---|---|---|---|---|---|---|---|
| en | 0.864 | 0.97 | 0.88 | 0.98 | 0.49 | 0.95 | 0.91 |
| ja | 0.805 | 0.92 | 0.74 | 0.92 | 0.45 | 0.88 | 0.90 |
| ko | 0.827 | 0.93 | 0.77 | 0.97 | 0.47 | 0.92 | 0.90 |
| th | 0.817 | 0.96 | 0.67 | 0.94 | 0.53 | 0.88 | 0.92 |
| zh | 0.809 | 0.95 | 0.65 | 0.93 | 0.44 | 0.93 | 0.94 |
relation_type underperforms (~47%). The 5 classes (causal /
temporal / spatial / attributive / none) overlap meaningfully —
many sentences are simultaneously causal AND spatial-movement,
but the synthetic training data forces a single label per
sentence. Treat low-confidence relation_type predictions
(confidence.relationType < 0.5) as unreliable.sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2