ZhiyuanChen commited on
Commit
388aa52
·
verified ·
1 Parent(s): af3884c

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: rna
3
+ tags:
4
+ - Biology
5
+ - RNA
6
+ license: agpl-3.0
7
+ datasets:
8
+ - multimolecule/ucsc-genome-browser
9
+ library_name: multimolecule
10
+ pipeline_tag: fill-mask
11
+ mask_token: "<mask>"
12
+ widget:
13
+ - example_title: "HIV-1"
14
+ text: "GGUC<mask>CUCUGGUUAGACCAGAUCUGAGCCU"
15
+ output:
16
+ - label: "U"
17
+ score: 0.340412974357605
18
+ - label: "Y"
19
+ score: 0.13882005214691162
20
+ - label: "C"
21
+ score: 0.056610625237226486
22
+ - label: "H"
23
+ score: 0.05455885827541351
24
+ - label: "W"
25
+ score: 0.05356108024716377
26
+ - example_title: "microRNA-21"
27
+ text: "UAGC<mask>UAUCAGACUGAUGUUG"
28
+ output:
29
+ - label: "A"
30
+ score: 0.09153486788272858
31
+ - label: "W"
32
+ score: 0.08465325832366943
33
+ - label: "U"
34
+ score: 0.07828908413648605
35
+ - label: "H"
36
+ score: 0.06861720234155655
37
+ - label: "M"
38
+ score: 0.0642390251159668
39
+ ---
40
+
41
+ # SpliceBERT
42
+
43
+ Pre-trained model on messenger RNA precursor (pre-mRNA) using a masked language modeling (MLM) objective.
44
+
45
+ ## Disclaimer
46
+
47
+ This is an UNOFFICIAL implementation of the [Self-supervised learning on millions of pre-mRNA sequences improves sequence-based RNA splicing prediction](https://doi.org/10.1101/2023.01.31.526427) by Ken Chen, et al.
48
+
49
+ The OFFICIAL repository of SpliceBERT is at [chenkenbio/SpliceBERT](https://github.com/chenkenbio/SpliceBERT).
50
+
51
+ > [!TIP]
52
+ > The MultiMolecule team has confirmed that the provided model and checkpoints are producing the same intermediate representations as the original implementation.
53
+
54
+ **The team releasing SpliceBERT did not write this model card for this model so this model card has been written by the MultiMolecule team.**
55
+
56
+ ## Model Details
57
+
58
+ SpliceBERT is a [bert](https://huggingface.co/google-bert/bert-base-uncased)-style model pre-trained on a large corpus of messenger RNA precursor sequences in a self-supervised fashion. This means that the model was trained on the raw nucleotides of RNA sequences only, with an automatic process to generate inputs and labels from those texts. Please refer to the [Training Details](#training-details) section for more information on the training process.
59
+
60
+ ### Variations
61
+
62
+ - **[multimolecule/splicebert](https://huggingface.co/multimolecule/splicebert)**: The SpliceBERT model.
63
+ - **[multimolecule/splicebert.510](https://huggingface.co/multimolecule/splicebert.510)**: The intermediate SpliceBERT model.
64
+ - **[multimolecule/splicebert-human.510](https://huggingface.co/multimolecule/splicebert-human.510)**: The intermediate SpliceBERT model pre-trained on human data only.
65
+
66
+ ### Model Specification
67
+
68
+ <table>
69
+ <thead>
70
+ <tr>
71
+ <th>Variants</th>
72
+ <th>Num Layers</th>
73
+ <th>Hidden Size</th>
74
+ <th>Num Heads</th>
75
+ <th>Intermediate Size</th>
76
+ <th>Num Parameters (M)</th>
77
+ <th>FLOPs (G)</th>
78
+ <th>MACs (G)</th>
79
+ <th>Max Num Tokens</th>
80
+ </tr>
81
+ </thead>
82
+ <tbody>
83
+ <tr>
84
+ <td>splicebert</td>
85
+ <td rowspan="3">6</td>
86
+ <td rowspan="3">512</td>
87
+ <td rowspan="3">16</td>
88
+ <td rowspan="3">2048</td>
89
+ <td>19.72</td>
90
+ <td rowspan="3">5.04</td>
91
+ <td rowspan="3">2.52</td>
92
+ <td>1024</td>
93
+ </tr>
94
+ <tr>
95
+ <td>splicebert.510</td>
96
+ <td rowspan="2">19.45</td>
97
+ <td rowspan="2">510</td>
98
+ </tr>
99
+ <tr>
100
+ <td>splicebert-human.510</td>
101
+ </tr>
102
+ </tbody>
103
+ </table>
104
+
105
+ ### Links
106
+
107
+ - **Code**: [multimolecule.splicebert](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/splicebert)
108
+ - **Data**: [UCSC Genome Browser](https://genome.ucsc.edu)
109
+ - **Paper**: [Self-supervised learning on millions of pre-mRNA sequences improves sequence-based RNA splicing prediction](https://doi.org/10.1101/2023.01.31.526427)
110
+ - **Developed by**: Ken Chen, Yue Zhou, Maolin Ding, Yu Wang, Zhixiang Ren, Yuedong Yang
111
+ - **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased) - [FlashAttention](https://huggingface.co/docs/text-generation-inference/en/conceptual/flash_attention)
112
+ - **Original Repository**: [chenkenbio/SpliceBERT](https://github.com/chenkenbio/SpliceBERT)
113
+
114
+ ## Usage
115
+
116
+ The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:
117
+
118
+ ```bash
119
+ pip install multimolecule
120
+ ```
121
+
122
+ ### Direct Use
123
+
124
+ You can use this model directly with a pipeline for masked language modeling:
125
+
126
+ ```python
127
+ >>> import multimolecule # you must import multimolecule to register models
128
+ >>> from transformers import pipeline
129
+
130
+ >>> unmasker = pipeline("fill-mask", model="multimolecule/splicebert")
131
+ >>> unmasker("gguc<mask>cucugguuagaccagaucugagccu")
132
+ [{'score': 0.340412974357605,
133
+ 'token': 9,
134
+ 'token_str': 'U',
135
+ 'sequence': 'G G U C U C U C U G G U U A G A C C A G A U C U G A G C C U'},
136
+ {'score': 0.13882005214691162,
137
+ 'token': 12,
138
+ 'token_str': 'Y',
139
+ 'sequence': 'G G U C Y C U C U G G U U A G A C C A G A U C U G A G C C U'},
140
+ {'score': 0.056610625237226486,
141
+ 'token': 7,
142
+ 'token_str': 'C',
143
+ 'sequence': 'G G U C C C U C U G G U U A G A C C A G A U C U G A G C C U'},
144
+ {'score': 0.05455885827541351,
145
+ 'token': 19,
146
+ 'token_str': 'H',
147
+ 'sequence': 'G G U C H C U C U G G U U A G A C C A G A U C U G A G C C U'},
148
+ {'score': 0.05356108024716377,
149
+ 'token': 14,
150
+ 'token_str': 'W',
151
+ 'sequence': 'G G U C W C U C U G G U U A G A C C A G A U C U G A G C C U'}]
152
+ ```
153
+
154
+ ### Downstream Use
155
+
156
+ #### Extract Features
157
+
158
+ Here is how to use this model to get the features of a given sequence in PyTorch:
159
+
160
+ ```python
161
+ from multimolecule import RnaTokenizer, SpliceBertModel
162
+
163
+
164
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/splicebert")
165
+ model = SpliceBertModel.from_pretrained("multimolecule/splicebert")
166
+
167
+ text = "UAGCUUAUCAGACUGAUGUUG"
168
+ input = tokenizer(text, return_tensors="pt")
169
+
170
+ output = model(**input)
171
+ ```
172
+
173
+ #### Sequence Classification / Regression
174
+
175
+ > [!NOTE]
176
+ > This model is not fine-tuned for any specific task. You will need to fine-tune the model on a downstream task to use it for sequence classification or regression.
177
+
178
+ Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:
179
+
180
+ ```python
181
+ import torch
182
+ from multimolecule import RnaTokenizer, SpliceBertForSequencePrediction
183
+
184
+
185
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/splicebert")
186
+ model = SpliceBertForSequencePrediction.from_pretrained("multimolecule/splicebert")
187
+
188
+ text = "UAGCUUAUCAGACUGAUGUUG"
189
+ input = tokenizer(text, return_tensors="pt")
190
+ label = torch.tensor([1])
191
+
192
+ output = model(**input, labels=label)
193
+ ```
194
+
195
+ #### Token Classification / Regression
196
+
197
+ > [!NOTE]
198
+ > This model is not fine-tuned for any specific task. You will need to fine-tune the model on a downstream task to use it for token classification or regression.
199
+
200
+ Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:
201
+
202
+ ```python
203
+ import torch
204
+ from multimolecule import RnaTokenizer, SpliceBertForTokenPrediction
205
+
206
+
207
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/splicebert")
208
+ model = SpliceBertForTokenPrediction.from_pretrained("multimolecule/splicebert")
209
+
210
+ text = "UAGCUUAUCAGACUGAUGUUG"
211
+ input = tokenizer(text, return_tensors="pt")
212
+ label = torch.randint(2, (len(text), ))
213
+
214
+ output = model(**input, labels=label)
215
+ ```
216
+
217
+ #### Contact Classification / Regression
218
+
219
+ > [!NOTE]
220
+ > This model is not fine-tuned for any specific task. You will need to fine-tune the model on a downstream task to use it for contact classification or regression.
221
+
222
+ Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:
223
+
224
+ ```python
225
+ import torch
226
+ from multimolecule import RnaTokenizer, SpliceBertForContactPrediction
227
+
228
+
229
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/splicebert")
230
+ model = SpliceBertForContactPrediction.from_pretrained("multimolecule/splicebert")
231
+
232
+ text = "UAGCUUAUCAGACUGAUGUUG"
233
+ input = tokenizer(text, return_tensors="pt")
234
+ label = torch.randint(2, (len(text), len(text)))
235
+
236
+ output = model(**input, labels=label)
237
+ ```
238
+
239
+ ## Training Details
240
+
241
+ SpliceBERT used Masked Language Modeling (MLM) as the pre-training objective: taking a sequence, the model randomly masks 15% of the tokens in the input then runs the entire masked sentence through the model and has to predict the masked tokens. This is comparable to the Cloze task in language modeling.
242
+
243
+ ### Training Data
244
+
245
+ The SpliceBERT model was pre-trained on messenger RNA precursor sequences from [UCSC Genome Browser](https://genome.ucsc.edu).
246
+ UCSC Genome Browser provides visualization, analysis, and download of comprehensive vertebrate genome data with aligned annotation tracks (known genes, predicted genes, ESTs, mRNAs, CpG islands, etc.).
247
+
248
+ SpliceBERT collected reference genomes and gene annotations from the UCSC Genome Browser for 72 vertebrate species. It applied [bedtools getfasta](https://bedtools.readthedocs.io/en/latest/content/tools/getfasta.html) to extract pre-mRNA sequences from the reference genomes based on the gene annotations. The pre-mRNA sequences are then used to pre-train SpliceBERT. The pre-training data contains 2 million pre-mRNA sequences with a total length of 65 billion nucleotides.
249
+
250
+ Note [`RnaTokenizer`][multimolecule.RnaTokenizer] will convert "T"s to "U"s for you, you may disable this behaviour by passing `replace_T_with_U=False`.
251
+
252
+ ### Training Procedure
253
+
254
+ #### Preprocessing
255
+
256
+ SpliceBERT used masked language modeling (MLM) as the pre-training objective. The masking procedure is similar to the one used in BERT:
257
+
258
+ - 15% of the tokens are masked.
259
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
260
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
261
+ - In the 10% remaining cases, the masked tokens are left as is.
262
+
263
+ #### Pre-training
264
+
265
+ The model was trained on 8 NVIDIA V100 GPUs.
266
+
267
+ - Optimizer: AdamW
268
+ - Learning rate: 1e-4
269
+ - Learning rate scheduler: ReduceLROnPlateau(patience=3)
270
+
271
+ SpliceBERT trained model in a two-stage training process:
272
+
273
+ 1. Pre-train with sequences of a fixed length of 510 nucleotides.
274
+ 2. Pre-train with sequences of a variable length between 64 and 1024 nucleotides.
275
+
276
+ The intermediate model after the first stage is available as `multimolecule/splicebert.510`.
277
+
278
+ SpliceBERT also pre-trained a model on human data only to validate the contribution of multi-species pre-training. The intermediate model after the first stage is available as `multimolecule/splicebert-human.510`.
279
+
280
+ ## Citation
281
+
282
+ **BibTeX**:
283
+
284
+ ```bibtex
285
+ @article {chen2023self,
286
+ author = {Chen, Ken and Zhou, Yue and Ding, Maolin and Wang, Yu and Ren, Zhixiang and Yang, Yuedong},
287
+ title = {Self-supervised learning on millions of pre-mRNA sequences improves sequence-based RNA splicing prediction},
288
+ elocation-id = {2023.01.31.526427},
289
+ year = {2023},
290
+ doi = {10.1101/2023.01.31.526427},
291
+ publisher = {Cold Spring Harbor Laboratory},
292
+ abstract = {RNA splicing is an important post-transcriptional process of gene expression in eukaryotic cells. Predicting RNA splicing from primary sequences can facilitate the interpretation of genomic variants. In this study, we developed a novel self-supervised pre-trained language model, SpliceBERT, to improve sequence-based RNA splicing prediction. Pre-training on pre-mRNA sequences from vertebrates enables SpliceBERT to capture evolutionary conservation information and characterize the unique property of splice sites. SpliceBERT also improves zero-shot prediction of variant effects on splicing by considering sequence context information, and achieves superior performance for predicting branchpoint in the human genome and splice sites across species. Our study highlighted the importance of pre-training genomic language models on a diverse range of species and suggested that pre-trained language models were promising for deciphering the sequence logic of RNA splicing.Competing Interest StatementThe authors have declared no competing interest.},
293
+ URL = {https://www.biorxiv.org/content/early/2023/05/09/2023.01.31.526427},
294
+ eprint = {https://www.biorxiv.org/content/early/2023/05/09/2023.01.31.526427.full.pdf},
295
+ journal = {bioRxiv}
296
+ }
297
+ ```
298
+
299
+ ## Contact
300
+
301
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
302
+
303
+ Please contact the authors of the [SpliceBERT paper](https://doi.org/10.1101/2023.01.31.526427) for questions or comments on the paper/model.
304
+
305
+ ## License
306
+
307
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
308
+
309
+ ```spdx
310
+ SPDX-License-Identifier: AGPL-3.0-or-later
311
+ ```
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "SpliceBertForPreTraining"
4
+ ],
5
+ "attention_dropout": 0.1,
6
+ "bos_token_id": 1,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "head": null,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout": 0.1,
12
+ "hidden_size": 512,
13
+ "id2label": null,
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 2048,
16
+ "label2id": null,
17
+ "layer_norm_eps": 1e-12,
18
+ "lm_head": null,
19
+ "mask_token_id": 4,
20
+ "max_position_embeddings": 512,
21
+ "model_type": "splicebert",
22
+ "null_token_id": 5,
23
+ "num_attention_heads": 16,
24
+ "num_hidden_layers": 6,
25
+ "num_labels": 1,
26
+ "output_hidden_states": true,
27
+ "pad_token_id": 0,
28
+ "position_embedding_type": "absolute",
29
+ "torch_dtype": "float32",
30
+ "transformers_version": "4.50.0",
31
+ "type_vocab_size": 2,
32
+ "unk_token_id": 3,
33
+ "use_cache": true,
34
+ "vocab_size": 26
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47db09ac94f2280af358081a7477ec3bce14c0e62120d10833e50dd5c3c38b67
3
+ size 77834792
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b05cbcb1a03d4f52cb7e7adb73a142aabf61965acf99e86edaddd80311ccbb20
3
+ size 77857586
special_tokens_map.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<null>"
4
+ ],
5
+ "bos_token": "<cls>",
6
+ "cls_token": "<cls>",
7
+ "eos_token": "<eos>",
8
+ "mask_token": "<mask>",
9
+ "pad_token": "<pad>",
10
+ "sep_token": "<eos>",
11
+ "unk_token": "<unk>"
12
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<pad>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<cls>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<eos>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "<mask>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "5": {
44
+ "content": "<null>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ }
51
+ },
52
+ "additional_special_tokens": [
53
+ "<null>"
54
+ ],
55
+ "bos_token": "<cls>",
56
+ "clean_up_tokenization_spaces": true,
57
+ "cls_token": "<cls>",
58
+ "codon": false,
59
+ "eos_token": "<eos>",
60
+ "extra_special_tokens": {},
61
+ "mask_token": "<mask>",
62
+ "model_max_length": 512,
63
+ "nmers": 1,
64
+ "pad_token": "<pad>",
65
+ "replace_T_with_U": true,
66
+ "sep_token": "<eos>",
67
+ "tokenizer_class": "RnaTokenizer",
68
+ "unk_token": "<unk>"
69
+ }
vocab.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <pad>
2
+ <cls>
3
+ <eos>
4
+ <unk>
5
+ <mask>
6
+ <null>
7
+ A
8
+ C
9
+ G
10
+ U
11
+ N
12
+ R
13
+ Y
14
+ S
15
+ W
16
+ K
17
+ M
18
+ B
19
+ D
20
+ H
21
+ V
22
+ .
23
+ X
24
+ *
25
+ -
26
+ I