Re-export: bake softmax/sigmoid into the graph (4 named probability outputs); external-data weights + export manifest
Browse files- .gitattributes +1 -0
- README.md +34 -22
- alignscore-export-manifest.json +18 -0
- alignscore-large.onnx +2 -2
- alignscore-large.onnx.data +3 -0
- tokenizer.json +1 -1
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
alignscore-large.onnx.data filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -34,15 +34,18 @@ general-purpose defaults.
|
|
| 34 |
|
| 35 |
## What this is
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
- a RoBERTa-large encoder with pooling layer (`pooler_output = tanh(dense(h[:,0]))`)
|
| 41 |
-
- `tri_layer`: `Linear(hidden, 3)` ->
|
| 42 |
-
- `reg_layer`: `Linear(hidden, 1)` ->
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
### Graph I/O
|
| 48 |
|
|
@@ -50,28 +53,36 @@ caller applies `softmax` to the 3-way head and `sigmoid` to the regression head.
|
|
| 50 |
|--------|-----------|------|-------|
|
| 51 |
| `input_ids` | input | int64 | `[batch, seq]` (dynamic) |
|
| 52 |
| `attention_mask` | input | int64 | `[batch, seq]` (dynamic) |
|
| 53 |
-
| `
|
| 54 |
-
| `
|
|
|
|
|
|
|
| 55 |
|
| 56 |
There is no `token_type_ids` input: a sentence pair is encoded into a single
|
| 57 |
`input_ids` sequence with `</s></s>` separators, exactly as
|
| 58 |
`AutoTokenizer("roberta-large")(context, claim)` produces. The bundled
|
| 59 |
`tokenizer.json` is the matching fast tokenizer. Use `max_length=512`.
|
| 60 |
|
| 61 |
-
Opset 17.
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## Files
|
| 64 |
|
| 65 |
-
- `alignscore-large.onnx` - the model (~
|
|
|
|
|
|
|
| 66 |
- `tokenizer.json` - roberta-large fast tokenizer with the pair post-processor
|
| 67 |
|
| 68 |
## Parity
|
| 69 |
|
| 70 |
Verified against the original PyTorch model's scores on a 136-pair corpus:
|
| 71 |
-
**max absolute difference
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
## Usage (ONNX Runtime, Python)
|
| 77 |
|
|
@@ -80,20 +91,21 @@ import numpy as np, onnxruntime as ort
|
|
| 80 |
from tokenizers import Tokenizer
|
| 81 |
|
| 82 |
tok = Tokenizer.from_file("tokenizer.json")
|
| 83 |
-
sess = ort.InferenceSession("alignscore-large.onnx")
|
| 84 |
|
| 85 |
def score(context, claim):
|
| 86 |
enc = tok.encode(context, claim)
|
| 87 |
ids = np.array([enc.ids], dtype=np.int64)
|
| 88 |
mask = np.array([enc.attention_mask], dtype=np.int64)
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
return {
|
| 93 |
-
"p_aligned_3way": float(
|
| 94 |
-
"p_neutral_3way": float(
|
| 95 |
-
"p_contradict_3way": float(
|
| 96 |
-
"p_aligned_reg": float(
|
| 97 |
}
|
| 98 |
```
|
| 99 |
|
|
|
|
| 34 |
|
| 35 |
## What this is
|
| 36 |
|
| 37 |
+
A faithful ONNX export of the encoder + pooler + the two alignment-scoring heads,
|
| 38 |
+
with the output activations **baked into the graph** so the model emits the four
|
| 39 |
+
probabilities directly:
|
| 40 |
|
| 41 |
- a RoBERTa-large encoder with pooling layer (`pooler_output = tanh(dense(h[:,0]))`)
|
| 42 |
+
- `tri_layer`: `Linear(hidden, 3)` -> `softmax` -> 3-way probabilities
|
| 43 |
+
- `reg_layer`: `Linear(hidden, 1)` -> `sigmoid` -> alignment probability
|
| 44 |
|
| 45 |
+
This is the key difference from the earlier revision of this repo, which emitted
|
| 46 |
+
raw `tri_logits` / `reg_logit` and left `softmax`/`sigmoid` to the caller. Baking
|
| 47 |
+
the activations in makes the graph self-contained: a single direction scores a
|
| 48 |
+
`(context, claim)` pair straight to probabilities, no post-processing.
|
| 49 |
|
| 50 |
### Graph I/O
|
| 51 |
|
|
|
|
| 53 |
|--------|-----------|------|-------|
|
| 54 |
| `input_ids` | input | int64 | `[batch, seq]` (dynamic) |
|
| 55 |
| `attention_mask` | input | int64 | `[batch, seq]` (dynamic) |
|
| 56 |
+
| `p_aligned_3way` | output | float32 | `[batch]` (softmax over tri head, aligned) |
|
| 57 |
+
| `p_neutral_3way` | output | float32 | `[batch]` (softmax over tri head, neutral) |
|
| 58 |
+
| `p_contradict_3way` | output | float32 | `[batch]` (softmax over tri head, contradict) |
|
| 59 |
+
| `p_aligned_reg` | output | float32 | `[batch]` (sigmoid over reg head) |
|
| 60 |
|
| 61 |
There is no `token_type_ids` input: a sentence pair is encoded into a single
|
| 62 |
`input_ids` sequence with `</s></s>` separators, exactly as
|
| 63 |
`AutoTokenizer("roberta-large")(context, claim)` produces. The bundled
|
| 64 |
`tokenizer.json` is the matching fast tokenizer. Use `max_length=512`.
|
| 65 |
|
| 66 |
+
Opset 17. Weights are stored as ONNX external data in `alignscore-large.onnx.data`
|
| 67 |
+
(the `.onnx` is the graph; keep the two files side by side). The
|
| 68 |
+
`alignscore-export-manifest.json` records the source checkpoint SHA-256, the
|
| 69 |
+
upstream HF revision, the opset, and the exact input/output tensor names.
|
| 70 |
|
| 71 |
## Files
|
| 72 |
|
| 73 |
+
- `alignscore-large.onnx` - the model graph (~0.2 MB)
|
| 74 |
+
- `alignscore-large.onnx.data` - external weights (~1.4 GB); must sit next to the `.onnx`
|
| 75 |
+
- `alignscore-export-manifest.json` - checkpoint SHA-256, HF revision, opset, I/O names
|
| 76 |
- `tokenizer.json` - roberta-large fast tokenizer with the pair post-processor
|
| 77 |
|
| 78 |
## Parity
|
| 79 |
|
| 80 |
Verified against the original PyTorch model's scores on a 136-pair corpus:
|
| 81 |
+
**max absolute difference 5e-06** on `p_contradict_3way` and **0** on
|
| 82 |
+
`p_aligned_reg`, across both directions, with **zero** verdict flips through a
|
| 83 |
+
downstream 0.75 bidirectional contradiction gate. The source checkpoint SHA-256
|
| 84 |
+
is asserted equal to the reference before export, so these are provably the same
|
| 85 |
+
weights.
|
| 86 |
|
| 87 |
## Usage (ONNX Runtime, Python)
|
| 88 |
|
|
|
|
| 91 |
from tokenizers import Tokenizer
|
| 92 |
|
| 93 |
tok = Tokenizer.from_file("tokenizer.json")
|
| 94 |
+
sess = ort.InferenceSession("alignscore-large.onnx") # loads .onnx.data automatically
|
| 95 |
|
| 96 |
def score(context, claim):
|
| 97 |
enc = tok.encode(context, claim)
|
| 98 |
ids = np.array([enc.ids], dtype=np.int64)
|
| 99 |
mask = np.array([enc.attention_mask], dtype=np.int64)
|
| 100 |
+
pa, pn, pc, pr = sess.run(
|
| 101 |
+
["p_aligned_3way", "p_neutral_3way", "p_contradict_3way", "p_aligned_reg"],
|
| 102 |
+
{"input_ids": ids, "attention_mask": mask},
|
| 103 |
+
)
|
| 104 |
return {
|
| 105 |
+
"p_aligned_3way": float(pa[0]),
|
| 106 |
+
"p_neutral_3way": float(pn[0]),
|
| 107 |
+
"p_contradict_3way": float(pc[0]),
|
| 108 |
+
"p_aligned_reg": float(pr[0]),
|
| 109 |
}
|
| 110 |
```
|
| 111 |
|
alignscore-export-manifest.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"schema_version": 1,
|
| 3 |
+
"checkpoint_sha256": "ff4336312b377edcbcdad5694a2d09d73dc4225422c0422d810aa7e78485e32d",
|
| 4 |
+
"hf_revision": "8509e78d25bb914939fc585c626500c9b2944249",
|
| 5 |
+
"opset": 17,
|
| 6 |
+
"encoder_name": "roberta-large",
|
| 7 |
+
"input_names": [
|
| 8 |
+
"input_ids",
|
| 9 |
+
"attention_mask"
|
| 10 |
+
],
|
| 11 |
+
"output_names": [
|
| 12 |
+
"p_aligned_3way",
|
| 13 |
+
"p_neutral_3way",
|
| 14 |
+
"p_contradict_3way",
|
| 15 |
+
"p_aligned_reg"
|
| 16 |
+
],
|
| 17 |
+
"generated_at": "2026-07-05T03:01:18Z"
|
| 18 |
+
}
|
alignscore-large.onnx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c4a95d87043d6a543d5089d3363ac0c3168bbfee93be06dadb7c36e9d9d3c76
|
| 3 |
+
size 210708
|
alignscore-large.onnx.data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c842f392dae6a5c777bb9792332731a14d53719815afac394f1ea1f0ce29c03
|
| 3 |
+
size 1421578240
|
tokenizer.json
CHANGED
|
@@ -50,7 +50,7 @@
|
|
| 50 |
"single_word": false,
|
| 51 |
"lstrip": true,
|
| 52 |
"rstrip": false,
|
| 53 |
-
"normalized":
|
| 54 |
"special": true
|
| 55 |
}
|
| 56 |
],
|
|
|
|
| 50 |
"single_word": false,
|
| 51 |
"lstrip": true,
|
| 52 |
"rstrip": false,
|
| 53 |
+
"normalized": false,
|
| 54 |
"special": true
|
| 55 |
}
|
| 56 |
],
|