Commit ·
576bca4
0
Parent(s):
Super-squash branch 'main' using huggingface_hub
Browse filesFiles changed (4)
- .gitattributesAdded+35
- README.mdAdded+114
- alignscore-large.onnxAdded+3
- tokenizer.jsonAdded
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114---license: mitlibrary_name: onnxtags: - alignscore - onnx - text-classification - natural-language-inference - robertabase_model: yzha/AlignScorepipeline_tag: text-classification---
# AlignScore-large (ONNX)
An ONNX export of [**AlignScore-large**](https://huggingface.co/yzha/AlignScore)(RoBERTa-large with AlignScore's 3-way and regression heads), for in-processinference without a Python/PyTorch runtime.
## Why this exists
Upstream AlignScore ships only PyTorch Lightning checkpoints built from a custom`BERTAlignModel` module - no `config.json`, no `safetensors` - so`optimum-cli export onnx` cannot consume it, and no ONNX build existed. This isthat build, so anyone who wants to experiment with AlignScore-large can, withoutstanding up a PyTorch runtime or writing a custom export pathway.
It reflects a Familiar Tools belief: a specialized, right-sized model that runsefficiently and in-process beats reaching for a large, general, resource-hungryone. Exporting a focused model to ONNX is part of that - it makes the modelcheap to run, easy to embed, and light on dependencies. Custom, deliberatelyengineered solutions tend to be more efficient and more resource-aware thangeneral-purpose defaults.
## What this is
This is a faithful ONNX export of the encoder + pooler + the two heads used foralignment scoring:
- a RoBERTa-large encoder with pooling layer (`pooler_output = tanh(dense(h[:,0]))`)- `tri_layer`: `Linear(hidden, 3)` -> raw 3-way logits- `reg_layer`: `Linear(hidden, 1)` -> raw regression logit
Activations are **not** baked into the graph: it emits raw logits, and thecaller applies `softmax` to the 3-way head and `sigmoid` to the regression head.
### Graph I/O
| Tensor | Direction | Type | Shape ||--------|-----------|------|-------|| `input_ids` | input | int64 | `[batch, seq]` (dynamic) || `attention_mask` | input | int64 | `[batch, seq]` (dynamic) || `tri_logits` | output | float32 | `[batch, 3]` -> softmax -> `[p_aligned, p_neutral, p_contradict]` || `reg_logit` | output | float32 | `[batch, 1]` -> sigmoid -> `p_aligned_reg` |
There is no `token_type_ids` input: a sentence pair is encoded into a single`input_ids` sequence with `</s></s>` separators, exactly as`AutoTokenizer("roberta-large")(context, claim)` produces. The bundled`tokenizer.json` is the matching fast tokenizer. Use `max_length=512`.
Opset 17. Exported with PyTorch (TorchScript exporter).
## Files
- `alignscore-large.onnx` - the model (~1.36 GB)- `tokenizer.json` - roberta-large fast tokenizer with the pair post-processor
## Parity
Verified against the original PyTorch model's scores on a 136-pair corpus:**max absolute difference 1.18e-07** across both directions and all fourprobabilities. The source checkpoint SHA-256 is asserted equal to the referencebefore export, so these are provably the same weights. A high-confidencecontradiction pair scores `p_contradict_3way` 0.982 / 0.977 (forward / reverse).
## Usage (ONNX Runtime, Python)
```pythonimport numpy as np, onnxruntime as ortfrom tokenizers import Tokenizer
tok = Tokenizer.from_file("tokenizer.json")sess = ort.InferenceSession("alignscore-large.onnx")
def score(context, claim): enc = tok.encode(context, claim) ids = np.array([enc.ids], dtype=np.int64) mask = np.array([enc.attention_mask], dtype=np.int64) tri, reg = sess.run(["tri_logits", "reg_logit"], {"input_ids": ids, "attention_mask": mask}) e = np.exp(tri[0] - tri[0].max()); tri_p = e / e.sum() return { "p_aligned_3way": float(tri_p[0]), "p_neutral_3way": float(tri_p[1]), "p_contradict_3way": float(tri_p[2]), "p_aligned_reg": float(1 / (1 + np.exp(-reg[0][0]))), }```
## License and attribution
Released under the **MIT License**, matching upstream.
- AlignScore: Zha et al., *AlignScore: Evaluating Factual Consistency with a Unified Alignment Function*, ACL 2023 ([arXiv:2305.16739](https://arxiv.org/abs/2305.16739), [code](https://github.com/yuh-zha/AlignScore)).- Original weights: [`yzha/AlignScore`](https://huggingface.co/yzha/AlignScore) (revision `8509e78d25bb914939fc585c626500c9b2944249`).- Base encoder: RoBERTa-large (Liu et al., 2019).
This repo redistributes a derivative (ONNX export) of the above under the sameMIT terms. No weights were retrained or modified; only the inference graph wasre-expressed.123version https://git-lfs.github.com/spec/v1oid sha256:350be954d95762c12157682aae77cd84699e189f6752d0caf8d38298b2ef2f90size 1421893132.gitattributesAdded+35
README.mdAdded+114
alignscore-large.onnxAdded+3
tokenizer.jsonAdded