ZhiyuanChen commited on
Commit
2048550
1 Parent(s): 739c055

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: "N"
17
+ score: 0.0385337695479393
18
+ - label: "I"
19
+ score: 0.03851701319217682
20
+ - label: "<unk>"
21
+ score: 0.03850541263818741
22
+ - label: "<null>"
23
+ score: 0.03850402310490608
24
+ - label: "<cls>"
25
+ score: 0.03848475590348244
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
+ > [!CAUTION]
39
+ > The MultiMolecule team is aware of a potential risk in reproducing the results of RNABERT.
40
+ >
41
+ > The original implementation of RNABERT does not prepend `<cls>` and append `<eos>` tokens to the input sequence.
42
+ > This should not affect the performance of the model in most cases, but it can lead to unexpected behavior in some cases.
43
+ >
44
+ > Please set `cls_token=None` and `eos_token=None` explicitly in the tokenizer if you want the exact behavior of the original implementation.
45
+
46
+ > [!TIP]
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.0385337695479393,
90
+ 'token': 10,
91
+ 'token_str': 'N',
92
+ 'sequence': 'U A G C N U A U C A G A C U G A U G U U G A'},
93
+ {'score': 0.03851701319217682,
94
+ 'token': 25,
95
+ 'token_str': 'I',
96
+ 'sequence': 'U A G C I U A U C A G A C U G A U G U U G A'},
97
+ {'score': 0.03850541263818741,
98
+ 'token': 3,
99
+ 'token_str': '<unk>',
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.03850402310490608,
102
+ 'token': 5,
103
+ 'token_str': '<null>',
104
+ 'sequence': 'U A G C U A U C A G A C U G A U G U U G A'},
105
+ {'score': 0.03848475590348244,
106
+ 'token': 1,
107
+ 'token_str': '<cls>',
108
+ 'sequence': 'U A G C 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://multimolecule.danling.org/datasets/rnacentral/).
203
+ RNAcentral is a free, public resource that offers integrated access to a comprehensive and up-to-date set of non-coding RNA sequences provided by a collaborating group of [Expert Databases](https://rnacentral.org/expert-databases) representing a broad range of organisms and RNA types.
204
+
205
+ RNABERT used a subset of 76, 237 human ncRNA sequences from RNAcentral for pre-training.
206
+ RNABERT preprocessed all tokens by replacing "U"s with "T"s.
207
+
208
+ 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`.
209
+
210
+ ### Training Procedure
211
+
212
+ #### Preprocessing
213
+
214
+ 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:
215
+
216
+ - 15% of the tokens are masked.
217
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
218
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
219
+ - In the 10% remaining cases, the masked tokens are left as is.
220
+
221
+ #### PreTraining
222
+
223
+ The model was trained on 1 NVIDIA V100 GPU.
224
+
225
+ ## Citation
226
+
227
+ **BibTeX**:
228
+
229
+ ```bibtex
230
+ @article{akiyama2022informative,
231
+ author = {Akiyama, Manato and Sakakibara, Yasubumi},
232
+ title = "{Informative RNA base embedding for RNA structural alignment and clustering by deep representation learning}",
233
+ journal = {NAR Genomics and Bioinformatics},
234
+ volume = {4},
235
+ number = {1},
236
+ pages = {lqac012},
237
+ year = {2022},
238
+ month = {02},
239
+ 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.}",
240
+ issn = {2631-9268},
241
+ doi = {10.1093/nargab/lqac012},
242
+ url = {https://doi.org/10.1093/nargab/lqac012},
243
+ eprint = {https://academic.oup.com/nargab/article-pdf/4/1/lqac012/42577168/lqac012.pdf},
244
+ }
245
+ ```
246
+
247
+ ## Contact
248
+
249
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
250
+
251
+ Please contact the authors of the [RNABERT paper](https://doi.org/10.1093/nargab/lqac012) for questions or comments on the paper/model.
252
+
253
+ ## License
254
+
255
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
256
+
257
+ ```spdx
258
+ SPDX-License-Identifier: AGPL-3.0-or-later
259
+ ```
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.44.0",
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:e8390e491267818f7b483d669d8c3727db5c3e985f6a48da5f11ff4697744eca
3
+ size 2144376
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:36ba8a7d9613a40807e43e6cb2e4b89cec0d6ca09051d825ff6084bb848067ab
3
+ size 2168502
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,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "mask_token": "<mask>",
61
+ "model_max_length": 440,
62
+ "nmers": 1,
63
+ "pad_token": "<pad>",
64
+ "replace_T_with_U": true,
65
+ "sep_token": "<eos>",
66
+ "tokenizer_class": "RnaTokenizer",
67
+ "unk_token": "<unk>"
68
+ }
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