Views
No views yet
allenai/specter2_aug2023refresh_classification for allenai/specter2_aug2023refresh_baseadapters:pip install -U adapters1from adapters import AutoAdapterModel
2
3model = AutoAdapterModel.from_pretrained("allenai/specter2_aug2023refresh_base")
4adapter_name = model.load_adapter("allenai/specter2_aug2023refresh_classification", source="hf", set_active=True)| Model | Name and HF link | Description |
|---|---|---|
| Proximity* | allenai/specter2_aug2023refresh_proximity | Encode papers as queries and candidates eg. Link Prediction, Nearest Neighbor Search |
| Adhoc Query | allenai/specter2_aug2023refresh_adhoc_query | Encode short raw text queries for search tasks. (Candidate papers can be encoded with the proximity adapter) |
| Classification | allenai/specter2_aug2023refresh_classification | Encode papers to feed into linear classifiers as features |
| Regression | allenai/specter2_aug2023refresh_regression | Encode papers to feed into linear regressors as features |
1from transformers import AutoTokenizer
2from adapters import AutoAdapterModel
3
4# load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained('allenai/specter2_aug2023refresh_base')
6
7#load base model
8model = AutoAdapterModel.from_pretrained('allenai/specter2_aug2023refresh_base')
9
10#load the adapter(s) as per the required task, provide an identifier for the adapter in load_as argument and activate it
11model.load_adapter("allenai/specter2_aug2023refresh_classification", source="hf", load_as="specter2_classification", set_active=True)
12
13papers = [{'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'}]
15
16# concatenate title and abstract
17text_batch = [d['title'] + tokenizer.sep_token + (d.get('abstract') or '') for d in papers]
18# preprocess the input
19inputs = 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 embedding
23embeddings = output.last_hidden_state[:, 0, :]{"query": {"title": ..., "abstract": ...}, "pos": {"title": ..., "abstract": ...}, "neg": {"title": ..., "abstract": ...}} batch size = 1024, max input length = 512, learning rate = 2e-5, epochs = 2 warmup steps = 10% fp16 batch size = 256, max input length = 512, learning rate = 1e-4, epochs = 6 warmup = 1000 steps fp16| Model | SciRepEval In-Train | SciRepEval Out-of-Train | SciRepEval Avg | MDCR(MAP, Recall@5) |
|---|---|---|---|---|
| BM-25 | n/a | n/a | n/a | (33.7, 28.5) |
| SPECTER | 54.7 | 57.4 | 68.0 | (30.6, 25.5) |
| SciNCL | 55.6 | 57.8 | 69.0 | (32.6, 27.3) |
| SciRepEval-Adapters | 61.9 | 59.0 | 70.9 | (35.3, 29.6) |
| SPECTER 2.0-Adapters | 62.3 | 59.2 | 71.2 | (38.4, 33.0) |
1@inproceedings{specter2020cohan,
2 title={{SPECTER: Document-level Representation Learning using Citation-informed Transformers}},
3 author={Arman Cohan and Sergey Feldman and Iz Beltagy and Doug Downey and Daniel S. Weld},
4 booktitle={ACL},
5 year={2020}
6}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}