Downloads · 30 days
6
13% of all-time downloads
zuliaio/specter2-proximity-onnx
specter2-proximity-onnx is a feature extraction model from zuliaio. Use it when you need embeddings to search or compare text. It is set up for onnxruntime. The card lists the license as apache-2.0.
A single-file ONNX export of SPECTER2 with the proximity adapter activated. SPECTER2 produces scientific document embeddings trained on citation links (Singh et al., 2022). The proximity adapter is the variant intende…
Downloads · 30 days
6
13% of all-time downloads
All-time downloads
45
Public
Repo size
441 MB
Likes
0
Public
Click a slice to open those files.
.onnx441 MB · 100%
From the Hugging Face model README
A single-file ONNX export of SPECTER2 with the proximity adapter activated. SPECTER2 produces scientific document embeddings trained on citation links (Singh et al., 2022). The proximity adapter is the variant intended for document-to-document similarity and nearest-neighbor retrieval.
This repository exists so the model can be loaded by ONNX Runtime without the adapters Python
library. It is used by Zulia as KnownEmbeddingModel.SPECTER2.
export_specter2_onnx.py in this repository is the exact script that produced model.onnx. It loads the
base model and adapter from Hugging Face, traces the graph, checks the ONNX output against PyTorch and
writes this folder:
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install adapters onnx onnxruntime huggingface_hub
python export_specter2_onnx.py --out ./specter2-proximity-onnx
allenai/specter2 was activated on allenai/specter2_base and the complete forward
pass was traced to ONNX (opset 17, fp32). The adapter layers are part of the graph.input_ids, attention_mask and token_type_ids and returns last_hidden_state.
Pooling is not part of the graph. Apply CLS pooling (take position 0) and L2 normalize.SPECTER2 expects the paper title and abstract joined by the tokenizer separator token:
title[SEP]abstract. Maximum sequence length is 512 tokens. Embedding dimension is 768.
import numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("zuliaio/specter2-proximity-onnx")
sess = ort.InferenceSession("model.onnx")
enc = tok(["Title[SEP]Abstract text"], padding=True, truncation=True, max_length=512, return_tensors="np")
hidden = sess.run(None, dict(enc))[0]
emb = hidden[:, 0, :]
emb = emb / np.linalg.norm(emb, axis=1, keepdims=True)
Apache License 2.0, unchanged from the upstream base model and adapter released by the Allen Institute for AI. See the SPECTER2 repository and SciRepEval. If you use this model, please cite:
@inproceedings{Singh2022SciRepEvalAM,
title={SciRepEval: A Multi-Format Benchmark for Scientific Document Representations},
author={Amanpreet Singh and Mike D'Arcy and Arman Cohan and Doug Downey and Sergey Feldman},
booktitle={Conference on Empirical Methods in Natural Language Processing},
year={2022},
url={https://api.semanticscholar.org/CorpusID:254018137}
}
@inproceedings{specter2020cohan,
title={SPECTER: Document-level Representation Learning using Citation-informed Transformers},
author={Arman Cohan and Sergey Feldman and Iz Beltagy and Doug Downey and Daniel S. Weld},
booktitle={ACL},
year={2020}
}