Views
No views yet
longformer-large-4096 model was additionally pre-trained on the S2ORC corpus (Lo et al., 2020) by (Wadden et al., 2022). The S2ORC is a large corpus of 81.1M English-language academic papers from different disciplines. The model uses the weights of the longformer large science checkpoint that was also used as the starting point for training the MultiVerS model (Wadden et al., 2022) on the task of scientific claim verification.longformer-large-4096 (50265) since 10 new tokens were included:<|par|>, </|title|>, </|sec|>, <|sec-title|>, <|sent|>, <|title|>, <|abs|>, <|sec|>, </|sec-title|>, </|abs|>.transformers==4.2.2 and torch==1.7.1 correspond to the MultiVerS requirements.txt:1import os
2import pathlib
3import subprocess
4
5import torch
6from transformers import LongformerModel
7
8model = LongformerModel.from_pretrained(
9 "allenai/longformer-large-4096", gradient_checkpointing=False
10)
11
12# Load the pre-trained checkpoint.
13url = f"https://scifact.s3.us-west-2.amazonaws.com/longchecker/latest/checkpoints/#longformer_large_science.ckpt"
14out_file = f"checkpoints/longformer_large_science.ckpt"
15cmd = ["wget", "-O", out_file, url]
16
17if not pathlib.Path(out_file).exists():
18 subprocess.run(cmd)
19
20checkpoint_prefixed = torch.load("checkpoints/longformer_large_science.ckpt")
21
22# New checkpoint
23new_state_dict = {}
24# Add items from loaded checkpoint.
25for k, v in checkpoint_prefixed.items():
26 # Don't need the language model head.
27 if "lm_head." in k:
28 continue
29 # Get rid of the first 8 characters, which say `roberta.`.
30 new_key = k[8:]
31 new_state_dict[new_key] = v
32
33# Resize embeddings and load state dict.
34target_embed_size = new_state_dict["embeddings.word_embeddings.weight"].shape[0]
35model.resize_token_embeddings(target_embed_size)
36model.load_state_dict(new_state_dict)
37
38model_dir = "checkpoints/longformer_large_science"
39if not os.path.exists(model_dir):
40 os.makedirs(model_dir)
41
42model.save_pretrained(model_dir)1from transformers import AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained("allenai/longformer-large-4096")
4ADDITIONAL_TOKENS = {
5 "section_start": "<|sec|>",
6 "section_end": "</|sec|>",
7 "section_title_start": "<|sec-title|>",
8 "section_title_end": "</|sec-title|>",
9 "abstract_start": "<|abs|>",
10 "abstract_end": "</|abs|>",
11 "title_start": "<|title|>",
12 "title_end": "</|title|>",
13 "sentence_sep": "<|sent|>",
14 "paragraph_sep": "<|par|>",
15}
16tokenizer.add_tokens(list(ADDITIONAL_TOKENS.values()))
17tokenizer.save_pretrained("checkpoints/longformer_large_science")