ZhiyuanChen commited on
Commit
7a9b5d5
·
verified ·
1 Parent(s): c571c7a

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: "HIV-1"
14
+ text: "GGUC<mask>CUCUGGUUAGACCAGAUCUGAGCCU"
15
+ output:
16
+ - label: "-"
17
+ score: 0.03852083534002304
18
+ - label: "N"
19
+ score: 0.03851056098937988
20
+ - label: "I"
21
+ score: 0.03849703073501587
22
+ - label: "<unk>"
23
+ score: 0.03848597779870033
24
+ - label: "<null>"
25
+ score: 0.038484156131744385
26
+ - example_title: "microRNA-21"
27
+ text: "UAGC<mask>UAUCAGACUGAUGUUG"
28
+ output:
29
+ - label: "N"
30
+ score: 0.03855736553668976
31
+ - label: "I"
32
+ score: 0.03851182386279106
33
+ - label: "<unk>"
34
+ score: 0.038497816771268845
35
+ - label: "<null>"
36
+ score: 0.03848177567124367
37
+ - label: "-"
38
+ score: 0.038468137383461
39
+ ---
40
+
41
+ # RNABERT
42
+
43
+ Pre-trained model on non-coding RNA (ncRNA) using masked language modeling (MLM) and structural alignment learning (SAL) objectives.
44
+
45
+ ## Disclaimer
46
+
47
+ 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.
48
+
49
+ The OFFICIAL repository of RNABERT is at [mana438/RNABERT](https://github.com/mana438/RNABERT).
50
+
51
+ > [!CAUTION]
52
+ > The MultiMolecule team is aware of a potential risk in reproducing the results of RNABERT.
53
+ >
54
+ > The original implementation of RNABERT does not prepend `<bos>` (`<cls>`) and append `<eos>` tokens to the input sequence.
55
+ > This should not affect the performance of the model in most cases, but it can lead to unexpected behavior in some cases.
56
+ >
57
+ > Please set `bos_token=None, eos_token=None` in the tokenizer and set `bos_token_id=None, eos_token_id=None` in the model configuration if you want the exact behavior of the original implementation.
58
+
59
+ > [!TIP]
60
+ > The MultiMolecule team has confirmed that the provided model and checkpoints are producing the same intermediate representations as the original implementation.
61
+
62
+ **The team releasing RNABERT did not write this model card for this model so this model card has been written by the MultiMolecule team.**
63
+
64
+ ## Model Details
65
+
66
+ 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.
67
+
68
+ ### Model Specification
69
+
70
+ | Num Layers | Hidden Size | Num Heads | Intermediate Size | Num Parameters (M) | FLOPs (G) | MACs (G) | Max Num Tokens |
71
+ | ---------- | ----------- | --------- | ----------------- | ------------------ | --------- | -------- | -------------- |
72
+ | 6 | 120 | 12 | 40 | 0.48 | 0.15 | 0.08 | 440 |
73
+
74
+ ### Links
75
+
76
+ - **Code**: [multimolecule.rnabert](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/rnabert)
77
+ - **Weights**: [multimolecule/rnabert](https://huggingface.co/multimolecule/rnabert)
78
+ - **Data**: [multimolecule/rnacentral](https://huggingface.co/datasets/multimolecule/rnacentral)
79
+ - **Paper**: [Informative RNA-base embedding for functional RNA clustering and structural alignment](https://doi.org/10.1093/nargab/lqac012)
80
+ - **Developed by**: JManato Akiyama and Yasubumi Sakakibara
81
+ - **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased)
82
+ - **Original Repository**: [mana438/RNABERT](https://github.com/mana438/RNABERT)
83
+
84
+ ## Usage
85
+
86
+ The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:
87
+
88
+ ```bash
89
+ pip install multimolecule
90
+ ```
91
+
92
+ ### Direct Use
93
+
94
+ You can use this model directly with a pipeline for masked language modeling:
95
+
96
+ ```python
97
+ >>> import multimolecule # you must import multimolecule to register models
98
+ >>> from transformers import pipeline
99
+
100
+ >>> unmasker = pipeline("fill-mask", model="multimolecule/rnabert")
101
+ >>> unmasker("gguc<mask>cucugguuagaccagaucugagccu")
102
+ [{'score': 0.03852083534002304,
103
+ 'token': 24,
104
+ 'token_str': '-',
105
+ 'sequence': 'G G U 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'},
106
+ {'score': 0.03851056098937988,
107
+ 'token': 10,
108
+ 'token_str': 'N',
109
+ 'sequence': 'G G U C N 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'},
110
+ {'score': 0.03849703073501587,
111
+ 'token': 25,
112
+ 'token_str': 'I',
113
+ 'sequence': 'G G U C I 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'},
114
+ {'score': 0.03848597779870033,
115
+ 'token': 3,
116
+ 'token_str': '<unk>',
117
+ 'sequence': 'G G U 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'},
118
+ {'score': 0.038484156131744385,
119
+ 'token': 5,
120
+ 'token_str': '<null>',
121
+ 'sequence': 'G G U 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'}]
122
+ ```
123
+
124
+ ### Downstream Use
125
+
126
+ #### Extract Features
127
+
128
+ Here is how to use this model to get the features of a given sequence in PyTorch:
129
+
130
+ ```python
131
+ from multimolecule import RnaTokenizer, RnaBertModel
132
+
133
+
134
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/rnabert")
135
+ model = RnaBertModel.from_pretrained("multimolecule/rnabert")
136
+
137
+ text = "UAGCUUAUCAGACUGAUGUUG"
138
+ input = tokenizer(text, return_tensors="pt")
139
+
140
+ output = model(**input)
141
+ ```
142
+
143
+ #### Sequence Classification / Regression
144
+
145
+ > [!NOTE]
146
+ > 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.
147
+
148
+ Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:
149
+
150
+ ```python
151
+ import torch
152
+ from multimolecule import RnaTokenizer, RnaBertForSequencePrediction
153
+
154
+
155
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/rnabert")
156
+ model = RnaBertForSequencePrediction.from_pretrained("multimolecule/rnabert")
157
+
158
+ text = "UAGCUUAUCAGACUGAUGUUG"
159
+ input = tokenizer(text, return_tensors="pt")
160
+ label = torch.tensor([1])
161
+
162
+ output = model(**input, labels=label)
163
+ ```
164
+
165
+ #### Token Classification / Regression
166
+
167
+ > [!NOTE]
168
+ > 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.
169
+
170
+ Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:
171
+
172
+ ```python
173
+ import torch
174
+ from multimolecule import RnaTokenizer, RnaBertForTokenPrediction
175
+
176
+
177
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/rnabert")
178
+ model = RnaBertForTokenPrediction.from_pretrained("multimolecule/rnabert")
179
+
180
+ text = "UAGCUUAUCAGACUGAUGUUG"
181
+ input = tokenizer(text, return_tensors="pt")
182
+ label = torch.randint(2, (len(text), ))
183
+
184
+ output = model(**input, labels=label)
185
+ ```
186
+
187
+ #### Contact Classification / Regression
188
+
189
+ > [!NOTE]
190
+ > 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.
191
+
192
+ Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:
193
+
194
+ ```python
195
+ import torch
196
+ from multimolecule import RnaTokenizer, RnaBertForContactPrediction
197
+
198
+
199
+ tokenizer = RnaTokenizer.from_pretrained("multimolecule/rnabert")
200
+ model = RnaBertForContactPrediction.from_pretrained("multimolecule/rnabert")
201
+
202
+ text = "UAGCUUAUCAGACUGAUGUUG"
203
+ input = tokenizer(text, return_tensors="pt")
204
+ label = torch.randint(2, (len(text), len(text)))
205
+
206
+ output = model(**input, labels=label)
207
+ ```
208
+
209
+ ## Training Details
210
+
211
+ RNABERT has two pre-training objectives: masked language modeling (MLM) and structural alignment learning (SAL).
212
+
213
+ - **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.
214
+ - **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.
215
+
216
+ ### Training Data
217
+
218
+ The RNABERT model was pre-trained on [RNAcentral](https://multimolecule.danling.org/datasets/rnacentral).
219
+ 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.
220
+
221
+ RNABERT used a subset of 76, 237 human ncRNA sequences from RNAcentral for pre-training.
222
+ RNABERT preprocessed all tokens by replacing "U"s with "T"s.
223
+
224
+ 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`.
225
+
226
+ ### Training Procedure
227
+
228
+ #### Preprocessing
229
+
230
+ 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:
231
+
232
+ - 15% of the tokens are masked.
233
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
234
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
235
+ - In the 10% remaining cases, the masked tokens are left as is.
236
+
237
+ #### Pre-training
238
+
239
+ The model was trained on 1 NVIDIA V100 GPU.
240
+
241
+ ## Citation
242
+
243
+ **BibTeX**:
244
+
245
+ ```bibtex
246
+ @article{akiyama2022informative,
247
+ author = {Akiyama, Manato and Sakakibara, Yasubumi},
248
+ title = "{Informative RNA base embedding for RNA structural alignment and clustering by deep representation learning}",
249
+ journal = {NAR Genomics and Bioinformatics},
250
+ volume = {4},
251
+ number = {1},
252
+ pages = {lqac012},
253
+ year = {2022},
254
+ month = {02},
255
+ 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.}",
256
+ issn = {2631-9268},
257
+ doi = {10.1093/nargab/lqac012},
258
+ url = {https://doi.org/10.1093/nargab/lqac012},
259
+ eprint = {https://academic.oup.com/nargab/article-pdf/4/1/lqac012/42577168/lqac012.pdf},
260
+ }
261
+ ```
262
+
263
+ ## Contact
264
+
265
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
266
+
267
+ Please contact the authors of the [RNABERT paper](https://doi.org/10.1093/nargab/lqac012) for questions or comments on the paper/model.
268
+
269
+ ## License
270
+
271
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
272
+
273
+ ```spdx
274
+ SPDX-License-Identifier: AGPL-3.0-or-later
275
+ ```
config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RnaBertForPreTraining"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 1,
7
+ "eos_token_id": 2,
8
+ "head": null,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout": 0.0,
11
+ "hidden_size": 120,
12
+ "id2label": null,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 40,
15
+ "label2id": null,
16
+ "layer_norm_eps": 1e-12,
17
+ "lm_head": null,
18
+ "mask_token_id": 4,
19
+ "max_position_embeddings": 440,
20
+ "model_type": "rnabert",
21
+ "null_token_id": 5,
22
+ "num_attention_heads": 12,
23
+ "num_hidden_layers": 6,
24
+ "num_labels": 1,
25
+ "pad_token_id": 0,
26
+ "position_embedding_type": "absolute",
27
+ "ss_vocab_size": 8,
28
+ "torch_dtype": "float32",
29
+ "transformers_version": "4.50.0",
30
+ "type_vocab_size": 2,
31
+ "unk_token_id": 3,
32
+ "use_cache": true,
33
+ "vocab_size": 26
34
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0619ebdf92a652b38d89973e1f42c03f057a3b05498b7128146e979934e726f
3
+ size 2072000
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5341a0ba996f4604f9528cd966e70684348b1e5ab2e25f0c6897114ab820d3ab
3
+ size 2094878
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": 440,
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