Add model.safetensors converted from pytorch_model.bin
Browse files- .gitattributes +0 -1
- README.md +183 -0
- config.json +31 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +16 -0
- vocab.txt +0 -0
.gitattributes
CHANGED
|
@@ -25,7 +25,6 @@
|
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 28 |
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
*.wasm filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
datasets:
|
| 4 |
+
- allenai/scirepeval
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 10 |
+
|
| 11 |
+
## SPECTER2
|
| 12 |
+
|
| 13 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
| 14 |
+
|
| 15 |
+
SPECTER2 is the successor to [SPECTER](https://huggingface.co/allenai/specter) and is capable of generating task specific embeddings for scientific tasks when paired with [adapters](https://huggingface.co/models?search=allenai/specter-2_).
|
| 16 |
+
This is the base model to be used along with the adapters.
|
| 17 |
+
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.
|
| 18 |
+
|
| 19 |
+
**Note:For general embedding purposes, please use [allenai/specter2](https://huggingface.co/allenai/specter2).**
|
| 20 |
+
|
| 21 |
+
**To get the best performance on a downstream task type please load the associated adapter with the base model as in the example below.**
|
| 22 |
+
|
| 23 |
+
**Dec 2023 Update:**
|
| 24 |
+
|
| 25 |
+
Model usage updated to be compatible with latest versions of transformers and adapters (newly released update to adapter-transformers) libraries.
|
| 26 |
+
|
| 27 |
+
**Aug 2023 Update:**
|
| 28 |
+
1. **The SPECTER2 Base and proximity adapter models have been renamed in Hugging Face based upon usage patterns as follows:**
|
| 29 |
+
|
| 30 |
+
|Old Name|New Name|
|
| 31 |
+
|--|--|
|
| 32 |
+
|allenai/specter2|[allenai/specter2_base](https://huggingface.co/allenai/specter2_base)|
|
| 33 |
+
|allenai/specter2_proximity|[allenai/specter2](https://huggingface.co/allenai/specter2)|
|
| 34 |
+
|
| 35 |
+
2. **We have a parallel version (termed [aug2023refresh](https://huggingface.co/allenai/specter2_aug2023refresh)) where the base transformer encoder version is pre-trained on a collection of newer papers (published after 2018).
|
| 36 |
+
However, for benchmarking purposes, please continue using the current version.**
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
An [adapter](https://adapterhub.ml) for the [allenai/specter2_base](https://huggingface.co/allenai/specter2_base) model that was trained on the [allenai/scirepeval](https://huggingface.co/datasets/allenai/scirepeval/) dataset.
|
| 40 |
+
|
| 41 |
+
This adapter was created for usage with the **[adapters](https://github.com/adapter-hub/adapters)** library.
|
| 42 |
+
|
| 43 |
+
# Model Details
|
| 44 |
+
|
| 45 |
+
## Model Description
|
| 46 |
+
|
| 47 |
+
SPECTER2 has been trained on over 6M triplets of scientific paper citations, which are available [here](https://huggingface.co/datasets/allenai/scirepeval/viewer/cite_prediction_new/evaluation).
|
| 48 |
+
Post that it is trained with additionally attached task format specific adapter modules on all the [SciRepEval](https://huggingface.co/datasets/allenai/scirepeval) training tasks.
|
| 49 |
+
|
| 50 |
+
Task Formats trained on:
|
| 51 |
+
- Classification
|
| 52 |
+
- Regression
|
| 53 |
+
- Proximity (Retrieval)
|
| 54 |
+
- Adhoc Search
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
It builds on the work done in [SciRepEval: A Multi-Format Benchmark for Scientific Document Representations](https://api.semanticscholar.org/CorpusID:254018137) and we evaluate the trained model on this benchmark as well.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
- **Developed by:** Amanpreet Singh, Mike D'Arcy, Arman Cohan, Doug Downey, Sergey Feldman
|
| 62 |
+
- **Shared by :** Allen AI
|
| 63 |
+
- **Model type:** bert-base-uncased + adapters
|
| 64 |
+
- **License:** Apache 2.0
|
| 65 |
+
- **Finetuned from model:** [allenai/scibert](https://huggingface.co/allenai/scibert_scivocab_uncased).
|
| 66 |
+
|
| 67 |
+
## Model Sources
|
| 68 |
+
|
| 69 |
+
<!-- Provide the basic links for the model. -->
|
| 70 |
+
|
| 71 |
+
- **Repository:** [https://github.com/allenai/SPECTER2](https://github.com/allenai/SPECTER2)
|
| 72 |
+
- **Paper:** [https://api.semanticscholar.org/CorpusID:254018137](https://api.semanticscholar.org/CorpusID:254018137)
|
| 73 |
+
- **Demo:** [Usage](https://github.com/allenai/SPECTER2/blob/main/README.md)
|
| 74 |
+
|
| 75 |
+
# Uses
|
| 76 |
+
|
| 77 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 78 |
+
|
| 79 |
+
## Direct Use
|
| 80 |
+
|
| 81 |
+
|Model|Name and HF link|Description|
|
| 82 |
+
|--|--|--|
|
| 83 |
+
|Proximity*|[allenai/specter2](https://huggingface.co/allenai/specter2)|Encode papers as queries and candidates eg. Link Prediction, Nearest Neighbor Search|
|
| 84 |
+
|Adhoc Query|[allenai/specter2_adhoc_query](https://huggingface.co/allenai/specter2_adhoc_query)|Encode short raw text queries for search tasks. (Candidate papers can be encoded with the proximity adapter)|
|
| 85 |
+
|Classification|[allenai/specter2_classification](https://huggingface.co/allenai/specter2_classification)|Encode papers to feed into linear classifiers as features|
|
| 86 |
+
|Regression|[allenai/specter2_regression](https://huggingface.co/allenai/specter2_regression)|Encode papers to feed into linear regressors as features|
|
| 87 |
+
|
| 88 |
+
*Proximity model should suffice for downstream task types not mentioned above
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
from transformers import AutoTokenizer
|
| 92 |
+
from adapters import AutoAdapterModel
|
| 93 |
+
|
| 94 |
+
# load model and tokenizer
|
| 95 |
+
tokenizer = AutoTokenizer.from_pretrained('allenai/specter2_base')
|
| 96 |
+
|
| 97 |
+
#load base model
|
| 98 |
+
model = AutoAdapterModel.from_pretrained('allenai/specter2_base')
|
| 99 |
+
|
| 100 |
+
#load the adapter(s) as per the required task, provide an identifier for the adapter in load_as argument and activate it
|
| 101 |
+
model.load_adapter("allenai/specter2", source="hf", load_as="proximity", set_active=True)
|
| 102 |
+
#other possibilities: allenai/specter2_<classification|regression|adhoc_query>
|
| 103 |
+
|
| 104 |
+
papers = [{'title': 'BERT', 'abstract': 'We introduce a new language representation model called BERT'},
|
| 105 |
+
{'title': 'Attention is all you need', 'abstract': ' The dominant sequence transduction models are based on complex recurrent or convolutional neural networks'}]
|
| 106 |
+
|
| 107 |
+
# concatenate title and abstract
|
| 108 |
+
text_batch = [d['title'] + tokenizer.sep_token + (d.get('abstract') or '') for d in papers]
|
| 109 |
+
# preprocess the input
|
| 110 |
+
inputs = self.tokenizer(text_batch, padding=True, truncation=True,
|
| 111 |
+
return_tensors="pt", return_token_type_ids=False, max_length=512)
|
| 112 |
+
output = model(**inputs)
|
| 113 |
+
# take the first token in the batch as the embedding
|
| 114 |
+
embeddings = output.last_hidden_state[:, 0, :]
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
## Downstream Use
|
| 118 |
+
|
| 119 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 120 |
+
|
| 121 |
+
For evaluation and downstream usage, please refer to [https://github.com/allenai/scirepeval/blob/main/evaluation/INFERENCE.md](https://github.com/allenai/scirepeval/blob/main/evaluation/INFERENCE.md).
|
| 122 |
+
|
| 123 |
+
# Training Details
|
| 124 |
+
|
| 125 |
+
## Training Data
|
| 126 |
+
|
| 127 |
+
<!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 128 |
+
|
| 129 |
+
The base model is trained on citation links between papers and the adapters are trained on 8 large scale tasks across the four formats.
|
| 130 |
+
All the data is a part of SciRepEval benchmark and is available [here](https://huggingface.co/datasets/allenai/scirepeval).
|
| 131 |
+
|
| 132 |
+
The citation link are triplets in the form
|
| 133 |
+
|
| 134 |
+
```json
|
| 135 |
+
{"query": {"title": ..., "abstract": ...}, "pos": {"title": ..., "abstract": ...}, "neg": {"title": ..., "abstract": ...}}
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
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.
|
| 139 |
+
|
| 140 |
+
## Training Procedure
|
| 141 |
+
|
| 142 |
+
Please refer to the [SPECTER paper](https://api.semanticscholar.org/CorpusID:215768677).
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
### Training Hyperparameters
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
The model is trained in two stages using [SciRepEval](https://github.com/allenai/scirepeval/blob/main/training/TRAINING.md):
|
| 149 |
+
- Base Model: First a base model is trained on the above citation triplets.
|
| 150 |
+
``` batch size = 1024, max input length = 512, learning rate = 2e-5, epochs = 2 warmup steps = 10% fp16```
|
| 151 |
+
- 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.
|
| 152 |
+
``` batch size = 256, max input length = 512, learning rate = 1e-4, epochs = 6 warmup = 1000 steps fp16```
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
# Evaluation
|
| 156 |
+
|
| 157 |
+
We evaluate the model on [SciRepEval](https://github.com/allenai/scirepeval), a large scale eval benchmark for scientific embedding tasks which which has [SciDocs] as a subset.
|
| 158 |
+
We also evaluate and establish a new SoTA on [MDCR](https://github.com/zoranmedic/mdcr), a large scale citation recommendation benchmark.
|
| 159 |
+
|
| 160 |
+
|Model|SciRepEval In-Train|SciRepEval Out-of-Train|SciRepEval Avg|MDCR(MAP, Recall@5)|
|
| 161 |
+
|--|--|--|--|--|
|
| 162 |
+
|[BM-25](https://api.semanticscholar.org/CorpusID:252199740)|n/a|n/a|n/a|(33.7, 28.5)|
|
| 163 |
+
|[SPECTER](https://huggingface.co/allenai/specter)|54.7|72.0|67.5|(30.6, 25.5)|
|
| 164 |
+
|[SciNCL](https://huggingface.co/malteos/scincl)|55.6|73.4|68.8|(32.6, 27.3)|
|
| 165 |
+
|[SciRepEval-Adapters](https://huggingface.co/models?search=scirepeval)|61.9|73.8|70.7|(35.3, 29.6)|
|
| 166 |
+
|[SPECTER2 Base](allenai/specter2_base)|56.3|73.6|69.1|(38.0, 32.4)|
|
| 167 |
+
|[SPECTER2-Adapters](https://huggingface.co/models?search=allenai/specter-2)|**62.3**|**74.1**|**71.1**|**(38.4, 33.0)**|
|
| 168 |
+
|
| 169 |
+
Please cite the following works if you end up using SPECTER2:
|
| 170 |
+
|
| 171 |
+
```
|
| 172 |
+
[SciRepEval paper](https://api.semanticscholar.org/CorpusID:254018137)
|
| 173 |
+
```bibtex
|
| 174 |
+
@inproceedings{Singh2022SciRepEvalAM,
|
| 175 |
+
title={SciRepEval: A Multi-Format Benchmark for Scientific Document Representations},
|
| 176 |
+
author={Amanpreet Singh and Mike D'Arcy and Arman Cohan and Doug Downey and Sergey Feldman},
|
| 177 |
+
booktitle={Conference on Empirical Methods in Natural Language Processing},
|
| 178 |
+
year={2022},
|
| 179 |
+
url={https://api.semanticscholar.org/CorpusID:254018137}
|
| 180 |
+
}
|
| 181 |
+
```
|
| 182 |
+
|
| 183 |
+
|
config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "scirepeval/specterv4/checkpoints/model",
|
| 3 |
+
"adapters": {
|
| 4 |
+
"adapters": {},
|
| 5 |
+
"config_map": {},
|
| 6 |
+
"fusion_config_map": {},
|
| 7 |
+
"fusions": {}
|
| 8 |
+
},
|
| 9 |
+
"architectures": [
|
| 10 |
+
"BertModel"
|
| 11 |
+
],
|
| 12 |
+
"attention_probs_dropout_prob": 0.1,
|
| 13 |
+
"classifier_dropout": null,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"hidden_dropout_prob": 0.1,
|
| 16 |
+
"hidden_size": 768,
|
| 17 |
+
"initializer_range": 0.02,
|
| 18 |
+
"intermediate_size": 3072,
|
| 19 |
+
"layer_norm_eps": 1e-12,
|
| 20 |
+
"max_position_embeddings": 512,
|
| 21 |
+
"model_type": "bert",
|
| 22 |
+
"num_attention_heads": 12,
|
| 23 |
+
"num_hidden_layers": 12,
|
| 24 |
+
"pad_token_id": 0,
|
| 25 |
+
"position_embedding_type": "absolute",
|
| 26 |
+
"torch_dtype": "float32",
|
| 27 |
+
"transformers_version": "4.26.1",
|
| 28 |
+
"type_vocab_size": 2,
|
| 29 |
+
"use_cache": true,
|
| 30 |
+
"vocab_size": 31090
|
| 31 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cf759fdf8ca467ffc9095f8e3262be74a4fd054d355e24549ef4cf793c62c648
|
| 3 |
+
size 439700376
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:801eda968fad1752fe846a8e572bfdc25202be85544680dda4c99f4589646ebc
|
| 3 |
+
size 439740465
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"do_basic_tokenize": true,
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 7 |
+
"name_or_path": "scirepeval/specterv4/checkpoints/tokenizer",
|
| 8 |
+
"never_split": null,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"special_tokens_map_file": null,
|
| 12 |
+
"strip_accents": null,
|
| 13 |
+
"tokenize_chinese_chars": true,
|
| 14 |
+
"tokenizer_class": "BertTokenizer",
|
| 15 |
+
"unk_token": "[UNK]"
|
| 16 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|