SPECTER2 is a family of models that succeeds SPECTER and is capable of generating task specific embeddings for scientific tasks when paired with adapters.
Given the combination of title and abstract of a scientific paper or a short texual query, the model can be used to generate effective embeddings to be used in downstream applications.
Note:For general embedding purposes, please use allenai/specter2.
To get the best performance on a downstream task type please load the associated adapter () with the base model as in the example below.
Dec 2023 Update:
Model usage updated to be compatible with latest versions of transformers and adapters (newly released update to adapter-transformers) libraries.
Aug 2023 Update:
The SPECTER2 Base and proximity adapter models have been renamed in Hugging Face based upon usage patterns as follows:
We have a parallel version (termed aug2023refresh) where the base transformer encoder version is pre-trained on a collection of newer papers (published after 2018).
However, for benchmarking purposes, please continue using the current version.
Adapter allenai/specter2 for allenai/specter2_base
SPECTER2 has been trained on over 6M triplets of scientific paper citations, which are available here.
Post that it is trained with additionally attached task format specific adapter modules on all the SciRepEval training tasks.
Task Formats trained on:
Classification
Regression
Proximity (Retrieval)
Adhoc Search
This is a retrieval specific adapter. For tasks where given a paper query, other relevant papers have to be retrieved from a corpus, use this adapter to generate the embeddings.
Encode papers to feed into linear regressors as features
*Proximity model should suffice for downstream task types not mentioned above
python
1from transformers import AutoTokenizer
2from adapters import AutoAdapterModel
34# load model and tokenizer5tokenizer = AutoTokenizer.from_pretrained('allenai/specter2_base')67#load base model8model = AutoAdapterModel.from_pretrained('allenai/specter2_base')910#load the adapter(s) as per the required task, provide an identifier for the adapter in load_as argument and activate it11model.load_adapter("allenai/specter2", source="hf", load_as="specter2", set_active=True)1213papers =[{'title':'BERT','abstract':'We introduce a new language representation model called BERT'},14{'title':'Attention is all you need','abstract':' The dominant sequence transduction models are based on complex recurrent or convolutional neural networks'}]1516# concatenate title and abstract17text_batch =[d['title']+ tokenizer.sep_token +(d.get('abstract')or'')for d in papers]18# preprocess the input19inputs = self.tokenizer(text_batch, padding=True, truncation=True,20 return_tensors="pt", return_token_type_ids=False, max_length=512)21output = model(**inputs)22# take the first token in the batch as the embedding23embeddings = output.last_hidden_state[:,0,:]
The base model is trained on citation links between papers and the adapters are trained on 8 large scale tasks across the four formats.
All the data is a part of SciRepEval benchmark and is available here.
consisting of a query paper, a positive citation and a negative which can be from the same/different field of study as the query or citation of a citation.
The model is trained in two stages using SciRepEval:
Base Model: First a base model is trained on the above citation triplets.
batch size = 1024, max input length = 512, learning rate = 2e-5, epochs = 2 warmup steps = 10% fp16
Adapters: Thereafter, task format specific adapters are trained on the SciRepEval training tasks, where 600K triplets are sampled from above and added to the training data as well.
batch size = 256, max input length = 512, learning rate = 1e-4, epochs = 6 warmup = 1000 steps fp16
Evaluation
We evaluate the model on SciRepEval, a large scale eval benchmark for scientific embedding tasks which which has [SciDocs] as a subset.
We also evaluate and establish a new SoTA on MDCR, a large scale citation recommendation benchmark.
1@inproceedings{Singh2022SciRepEvalAM,
2 title={SciRepEval: A Multi-Format Benchmark for Scientific Document Representations},
3 author={Amanpreet Singh and Mike D'Arcy and Arman Cohan and Doug Downey and Sergey Feldman},
4 booktitle={Conference on Empirical Methods in Natural Language Processing},
5 year={2022},
6 url={https://api.semanticscholar.org/CorpusID:254018137}
7}