SPECTER2 base β€” fp32 ONNX export

An ONNX (fp32, opset 17) export of allenai/specter2_base, the SPECTER2 scientific-document embedding model, for torch-free inference via ONNX Runtime. Published because no official ONNX export of the base model exists; produced for (and consumed by) Academic Noosphere, a Mac-local literature-gap mapping app.

Usage recipe

Tokenize with tokenizer.json (truncation at 512 tokens), run model.onnx (input_ids, attention_mask, token_type_ids β†’ last_hidden_state), then mean-pool over the attention mask and L2-normalize. recipe.json records this contract plus the model file's sha256.

import numpy as np, onnxruntime as ort
from tokenizers import Tokenizer

tok = Tokenizer.from_file("tokenizer.json"); tok.enable_truncation(max_length=512); tok.enable_padding()
sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
enc = tok.encode_batch(["Attention Is All You Need"])
ids, mask, types = (np.array([e.ids for e in enc], np.int64),
                    np.array([e.attention_mask for e in enc], np.int64),
                    np.array([e.type_ids for e in enc], np.int64))
h = sess.run(["last_hidden_state"], {"input_ids": ids, "attention_mask": mask, "token_type_ids": types})[0]
m = mask[..., None].astype(np.float32)
v = (h * m).sum(1) / m.sum(1); v /= np.linalg.norm(v, axis=1, keepdims=True)

Provenance & parity

Exported by scripts/export_specter2_onnx.py (torch legacy exporter, CPU trace of the unmodified weights). Verified against SentenceTransformer("allenai/specter2_base") over 110 texts (short/long/unicode plus 100 real OpenAlex abstracts): minimum cosine similarity 0.99999982, max per-component deviation 3.0e-7 (parity-report.json). No quantization, no adapters, no fine-tuning β€” the weights are byte-faithful to the source model, which is Apache-2.0 licensed by the Allen Institute for AI.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for jacksodj/specter2-base-onnx

Quantized
(2)
this model