Commit ·
576bca4
0
Parent(s):
Super-squash branch 'main' using huggingface_hub
Browse files- .gitattributes +35 -0
- README.md +114 -0
- alignscore-large.onnx +3 -0
- tokenizer.json +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz 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
|
README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: onnx
|
| 4 |
+
tags:
|
| 5 |
+
- alignscore
|
| 6 |
+
- onnx
|
| 7 |
+
- text-classification
|
| 8 |
+
- natural-language-inference
|
| 9 |
+
- roberta
|
| 10 |
+
base_model: yzha/AlignScore
|
| 11 |
+
pipeline_tag: text-classification
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# AlignScore-large (ONNX)
|
| 15 |
+
|
| 16 |
+
An ONNX export of [**AlignScore-large**](https://huggingface.co/yzha/AlignScore)
|
| 17 |
+
(RoBERTa-large with AlignScore's 3-way and regression heads), for in-process
|
| 18 |
+
inference without a Python/PyTorch runtime.
|
| 19 |
+
|
| 20 |
+
## Why this exists
|
| 21 |
+
|
| 22 |
+
Upstream AlignScore ships only PyTorch Lightning checkpoints built from a custom
|
| 23 |
+
`BERTAlignModel` module - no `config.json`, no `safetensors` - so
|
| 24 |
+
`optimum-cli export onnx` cannot consume it, and no ONNX build existed. This is
|
| 25 |
+
that build, so anyone who wants to experiment with AlignScore-large can, without
|
| 26 |
+
standing up a PyTorch runtime or writing a custom export pathway.
|
| 27 |
+
|
| 28 |
+
It reflects a Familiar Tools belief: a specialized, right-sized model that runs
|
| 29 |
+
efficiently and in-process beats reaching for a large, general, resource-hungry
|
| 30 |
+
one. Exporting a focused model to ONNX is part of that - it makes the model
|
| 31 |
+
cheap to run, easy to embed, and light on dependencies. Custom, deliberately
|
| 32 |
+
engineered solutions tend to be more efficient and more resource-aware than
|
| 33 |
+
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 |
+
|
| 49 |
+
| Tensor | Direction | Type | Shape |
|
| 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 |
+
|
| 78 |
+
```python
|
| 79 |
+
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 |
+
|
| 100 |
+
## License and attribution
|
| 101 |
+
|
| 102 |
+
Released under the **MIT License**, matching upstream.
|
| 103 |
+
|
| 104 |
+
- AlignScore: Zha et al., *AlignScore: Evaluating Factual Consistency with a
|
| 105 |
+
Unified Alignment Function*, ACL 2023
|
| 106 |
+
([arXiv:2305.16739](https://arxiv.org/abs/2305.16739),
|
| 107 |
+
[code](https://github.com/yuh-zha/AlignScore)).
|
| 108 |
+
- Original weights: [`yzha/AlignScore`](https://huggingface.co/yzha/AlignScore)
|
| 109 |
+
(revision `8509e78d25bb914939fc585c626500c9b2944249`).
|
| 110 |
+
- Base encoder: RoBERTa-large (Liu et al., 2019).
|
| 111 |
+
|
| 112 |
+
This repo redistributes a derivative (ONNX export) of the above under the same
|
| 113 |
+
MIT terms. No weights were retrained or modified; only the inference graph was
|
| 114 |
+
re-expressed.
|
alignscore-large.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:350be954d95762c12157682aae77cd84699e189f6752d0caf8d38298b2ef2f90
|
| 3 |
+
size 1421893132
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|