tau
/

Transformers
PyTorch
English
tau/sled
Inference Endpoints
maorivgi commited on
Commit
d01ed1c
1 Parent(s): 6d9090f

initial commit

Browse files
Files changed (3) hide show
  1. README.md +119 -0
  2. config.json +9 -0
  3. tokenizer_config.json +5 -0
README.md CHANGED
@@ -1,3 +1,122 @@
1
  ---
2
  license: mit
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language: en
4
  ---
5
+
6
+ # BART-SLED (SLiding-Encoder and Decoder, large-sized model)
7
+
8
+ SLED models use pretrained, short-range encoder-decoder models, and apply them over
9
+ long-text inputs by splitting the input into multiple overlapping chunks, encoding each independently and perform fusion-in-decoder
10
+
11
+ ## Model description
12
+
13
+ This SLED model is based on the BART model, which is described in its [model card](https://huggingface.co/facebook/bart-large).
14
+ BART is particularly effective when fine-tuned for text generation (e.g. summarization, translation) but also works
15
+ well for comprehension tasks (e.g. text classification, question answering). When used as a BART-SLED model, it can be applied on long text tasks.
16
+
17
+ This model was finetuned on the [GovReport](https://arxiv.org/abs/2104.02112)
18
+
19
+ ## Intended uses & limitations
20
+
21
+ You can use the raw model for text infilling. However, the model is mostly meant to be fine-tuned on a supervised dataset.
22
+
23
+ ### How to use
24
+ To use the model, you first need to install `py-sled` in your environment (or clone the code from the [official repository](https://github.com/Mivg/SLED/blob/main/README.md))
25
+ ```
26
+ pip install py-sled
27
+ ```
28
+ For more installation instructions, see [here](https://github.com/Mivg/SLED#Installation).
29
+
30
+
31
+ Once installed, SLED is fully compatible with HuggingFace's AutoClasses (AutoTokenizer, AutoConfig, AutoModel
32
+ and AutoModelForCausalLM) and can be loaded using the from_pretrained methods
33
+ ```python
34
+ import sled # *** required so that SledModels will be registered for the AutoClasses ***
35
+ model = AutoModel.from_pretrained('tau/bart-large-sled')
36
+ ```
37
+
38
+ Here is how to use this model in PyTorch:
39
+
40
+ ```python
41
+ from sled import SledTokenizer, SledModel
42
+ tokenizer = SledTokenizer.from_pretrained('tau/bart-large-sled')
43
+ model = SledModel.from_pretrained('tau/bart-large-sled')
44
+ inputs = tokenizer("Hello, my dog is cute", return_tensors="pt")
45
+ outputs = model(**inputs)
46
+ last_hidden_states = outputs.last_hidden_state
47
+ ```
48
+ You can also replace SledModel by SledModelForConditionalGeneration for Seq2Seq generation
49
+ ```python
50
+ model = SledModelForConditionalGeneration.from_pretrained('tau/bart-large-sled')
51
+ ```
52
+ In case you wish to apply SLED on a task containing a prefix (e.g. question) which should be given as a context to
53
+ every chunk, you can pass the `prefix_length` tensor input as well (A LongTensor in the length of the batch size).
54
+ ```python
55
+ import torch
56
+ import sled # *** required so that SledModels will be registered for the AutoClasses ***
57
+ tokenizer = AutoTokenizer.from_pretrained('tau/bart-large-sled')
58
+ model = AutoModel.from_pretrained('tau/bart-large-sled')
59
+ document_input_ids = tokenizer("Dogs are great for you.", return_tensors="pt").input_ids
60
+ prefix_input_ids = tokenizer("Are dogs good for you?", return_tensors="pt").input_ids
61
+ input_ids = torch.cat((prefix_input_ids, document_input_ids), dim=-1)
62
+ attention_mask = torch.ones_like(input_ids)
63
+ prefix_length = torch.LongTensor([[prefix_input_ids.size(1)]])
64
+
65
+ outputs = model(input_ids=input_ids, attention_mask=attention_mask, prefix_length=prefix_length)
66
+ last_hidden_states = outputs.last_hidden_state
67
+ ```
68
+
69
+ ### BibTeX entry and citation info
70
+
71
+ Please cite both the SLED [paper](https://arxiv.org/abs/2208.00748.pdf) and the BART [paper](https://arxiv.org/abs/1910.13461) by Lewis et al as well as GovReport by Huang et al
72
+
73
+ ```bibtex
74
+ @inproceedings{Ivgi2022EfficientLU,
75
+ title={Efficient Long-Text Understanding with Short-Text Models},
76
+ author={Maor Ivgi and Uri Shaham and Jonathan Berant},
77
+ year={2022}
78
+ }
79
+ ```
80
+
81
+ ```bibtex
82
+ @article{DBLP:journals/corr/abs-1910-13461,
83
+ author = {Mike Lewis and
84
+ Yinhan Liu and
85
+ Naman Goyal and
86
+ Marjan Ghazvininejad and
87
+ Abdelrahman Mohamed and
88
+ Omer Levy and
89
+ Veselin Stoyanov and
90
+ Luke Zettlemoyer},
91
+ title = {{BART:} Denoising Sequence-to-Sequence Pre-training for Natural Language
92
+ Generation, Translation, and Comprehension},
93
+ journal = {CoRR},
94
+ volume = {abs/1910.13461},
95
+ year = {2019},
96
+ url = {http://arxiv.org/abs/1910.13461},
97
+ eprinttype = {arXiv},
98
+ eprint = {1910.13461},
99
+ timestamp = {Thu, 31 Oct 2019 14:02:26 +0100},
100
+ biburl = {https://dblp.org/rec/journals/corr/abs-1910-13461.bib},
101
+ bibsource = {dblp computer science bibliography, https://dblp.org}
102
+ }
103
+ ```
104
+
105
+ ```bibtex
106
+ @inproceedings{huang2021govreport,
107
+ title = "Efficient Attentions for Long Document Summarization",
108
+ author = "Huang, Luyang and
109
+ Cao, Shuyang and
110
+ Parulian, Nikolaus and
111
+ Ji, Heng and
112
+ Wang, Lu",
113
+ booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
114
+ month = jun,
115
+ year = "2021",
116
+ address = "Online",
117
+ publisher = "Association for Computational Linguistics",
118
+ url = "https://aclanthology.org/2021.naacl-main.112",
119
+ doi = "10.18653/v1/2021.naacl-main.112",
120
+ pages = "1419--1436"
121
+ }
122
+ ```
config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "tau/sled",
3
+ "underlying_config": "facebook/bart-large",
4
+ "context_size": 256,
5
+ "window_fraction": 0.5,
6
+ "prepend_prefix": true,
7
+ "encode_prefix": true,
8
+ "sliding_method": "dynamic"
9
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "tokenizer_class": "SledTokenizer",
3
+ "base_tokenizer": "facebook/bart-large",
4
+ "model_max_length": 16384
5
+ }