ZhiyuanChen commited on
Commit
5ccfda3
1 Parent(s): accdaa6

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: rna
3
+ tags:
4
+ - Biology
5
+ - RNA
6
+ license: agpl-3.0
7
+ datasets:
8
+ - multimolecule/rfam
9
+ library_name: multimolecule
10
+ pipeline_tag: fill-mask
11
+ mask_token: "<mask>"
12
+ widget:
13
+ - example_title: "microRNA-21"
14
+ text: "UAGC<mask>UAUCAGACUGAUGUUGA"
15
+ output:
16
+ - label: "U"
17
+ score: 0.28535839915275574
18
+ - label: "K"
19
+ score: 0.2532415986061096
20
+ - label: "G"
21
+ score: 0.2247398942708969
22
+ - label: "D"
23
+ score: 0.06841657310724258
24
+ - label: "W"
25
+ score: 0.03774874284863472
26
+ ---
27
+
28
+ # RNA-MSM
29
+
30
+ Pre-trained model on non-coding RNA (ncRNA) with multi (homologous) sequence alignment using a masked language modeling (MLM) objective.
31
+
32
+ ## Disclaimer
33
+
34
+ This is an UNOFFICIAL implementation of the [Multiple sequence alignment-based RNA language model and its application to structural inference](https://doi.org/10.1093/nar/gkad1031) by Yikun Zhang, Mei Lang, Jiuhong Jiang, Zhiqiang Gao, et al.
35
+
36
+ The OFFICIAL repository of RNA-MSM is at [yikunpku/RNA-MSM](https://github.com/yikunpku/RNA-MSM).
37
+
38
+ !!! Bug "Reproducibility"
39
+
40
+ The MultiMolecule team is aware of a potential risk in reproducing the results of RNA-MSM.
41
+
42
+ The original implementation of RNA-MSM used a custom tokenizer.
43
+ The custom tokenizer may not append `<eos>` token to the end of the input sequence.
44
+ This may lead to unexpected results when using the model.
45
+
46
+ This issue is been tracked at [issue #10](https://github.com/yikunpku/RNA-MSM/issues/10)
47
+
48
+ !!! Success "Reproducibility"
49
+
50
+ The MultiMolecule team has confirmed that the provided model and checkpoints are producing the same intermediate representations as the original implementation.
51
+
52
+ **The team releasing RNA-MSM did not write this model card for this model so this model card has been written by the MultiMolecule team.**
53
+
54
+ ## Model Details
55
+
56
+ RNA-MSM is a [bert](https://huggingface.co/google-bert/bert-base-uncased)-style model pre-trained on a large corpus of non-coding RNA 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.
57
+
58
+ ### Model Specification
59
+
60
+ | Num Layers | Hidden Size | Num Heads | Intermediate Size | Num Parameters (M) | FLOPs (G) | MACs (G) | Max Num Tokens |
61
+ | ---------- | ----------- | --------- | ----------------- | ------------------ | --------- | -------- | -------------- |
62
+ | 10 | 768 | 12 | 3072 | 95.92 | 21.66 | 10.57 | 1024 |
63
+
64
+ ### Links
65
+
66
+ - **Code**: [multimolecule.rnamsm](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/rnamsm)
67
+ - **Weights**: [multimolecule/rnamsm](https://huggingface.co/multimolecule/rnamsm)
68
+ - **Data**: [Rfam](https://rfam.org)
69
+ - **Paper**: [Multiple sequence alignment-based RNA language model and its application to structural inference](https://doi.org/10.1093/nar/gkad1031)
70
+ - **Developed by**: Yikun Zhang, Mei Lang, Jiuhong Jiang, Zhiqiang Gao, Fan Xu, Thomas Litfin, Ke Chen, Jaswinder Singh, Xiansong Huang, Guoli Song, Yonghong Tian, Jian Zhan, Jie Chen, Yaoqi Zhou
71
+ - **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased) - [MSA](https://doi.org/10.1101/2021.02.12.430858)
72
+ - **Original Repository**: [https://github.com/yikunpku/RNA-MSM](https://github.com/yikunpku/RNA-MSM)
73
+
74
+ ## Usage
75
+
76
+ The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:
77
+
78
+ ```bash
79
+ pip install multimolecule
80
+ ```
81
+
82
+ ### Direct Use
83
+
84
+ You can use this model directly with a pipeline for masked language modeling:
85
+
86
+ ```python
87
+ >>> import multimolecule # you must import multimolecule to register models
88
+ >>> from transformers import pipeline
89
+ >>> unmasker = pipeline('fill-mask', model='multimolecule/rnamsm')
90
+ >>> unmasker("uagc<mask>uaucagacugauguuga")
91
+
92
+ [{'score': 0.28535839915275574,
93
+ 'token': 9,
94
+ 'token_str': 'U',
95
+ 'sequence': 'U A G C U U A U C A G A C U G A U G U U G A'},
96
+ {'score': 0.2532415986061096,
97
+ 'token': 22,
98
+ 'token_str': 'K',
99
+ 'sequence': 'U A G C K U A U C A G A C U G A U G U U G A'},
100
+ {'score': 0.2247398942708969,
101
+ 'token': 8,
102
+ 'token_str': 'G',
103
+ 'sequence': 'U A G C G U A U C A G A C U G A U G U U G A'},
104
+ {'score': 0.06841657310724258,
105
+ 'token': 15,
106
+ 'token_str': 'D',
107
+ 'sequence': 'U A G C D U A U C A G A C U G A U G U U G A'},
108
+ {'score': 0.03774874284863472,
109
+ 'token': 19,
110
+ 'token_str': 'W',
111
+ 'sequence': 'U A G C W U A U C A G A C U G A U G U U G A'}]
112
+ ```
113
+
114
+ ### Downstream Use
115
+
116
+ #### Extract Features
117
+
118
+ Here is how to use this model to get the features of a given sequence in PyTorch:
119
+
120
+ ```python
121
+ from multimolecule import RnaTokenizer, RnaMsmModel
122
+
123
+
124
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnamsm')
125
+ model = RnaMsmModel.from_pretrained('multimolecule/rnamsm')
126
+
127
+ text = "UAGCUUAUCAGACUGAUGUUGA"
128
+ input = tokenizer(text, return_tensors='pt')
129
+
130
+ output = model(**input)
131
+ ```
132
+
133
+ #### Sequence Classification / Regression
134
+
135
+ **Note**: 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.
136
+
137
+ Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:
138
+
139
+ ```python
140
+ import torch
141
+ from multimolecule import RnaTokenizer, RnaMsmForSequencePrediction
142
+
143
+
144
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnamsm')
145
+ model = RnaMsmForSequencePrediction.from_pretrained('multimolecule/rnamsm')
146
+
147
+ text = "UAGCUUAUCAGACUGAUGUUGA"
148
+ input = tokenizer(text, return_tensors='pt')
149
+ label = torch.tensor([1])
150
+
151
+ output = model(**input, labels=label)
152
+ ```
153
+
154
+ #### Nucleotide Classification / Regression
155
+
156
+ **Note**: 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 nucleotide classification or regression.
157
+
158
+ Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:
159
+
160
+ ```python
161
+ import torch
162
+ from multimolecule import RnaTokenizer, RnaMsmForNucleotidePrediction
163
+
164
+
165
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnamsm')
166
+ model = RnaMsmForNucleotidPrediction.from_pretrained('multimolecule/rnamsm')
167
+
168
+ text = "UAGCUUAUCAGACUGAUGUUGA"
169
+ input = tokenizer(text, return_tensors='pt')
170
+ label = torch.randint(2, (len(text), ))
171
+
172
+ output = model(**input, labels=label)
173
+ ```
174
+
175
+ #### Contact Classification / Regression
176
+
177
+ **Note**: 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.
178
+
179
+ Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:
180
+
181
+ ```python
182
+ import torch
183
+ from multimolecule import RnaTokenizer, RnaMsmForContactPrediction
184
+
185
+
186
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnamsm')
187
+ model = RnaMsmForContactPrediction.from_pretrained('multimolecule/rnamsm')
188
+
189
+ text = "UAGCUUAUCAGACUGAUGUUGA"
190
+ input = tokenizer(text, return_tensors='pt')
191
+ label = torch.randint(2, (len(text), len(text)))
192
+
193
+ output = model(**input, labels=label)
194
+ ```
195
+
196
+ ## Training Details
197
+
198
+ RNA-MSM 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.
199
+
200
+ ### Training Data
201
+
202
+ The RNA-MSM model was pre-trained on [Rfam](https://rfam.org). Rfam database is a collection of RNA families, each represented by multiple sequence alignments, consensus secondary structures and covariance models. RNA-MSM used Rfam 14.7 which contains 4,069 RNA families.
203
+
204
+ To avoid potential overfitting in structural inference, RNA-MSM excluded families with experimentally determined structures, such as ribosomal RNAs, transfer RNAs, and small nuclear RNAs. The final dataset contains 3,932 RNA families. The median value for the number of MSA sequences for these families by RNAcmap3 is 2,184.
205
+
206
+ To increase the number of homologous sequences, RNA-MSM used an automatic pipeline, RNAcmap3, for homolog search and sequence alignment. RNAcmap3 is a pipeline that combines the BLAST-N, INFERNAL, Easel, RNAfold and evolutionary coupling tools to generate homologous sequences.
207
+
208
+ RNA-MSM preprocessed all tokens by replacing "T"s with "U"s and substituting "R", "Y", "K", "M", "S", "W", "B", "D", "H", "V", "N" with "X".
209
+
210
+ Note that [`RnaTokenizer`][multimolecule.RnaTokenizer] will convert "T"s to "U"s for you, you may disable this behaviour by passing `replace_T_with_U=False`. `RnaTokenizer` does not perform other substitutions.
211
+
212
+ ### Training Procedure
213
+
214
+ #### Preprocessing
215
+
216
+ RNA-MSM used masked language modeling (MLM) as the pre-training objective. The masking procedure is similar to the one used in BERT:
217
+
218
+ - 15% of the tokens are masked.
219
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
220
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
221
+ - In the 10% remaining cases, the masked tokens are left as is.
222
+
223
+ #### PreTraining
224
+
225
+ The model was trained on 8 NVIDIA V100 GPUs with 32GiB memories.
226
+
227
+ - Learning rate: 3e-4
228
+ - Weight decay: 3e-4
229
+ - Optimizer: Adam
230
+ - Learning rate warm-up: 16,000 steps
231
+ - Epochs: 300
232
+ - Batch Size: 1
233
+ - Dropout: 0.1
234
+
235
+ ## Citation
236
+
237
+ **BibTeX**:
238
+
239
+ ```bibtex
240
+ @article{zhang2023multiple,
241
+ author = {Zhang, Yikun and Lang, Mei and Jiang, Jiuhong and Gao, Zhiqiang and Xu, Fan and Litfin, Thomas and Chen, Ke and Singh, Jaswinder and Huang, Xiansong and Song, Guoli and Tian, Yonghong and Zhan, Jian and Chen, Jie and Zhou, Yaoqi},
242
+ title = "{Multiple sequence alignment-based RNA language model and its application to structural inference}",
243
+ journal = {Nucleic Acids Research},
244
+ volume = {52},
245
+ number = {1},
246
+ pages = {e3-e3},
247
+ year = {2023},
248
+ month = {11},
249
+ abstract = "{Compared with proteins, DNA and RNA are more difficult languages to interpret because four-letter coded DNA/RNA sequences have less information content than 20-letter coded protein sequences. While BERT (Bidirectional Encoder Representations from Transformers)-like language models have been developed for RNA, they are ineffective at capturing the evolutionary information from homologous sequences because unlike proteins, RNA sequences are less conserved. Here, we have developed an unsupervised multiple sequence alignment-based RNA language model (RNA-MSM) by utilizing homologous sequences from an automatic pipeline, RNAcmap, as it can provide significantly more homologous sequences than manually annotated Rfam. We demonstrate that the resulting unsupervised, two-dimensional attention maps and one-dimensional embeddings from RNA-MSM contain structural information. In fact, they can be directly mapped with high accuracy to 2D base pairing probabilities and 1D solvent accessibilities, respectively. Further fine-tuning led to significantly improved performance on these two downstream tasks compared with existing state-of-the-art techniques including SPOT-RNA2 and RNAsnap2. By comparison, RNA-FM, a BERT-based RNA language model, performs worse than one-hot encoding with its embedding in base pair and solvent-accessible surface area prediction. We anticipate that the pre-trained RNA-MSM model can be fine-tuned on many other tasks related to RNA structure and function.}",
250
+ issn = {0305-1048},
251
+ doi = {10.1093/nar/gkad1031},
252
+ url = {https://doi.org/10.1093/nar/gkad1031},
253
+ eprint = {https://academic.oup.com/nar/article-pdf/52/1/e3/55443207/gkad1031.pdf},
254
+ }
255
+ ```
256
+
257
+ ## Contact
258
+
259
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
260
+
261
+ Please contact the authors of the [RNA-MSM paper](https://doi.org/10.1093/nar/gkad1031) for questions or comments on the paper/model.
262
+
263
+ ## License
264
+
265
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
266
+
267
+ ```spdx
268
+ SPDX-License-Identifier: AGPL-3.0-or-later
269
+ ```
config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RnaMsmForPreTraining"
4
+ ],
5
+ "attention_bias": true,
6
+ "attention_dropout": 0.1,
7
+ "attention_type": "standard",
8
+ "bos_token_id": 1,
9
+ "embed_positions_msa": true,
10
+ "eos_token_id": 2,
11
+ "head": {
12
+ "act": null,
13
+ "bias": true,
14
+ "dropout": 0.0,
15
+ "hidden_size": null,
16
+ "layer_norm_eps": 1e-12,
17
+ "num_labels": null,
18
+ "output_name": null,
19
+ "problem_type": null,
20
+ "transform": null,
21
+ "transform_act": "gelu"
22
+ },
23
+ "hidden_act": "gelu",
24
+ "hidden_dropout": 0.1,
25
+ "hidden_size": 768,
26
+ "id2label": {
27
+ "0": "LABEL_0"
28
+ },
29
+ "initializer_range": 0.02,
30
+ "intermediate_size": 3072,
31
+ "label2id": {
32
+ "LABEL_0": 0
33
+ },
34
+ "layer_norm_eps": 1e-12,
35
+ "layer_type": "standard",
36
+ "lm_head": {
37
+ "act": null,
38
+ "bias": true,
39
+ "dropout": 0.0,
40
+ "hidden_size": 768,
41
+ "layer_norm_eps": 1e-12,
42
+ "output_name": null,
43
+ "transform": "nonlinear",
44
+ "transform_act": "gelu"
45
+ },
46
+ "mask_token_id": 4,
47
+ "max_position_embeddings": 1024,
48
+ "max_tokens_per_msa": 16384,
49
+ "model_type": "rnamsm",
50
+ "null_token_id": 5,
51
+ "num_attention_heads": 12,
52
+ "num_hidden_layers": 10,
53
+ "pad_token_id": 0,
54
+ "position_embedding_type": "absolute",
55
+ "torch_dtype": "float32",
56
+ "transformers_version": "4.41.2",
57
+ "unk_token_id": 3,
58
+ "use_cache": true,
59
+ "vocab_size": 26
60
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:177181212c0d6c43de10d0ca7f2c322ad5de55007fb9ba1a2f96ed315465dbf7
3
+ size 386173696
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13994affb8777940aaa12273ad9196761528edd971b4f22bc7c322be8870c93a
3
+ size 386233650
special_tokens_map.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "pad_token": {
3
+ "content": "<pad>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<cls>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "<eos>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "mask_token": {
31
+ "content": "<mask>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "null_token": {
38
+ "content": "<null>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ }
44
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "tokenizer_class": "RnaTokenizer",
3
+ "clean_up_tokenization_spaces": true,
4
+ "model_max_length": 1024
5
+ }