guiwf commited on
Commit
31188dc
·
verified ·
1 Parent(s): 576bca4

Re-export: bake softmax/sigmoid into the graph (4 named probability outputs); external-data weights + export manifest

Browse files
.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
- This is a faithful ONNX export of the encoder + pooler + the two heads used for
38
- alignment scoring:
 
39
 
40
  - a RoBERTa-large encoder with pooling layer (`pooler_output = tanh(dense(h[:,0]))`)
41
- - `tri_layer`: `Linear(hidden, 3)` -> raw 3-way logits
42
- - `reg_layer`: `Linear(hidden, 1)` -> raw regression logit
43
 
44
- Activations are **not** baked into the graph: it emits raw logits, and the
45
- caller applies `softmax` to the 3-way head and `sigmoid` to the regression head.
 
 
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
- | `tri_logits` | output | float32 | `[batch, 3]` -> softmax -> `[p_aligned, p_neutral, p_contradict]` |
54
- | `reg_logit` | output | float32 | `[batch, 1]` -> sigmoid -> `p_aligned_reg` |
 
 
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. Exported with PyTorch (TorchScript exporter).
 
 
 
62
 
63
  ## Files
64
 
65
- - `alignscore-large.onnx` - the model (~1.36 GB)
 
 
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 1.18e-07** across both directions and all four
72
- probabilities. The source checkpoint SHA-256 is asserted equal to the reference
73
- before export, so these are provably the same weights. A high-confidence
74
- contradiction pair scores `p_contradict_3way` 0.982 / 0.977 (forward / reverse).
 
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
- tri, reg = sess.run(["tri_logits", "reg_logit"],
90
- {"input_ids": ids, "attention_mask": mask})
91
- e = np.exp(tri[0] - tri[0].max()); tri_p = e / e.sum()
 
92
  return {
93
- "p_aligned_3way": float(tri_p[0]),
94
- "p_neutral_3way": float(tri_p[1]),
95
- "p_contradict_3way": float(tri_p[2]),
96
- "p_aligned_reg": float(1 / (1 + np.exp(-reg[0][0]))),
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:350be954d95762c12157682aae77cd84699e189f6752d0caf8d38298b2ef2f90
3
- size 1421893132
 
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": true,
54
  "special": true
55
  }
56
  ],
 
50
  "single_word": false,
51
  "lstrip": true,
52
  "rstrip": false,
53
+ "normalized": false,
54
  "special": true
55
  }
56
  ],