ZhiyuanChen commited on
Commit
834d27b
1 Parent(s): 0b52374

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: rna
3
+ tags:
4
+ - Biology
5
+ - RNA
6
+ license: agpl-3.0
7
+ datasets:
8
+ - multimolecule/rnacentral
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: "<null>"
17
+ score: 0.038491372019052505
18
+ - label: "."
19
+ score: 0.03848646208643913
20
+ - label: "<pad>"
21
+ score: 0.03846566751599312
22
+ - label: "U"
23
+ score: 0.03846472129225731
24
+ - label: "W"
25
+ score: 0.03846454620361328
26
+ ---
27
+
28
+ # RNABERT
29
+
30
+ Pre-trained model on non-coding RNA (ncRNA) using masked language modeling (MLM) and structural alignment learning (SAL) objectives.
31
+
32
+ ## Disclaimer
33
+
34
+ This is an UNOFFICIAL implementation of the [Informative RNA-base embedding for functional RNA clustering and structural alignment](https://doi.org/10.1093/nargab/lqac012) by Manato Akiyama and Yasubumi Sakakibara.
35
+
36
+ The OFFICIAL repository of RNABERT is at [mana438/RNABERT](https://github.com/mana438/RNABERT).
37
+
38
+ !!! Bug "Reproducibility"
39
+
40
+ The MultiMolecule team is aware of a potential risk in reproducing the results of RNABERT.
41
+
42
+ The original implementation of RNABERT does not prepend `<cls>` and append `<eos>` tokens to the input sequence.
43
+ This may lead to unexpected results when using the model.
44
+
45
+ !!! Success "Reproducibility"
46
+
47
+ The MultiMolecule team has confirmed that the provided model and checkpoints are producing the same intermediate representations as the original implementation.
48
+
49
+ **The team releasing RNABERT did not write this model card for this model so this model card has been written by the MultiMolecule team.**
50
+
51
+ ## Model Details
52
+
53
+ RNABERT 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.
54
+
55
+ ### Model Specification
56
+
57
+ | Num Layers | Hidden Size | Num Heads | Intermediate Size | Num Parameters (M) | FLOPs (G) | MACs (G) | Max Num Tokens |
58
+ | ---------- | ----------- | --------- | ----------------- | ------------------ | --------- | -------- | -------------- |
59
+ | 6 | 120 | 12 | 40 | 0.48 | 0.15 | 0.08 | 440 |
60
+
61
+ ### Links
62
+
63
+ - **Code**: [multimolecule.rnabert](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/rnabert)
64
+ - **Weights**: [multimolecule/rnabert](https://huggingface.co/multimolecule/rnabert)
65
+ - **Data**: [RNAcentral](https://rnacentral.org)
66
+ - **Paper**: [Informative RNA-base embedding for functional RNA clustering and structural alignment](https://doi.org/10.1093/nargab/lqac012)
67
+ - **Developed by**: JManato Akiyama and Yasubumi Sakakibara
68
+ - **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased)
69
+ - **Original Repository**: [https://github.com/mana438/RNABERT](https://github.com/mana438/RNABERT)
70
+
71
+ ## Usage
72
+
73
+ The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:
74
+
75
+ ```bash
76
+ pip install multimolecule
77
+ ```
78
+
79
+ ### Direct Use
80
+
81
+ You can use this model directly with a pipeline for masked language modeling:
82
+
83
+ ```python
84
+ >>> import multimolecule # you must import multimolecule to register models
85
+ >>> from transformers import pipeline
86
+ >>> unmasker = pipeline('fill-mask', model='multimolecule/rnabert')
87
+ >>> unmasker("uagc<mask>uaucagacugauguuga")
88
+
89
+ [{'score': 0.038491372019052505,
90
+ 'token': 5,
91
+ 'token_str': '<null>',
92
+ 'sequence': 'U A G C U A U C A G A C U G A U G U U G A'},
93
+ {'score': 0.03848646208643913,
94
+ 'token': 23,
95
+ 'token_str': '.',
96
+ 'sequence': 'U A G C. U A U C A G A C U G A U G U U G A'},
97
+ {'score': 0.03846566751599312,
98
+ 'token': 0,
99
+ 'token_str': '<pad>',
100
+ 'sequence': 'U A G C U A U C A G A C U G A U G U U G A'},
101
+ {'score': 0.03846472129225731,
102
+ 'token': 9,
103
+ 'token_str': 'U',
104
+ 'sequence': 'U A G C U U A U C A G A C U G A U G U U G A'},
105
+ {'score': 0.03846454620361328,
106
+ 'token': 19,
107
+ 'token_str': 'W',
108
+ 'sequence': 'U A G C W U A U C A G A C U G A U G U U G A'}]
109
+ ```
110
+
111
+ ### Downstream Use
112
+
113
+ #### Extract Features
114
+
115
+ Here is how to use this model to get the features of a given sequence in PyTorch:
116
+
117
+ ```python
118
+ from multimolecule import RnaTokenizer, RnaBertModel
119
+
120
+
121
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnabert')
122
+ model = RnaBertModel.from_pretrained('multimolecule/rnabert')
123
+
124
+ text = "UAGCUUAUCAGACUGAUGUUGA"
125
+ input = tokenizer(text, return_tensors='pt')
126
+
127
+ output = model(**input)
128
+ ```
129
+
130
+ #### Sequence Classification / Regression
131
+
132
+ **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.
133
+
134
+ Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:
135
+
136
+ ```python
137
+ import torch
138
+ from multimolecule import RnaTokenizer, RnaBertForSequencePrediction
139
+
140
+
141
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnabert')
142
+ model = RnaBertForSequencePrediction.from_pretrained('multimolecule/rnabert')
143
+
144
+ text = "UAGCUUAUCAGACUGAUGUUGA"
145
+ input = tokenizer(text, return_tensors='pt')
146
+ label = torch.tensor([1])
147
+
148
+ output = model(**input, labels=label)
149
+ ```
150
+
151
+ #### Nucleotide Classification / Regression
152
+
153
+ **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.
154
+
155
+ Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:
156
+
157
+ ```python
158
+ import torch
159
+ from multimolecule import RnaTokenizer, RnaBertForNucleotidePrediction
160
+
161
+
162
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnabert')
163
+ model = RnaBertForNucleotidePrediction.from_pretrained('multimolecule/rnabert')
164
+
165
+ text = "UAGCUUAUCAGACUGAUGUUGA"
166
+ input = tokenizer(text, return_tensors='pt')
167
+ label = torch.randint(2, (len(text), ))
168
+
169
+ output = model(**input, labels=label)
170
+ ```
171
+
172
+ #### Contact Classification / Regression
173
+
174
+ **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.
175
+
176
+ Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:
177
+
178
+ ```python
179
+ import torch
180
+ from multimolecule import RnaTokenizer, RnaBertForContactPrediction
181
+
182
+
183
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/rnabert')
184
+ model = RnaBertForContactPrediction.from_pretrained('multimolecule/rnabert')
185
+
186
+ text = "UAGCUUAUCAGACUGAUGUUGA"
187
+ input = tokenizer(text, return_tensors='pt')
188
+ label = torch.randint(2, (len(text), len(text)))
189
+
190
+ output = model(**input, labels=label)
191
+ ```
192
+
193
+ ## Training Details
194
+
195
+ RNABERT has two pre-training objectives: masked language modeling (MLM) and structural alignment learning (SAL).
196
+
197
+ - **Masked Language Modeling (MLM)**: 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.
198
+ - **Structural Alignment Learning (SAL)**: the model learns to predict the structural alignment of two RNA sequences. The model is trained to predict the alignment score of two RNA sequences using the Needleman-Wunsch algorithm.
199
+
200
+ ### Training Data
201
+
202
+ The RNABERT model was pre-trained on [RNAcentral](https://rnacentral.org). RNAcentral is a comprehensive database of non-coding RNA sequences from a wide range of species. It combines 47 different databases, adding up to around 27 million RNA sequences in total. RNABERT used a subset of 76, 237 human ncRNA sequences from RNAcentral for pre-training.
203
+
204
+ RNABERT preprocessed all tokens by replacing "U"s with "T"s.
205
+
206
+ Note that during model conversions, "T" is replaced with "U". [`RnaTokenizer`][multimolecule.RnaTokenizer] will convert "T"s to "U"s for you, you may disable this behaviour by passing `replace_T_with_U=False`.
207
+
208
+ ### Training Procedure
209
+
210
+ #### Preprocessing
211
+
212
+ RNABERT preprocess the dataset by applying 10 different mask patterns to the 72, 237 human ncRNA sequences. The final dataset contains 722, 370 sequences. The masking procedure is similar to the one used in BERT:
213
+
214
+ - 15% of the tokens are masked.
215
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
216
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
217
+ - In the 10% remaining cases, the masked tokens are left as is.
218
+
219
+ #### PreTraining
220
+
221
+ The model was trained on 1 NVIDIA V100 GPU.
222
+
223
+ ## Citation
224
+
225
+ **BibTeX**:
226
+
227
+ ```bibtex
228
+ @article{akiyama2022informative,
229
+ author = {Akiyama, Manato and Sakakibara, Yasubumi},
230
+ title = "{Informative RNA base embedding for RNA structural alignment and clustering by deep representation learning}",
231
+ journal = {NAR Genomics and Bioinformatics},
232
+ volume = {4},
233
+ number = {1},
234
+ pages = {lqac012},
235
+ year = {2022},
236
+ month = {02},
237
+ abstract = "{Effective embedding is actively conducted by applying deep learning to biomolecular information. Obtaining better embeddings enhances the quality of downstream analyses, such as DNA sequence motif detection and protein function prediction. In this study, we adopt a pre-training algorithm for the effective embedding of RNA bases to acquire semantically rich representations and apply this algorithm to two fundamental RNA sequence problems: structural alignment and clustering. By using the pre-training algorithm to embed the four bases of RNA in a position-dependent manner using a large number of RNA sequences from various RNA families, a context-sensitive embedding representation is obtained. As a result, not only base information but also secondary structure and context information of RNA sequences are embedded for each base. We call this ‘informative base embedding’ and use it to achieve accuracies superior to those of existing state-of-the-art methods on RNA structural alignment and RNA family clustering tasks. Furthermore, upon performing RNA sequence alignment by combining this informative base embedding with a simple Needleman–Wunsch alignment algorithm, we succeed in calculating structural alignments with a time complexity of O(n2) instead of the O(n6) time complexity of the naive implementation of Sankoff-style algorithm for input RNA sequence of length n.}",
238
+ issn = {2631-9268},
239
+ doi = {10.1093/nargab/lqac012},
240
+ url = {https://doi.org/10.1093/nargab/lqac012},
241
+ eprint = {https://academic.oup.com/nargab/article-pdf/4/1/lqac012/42577168/lqac012.pdf},
242
+ }
243
+ ```
244
+
245
+ ## Contact
246
+
247
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
248
+
249
+ Please contact the authors of the [RNABERT paper](https://doi.org/10.1093/nargab/lqac012) for questions or comments on the paper/model.
250
+
251
+ ## License
252
+
253
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
254
+
255
+ ```spdx
256
+ SPDX-License-Identifier: AGPL-3.0-or-later
257
+ ```
config.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RnaBertForPreTraining"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 1,
7
+ "eos_token_id": 2,
8
+ "head": {
9
+ "act": null,
10
+ "bias": true,
11
+ "dropout": 0.0,
12
+ "hidden_size": 120,
13
+ "layer_norm_eps": 1e-12,
14
+ "num_labels": 2,
15
+ "output_name": null,
16
+ "problem_type": null,
17
+ "transform": null,
18
+ "transform_act": "gelu"
19
+ },
20
+ "hidden_act": "gelu",
21
+ "hidden_dropout": 0.0,
22
+ "hidden_size": 120,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 40,
25
+ "layer_norm_eps": 1e-12,
26
+ "lm_head": {
27
+ "act": null,
28
+ "bias": true,
29
+ "dropout": 0.0,
30
+ "hidden_size": 120,
31
+ "layer_norm_eps": 1e-12,
32
+ "output_name": null,
33
+ "transform": "nonlinear",
34
+ "transform_act": "gelu"
35
+ },
36
+ "mask_token_id": 4,
37
+ "max_position_embeddings": 440,
38
+ "model_type": "rnabert",
39
+ "null_token_id": 5,
40
+ "num_attention_heads": 12,
41
+ "num_hidden_layers": 6,
42
+ "pad_token_id": 0,
43
+ "position_embedding_type": "absolute",
44
+ "ss_vocab_size": 8,
45
+ "torch_dtype": "float32",
46
+ "transformers_version": "4.41.2",
47
+ "type_vocab_size": 2,
48
+ "unk_token_id": 3,
49
+ "use_cache": true,
50
+ "vocab_size": 26
51
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51814cd6d30ba8cb198d64cfb369e1566953cdb123900926147bcc36826897e3
3
+ size 2144376
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7473e7b3cbf3a61a4d6c737d441d02060a3b01136bf88d0759c5ea2cf7760192
3
+ size 2168502
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": 440
5
+ }