ZhiyuanChen commited on
Commit
dfceb13
1 Parent(s): 05d47be

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ---
11
+
12
+ # ERNIE-RNA
13
+
14
+ Pre-trained model on non-coding RNA (ncRNA) using a masked language modeling (MLM) objective.
15
+
16
+ ## Disclaimer
17
+
18
+ This is an UNOFFICIAL implementation of the [ERNIE-RNA: An RNA Language Model with Structure-enhanced Representations](https://doi.org/10.1101/2024.03.17.585376) by Weijie Yin, Zhaoyu Zhang, Liang He, et al.
19
+
20
+ The OFFICIAL repository of ERNIE-RNA is at [Bruce-ywj/ERNIE-RNA](https://github.com/Bruce-ywj/ERNIE-RNA).
21
+
22
+ **The team releasing ERNIE-RNA did not write this model card for this model so this model card has been written by the MultiMolecule team.**
23
+
24
+ ## Model Details
25
+
26
+ ERNIE-RNA 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.
27
+
28
+ ### Variations
29
+
30
+ - **[`multimolecule/ernierna`](https://huggingface.co/multimolecule/ernierna)**: The ERNIE-RNA model pre-trained on non-coding RNA sequences.
31
+ - **[`multimolecule/ernierna.ss`](https://huggingface.co/multimolecule/ernierna.ss)**: The ERNIE-RNA model fine-tuned on RNA secondary structure prediction.
32
+
33
+ ### Model Specification
34
+
35
+ | Num Layers | Hidden Size | Num Heads | Intermediate Size | Num Parameters (M) | FLOPs (G) | MACs (G) | Max Num Tokens |
36
+ | ---------- | ----------- | --------- | ----------------- | ------------------ | --------- | -------- | -------------- |
37
+ | 12 | 768 | 12 | 3072 | 85.67 | 22.36 | 11.17 | 1024 |
38
+
39
+ ### Links
40
+
41
+ - **Code**: [multimolecule.ernierna](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/ernierna)
42
+ - **Data**: [RNAcentral](https://rnacentral.org)
43
+ - **Paper**: [ERNIE-RNA: An RNA Language Model with Structure-enhanced Representations](https://doi.org/10.1101/2024.03.17.585376)
44
+ - **Developed by**: Weijie Yin, Zhaoyu Zhang, Liang He, Rui Jiang, Shuo Zhang, Gan Liu, Xuegong Zhang, Tao Qin, Zhen Xie
45
+ - **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased) - [ERNIE](https://huggingface.co/nghuyong/ernie-3.0-base-zh)
46
+ - **Original Repository**: [https://github.com/Bruce-ywj/ERNIE-RNA](https://github.com/Bruce-ywj/ERNIE-RNA)
47
+
48
+ ## Usage
49
+
50
+ The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:
51
+
52
+ ```bash
53
+ pip install multimolecule
54
+ ```
55
+
56
+ ### Direct Use
57
+
58
+ You can use this model directly with a pipeline for masked language modeling:
59
+
60
+ ```python
61
+ >>> import multimolecule # you must import multimolecule to register models
62
+ >>> from transformers import pipeline
63
+ >>> unmasker = pipeline('fill-mask', model='multimolecule/ernierna')
64
+ >>> unmasker("uagc<mask>uaucagacugauguuga")
65
+
66
+ [{'score': 0.47122013568878174,
67
+ 'token': 8,
68
+ 'token_str': 'G',
69
+ 'sequence': 'U A G C G U A U C A G A C U G A U G U U G A'},
70
+ {'score': 0.45008403062820435,
71
+ 'token': 6,
72
+ 'token_str': 'A',
73
+ 'sequence': 'U A G C A U A U C A G A C U G A U G U U G A'},
74
+ {'score': 0.03330205753445625,
75
+ 'token': 24,
76
+ 'token_str': '*',
77
+ 'sequence': 'U A G C * U A U C A G A C U G A U G U U G A'},
78
+ {'score': 0.025803660973906517,
79
+ 'token': 25,
80
+ 'token_str': '-',
81
+ 'sequence': 'U A G C - U A U C A G A C U G A U G U U G A'},
82
+ {'score': 0.018313394859433174,
83
+ 'token': 23,
84
+ 'token_str': '.',
85
+ 'sequence': 'U A G C. U A U C A G A C U G A U G U U G A'}]
86
+ ```
87
+
88
+ ### Downstream Use
89
+
90
+ #### Extract Features
91
+
92
+ Here is how to use this model to get the features of a given sequence in PyTorch:
93
+
94
+ ```python
95
+ from multimolecule import RnaTokenizer, ErnieRnaModel
96
+
97
+
98
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/ernierna')
99
+ model = ErnieRnaModel.from_pretrained('multimolecule/ernierna')
100
+
101
+ text = "UAGCUUAUCAGACUGAUGUUGA"
102
+ input = tokenizer(text, return_tensors='pt')
103
+
104
+ output = model(**input)
105
+ ```
106
+
107
+ #### Sequence Classification / Regression
108
+
109
+ **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.
110
+
111
+ Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:
112
+
113
+ ```python
114
+ import torch
115
+ from multimolecule import RnaTokenizer, ErnieRnaForSequencePrediction
116
+
117
+
118
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/ernierna')
119
+ model = ErnieRnaForSequencePrediction.from_pretrained('multimolecule/ernierna')
120
+
121
+ text = "UAGCUUAUCAGACUGAUGUUGA"
122
+ input = tokenizer(text, return_tensors='pt')
123
+ label = torch.tensor([1])
124
+
125
+ output = model(**input, labels=label)
126
+ ```
127
+
128
+ #### Nucleotide Classification / Regression
129
+
130
+ **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.
131
+
132
+ Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:
133
+
134
+ ```python
135
+ import torch
136
+ from multimolecule import RnaTokenizer, ErnieRnaForNucleotidePrediction
137
+
138
+
139
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/ernierna')
140
+ model = ErnieRnaForNucleotidePrediction.from_pretrained('multimolecule/ernierna')
141
+
142
+ text = "UAGCUUAUCAGACUGAUGUUGA"
143
+ input = tokenizer(text, return_tensors='pt')
144
+ label = torch.randint(2, (len(text), ))
145
+
146
+ output = model(**input, labels=label)
147
+ ```
148
+
149
+ #### Contact Classification / Regression
150
+
151
+ **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.
152
+
153
+ Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:
154
+
155
+ ```python
156
+ import torch
157
+ from multimolecule import RnaTokenizer, ErnieRnaForContactPrediction
158
+
159
+
160
+ tokenizer = RnaTokenizer.from_pretrained('multimolecule/ernierna')
161
+ model = ErnieRnaForContactPrediction.from_pretrained('multimolecule/ernierna')
162
+
163
+ text = "UAGCUUAUCAGACUGAUGUUGA"
164
+ input = tokenizer(text, return_tensors='pt')
165
+ label = torch.randint(2, (len(text), len(text)))
166
+
167
+ output = model(**input, labels=label)
168
+ ```
169
+
170
+ ## Training Details
171
+
172
+ ERNIE-RNA 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.
173
+
174
+ ### Training Data
175
+
176
+ The ERNIE-RNA 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 34 million RNA sequences in total.
177
+
178
+ ERNIE-RNA applied [CD-HIT (CD-HIT-EST)](https://sites.google.com/view/cd-hit) with a cut-off at 100% sequence identity to remove redundancy from the RNAcentral, resulting 25 million unique sequences. Sequences longer than 1024 nucleotides were subsequently excluded. The final dataset contains 20.4 million non-redundant RNA sequences.
179
+ ERNIE-RNA preprocessed all tokens by replacing "T"s with "S"s.
180
+
181
+ 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`.
182
+
183
+ ### Training Procedure
184
+
185
+ #### Preprocessing
186
+
187
+ ERNIE-RNA used masked language modeling (MLM) as the pre-training objective. The masking procedure is similar to the one used in BERT:
188
+
189
+ - 15% of the tokens are masked.
190
+ - In 80% of the cases, the masked tokens are replaced by `<mask>`.
191
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
192
+ - In the 10% remaining cases, the masked tokens are left as is.
193
+
194
+ #### PreTraining
195
+
196
+ The model was trained on 24 NVIDIA V100 GPUs with 32GiB memories.
197
+
198
+ - Learning rate: 1e-4
199
+ - Weight decay: 0.01
200
+ - Learning rate warm-up: 20,000 steps
201
+
202
+ ## Citation
203
+
204
+ **BibTeX**:
205
+
206
+ ```bibtex
207
+ @article {Yin2024.03.17.585376,
208
+ author = {Yin, Weijie and Zhang, Zhaoyu and He, Liang and Jiang, Rui and Zhang, Shuo and Liu, Gan and Zhang, Xuegong and Qin, Tao and Xie, Zhen},
209
+ title = {ERNIE-RNA: An RNA Language Model with Structure-enhanced Representations},
210
+ elocation-id = {2024.03.17.585376},
211
+ year = {2024},
212
+ doi = {10.1101/2024.03.17.585376},
213
+ publisher = {Cold Spring Harbor Laboratory},
214
+ abstract = {With large amounts of unlabeled RNA sequences data produced by high-throughput sequencing technologies, pre-trained RNA language models have been developed to estimate semantic space of RNA molecules, which facilities the understanding of grammar of RNA language. However, existing RNA language models overlook the impact of structure when modeling the RNA semantic space, resulting in incomplete feature extraction and suboptimal performance across various downstream tasks. In this study, we developed a RNA pre-trained language model named ERNIE-RNA (Enhanced Representations with base-pairing restriction for RNA modeling) based on a modified BERT (Bidirectional Encoder Representations from Transformers) by incorporating base-pairing restriction with no MSA (Multiple Sequence Alignment) information. We found that the attention maps from ERNIE-RNA with no fine-tuning are able to capture RNA structure in the zero-shot experiment more precisely than conventional methods such as fine-tuned RNAfold and RNAstructure, suggesting that the ERNIE-RNA can provide comprehensive RNA structural representations. Furthermore, ERNIE-RNA achieved SOTA (state-of-the-art) performance after fine-tuning for various downstream tasks, including RNA structural and functional predictions. In summary, our ERNIE-RNA model provides general features which can be widely and effectively applied in various subsequent research tasks. Our results indicate that introducing key knowledge-based prior information in the BERT framework may be a useful strategy to enhance the performance of other language models.Competing Interest StatementOne patent based on the study was submitted by Z.X. and W.Y., which is entitled as "A Pre-training Approach for RNA Sequences and Its Applications"(application number, no 202410262527.5). The remaining authors declare no competing interests.},
215
+ URL = {https://www.biorxiv.org/content/early/2024/03/17/2024.03.17.585376},
216
+ eprint = {https://www.biorxiv.org/content/early/2024/03/17/2024.03.17.585376.full.pdf},
217
+ journal = {bioRxiv}
218
+ }
219
+ ```
220
+
221
+ ## Contact
222
+
223
+ Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.
224
+
225
+ Please contact the authors of the [ERNIE-RNA paper](https://doi.org/10.1101/2024.03.17.585376) for questions or comments on the paper/model.
226
+
227
+ ## License
228
+
229
+ This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).
230
+
231
+ ```spdx
232
+ SPDX-License-Identifier: AGPL-3.0-or-later
233
+ ```
config.json ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ErnieRnaForContactClassification"
4
+ ],
5
+ "attention_dropout": 0.1,
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": null,
13
+ "layer_norm_eps": 1e-12,
14
+ "num_labels": null,
15
+ "problem_type": null,
16
+ "transform": null,
17
+ "transform_act": "gelu"
18
+ },
19
+ "hidden_act": "gelu",
20
+ "hidden_dropout": 0.1,
21
+ "hidden_size": 768,
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 3072,
24
+ "layer_norm_eps": 1e-12,
25
+ "lm_head": {
26
+ "act": null,
27
+ "bias": true,
28
+ "dropout": 0.0,
29
+ "hidden_size": 768,
30
+ "layer_norm_eps": 1e-12,
31
+ "transform": "nonlinear",
32
+ "transform_act": "gelu"
33
+ },
34
+ "mask_token_id": 4,
35
+ "max_position_embeddings": 1026,
36
+ "model_type": "ernierna",
37
+ "null_token_id": 5,
38
+ "num_attention_heads": 12,
39
+ "num_hidden_layers": 12,
40
+ "pad_token_id": 0,
41
+ "pairwise_alpha": 0.8,
42
+ "position_embedding_type": "sinusoidal",
43
+ "torch_dtype": "float32",
44
+ "transformers_version": "4.39.3",
45
+ "type_vocab_size": 2,
46
+ "unk_token_id": 3,
47
+ "use_cache": true,
48
+ "vocab_size": 26
49
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e5e52bf99ff701f9eda93fee10e1c975f74ffe523d7eff3e3584d480f0f97f1
3
+ size 350774824
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b90ecdcbe4ea1f183db840506e7a799279e29ab77cc8611a8bf4fdfcb0da44d5
3
+ size 350832070
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": 1026
5
+ }