Views
No views yet
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.1import numpy as np, onnxruntime as ort
2from tokenizers import Tokenizer
3
4tok = Tokenizer.from_file("tokenizer.json"); tok.enable_truncation(max_length=512); tok.enable_padding()
5sess = ort.InferenceSession("model.onnx", providers=["CPUExecutionProvider"])
6enc = tok.encode_batch(["Attention Is All You Need"])
7ids, mask, types = (np.array([e.ids for e in enc], np.int64),
8 np.array([e.attention_mask for e in enc], np.int64),
9 np.array([e.type_ids for e in enc], np.int64))
10h = sess.run(["last_hidden_state"], {"input_ids": ids, "attention_mask": mask, "token_type_ids": types})[0]
11m = mask[..., None].astype(np.float32)
12v = (h * m).sum(1) / m.sum(1); v /= np.linalg.norm(v, axis=1, keepdims=True)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.