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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
---
datasets:
- multimolecule/rnacentral
- multimolecule/rfam
- multimolecule/ensembl-genome-browser
- multimolecule/nucleotide
language: rna
library_name: multimolecule
license: agpl-3.0
mask_token: <mask>
pipeline_tag: fill-mask
tags:
- Biology
- RNA
- ncRNA
widget:
- example_title: microRNA 21
  output:
  - label: W
    score: 1.0
  - label: K
    score: 0.0
  - label: H
    score: 0.0
  - label: <unk>
    score: 0.0
  - label: B
    score: 0.0
  text: UAGCUUAUCAGAC<mask>GAUGUUGA
- example_title: microRNA 146a
  output:
  - label: W
    score: 1.0
  - label: K
    score: 0.0
  - label: H
    score: 0.0
  - label: '-'
    score: 0.0
  - label: <mask>
    score: 0.0
  text: UGAGAACUGAA<mask>UCCAUGGGUU
- example_title: microRNA 155
  output:
  - label: W
    score: 1.0
  - label: K
    score: 0.0
  - label: H
    score: 0.0
  - label: <mask>
    score: 0.0
  - label: <unk>
    score: 0.0
  text: UUAAUGCUAA<mask>CGUGAUAGGGGUU
- example_title: metastasis associated lung adenocarcinoma transcript 1
  output:
  - label: W
    score: 1.0
  - label: H
    score: 0.0
  - label: K
    score: 0.0
  - label: <unk>
    score: 0.0
  - label: M
    score: 0.0
  text: AGGCAUUGAGGCAGCCAGCGCAGGGGC<mask>UCUGCUGAGGGGGCAGGCGGAGCUUGAGGAAA
- example_title: Pvt1 oncogene
  output:
  - label: W
    score: 1.0
  - label: K
    score: 0.0
  - label: '-'
    score: 0.0
  - label: H
    score: 0.0
  - label: N
    score: 0.0
  text: CCCGCGCUCC<mask>CCGGGCAGAGCGCGUGUGGCGGCCGAGCACAUGGGCCCGCGGGCCGGGC
- example_title: telomerase RNA component
  output:
  - label: W
    score: 0.999979
  - label: K
    score: 2.1e-05
  - label: H
    score: 0.0
  - label: '-'
    score: 0.0
  - label: <unk>
    score: 0.0
  text: GGGUUGCGGAGGG<mask>GGGCCUGGGAGGGGUGGUGGCCAUUUUUUGUCUAACCCUAACUGAG
- example_title: vault RNA 2-1
  output:
  - label: W
    score: 1.0
  - label: K
    score: 0.0
  - label: '-'
    score: 0.0
  - label: H
    score: 0.0
  - label: M
    score: 0.0
  text: CGGGUCGGAG<mask>UAGCUCAAGCGGUUACCUCCUCAUGCCGGACUUUCUAUCUGUCCAUCUCUGUGCUGGGGUUCGAGACCCGCGGGUGCUUACUGACCCUUUUAUGCAA
- example_title: brain cytoplasmic RNA 1
  output:
  - label: <unk>
    score: 0.643389
  - label: H
    score: 0.356611
  - label: W
    score: 0.0
  - label: V
    score: 0.0
  - label: G
    score: 0.0
  text: GGCCGGGCGCGG<mask>GGCUCACGCCUGUAAUCCCAGCUCUCAGGGAGGCUAAGAGGCGGGAGGAUAGCUUGAGCCCAGGAGUUCGAGACCUGCCUGGGCAAUAUAGCGAGACCCCGUUCUCCAGAAAAAGGAAAAAAAAAAACAAAAGACAAAAAAAAAAUAAGCGUAACUUCCCUCAAAGCAACAACCCCCCCCCCCCUUU
- example_title: HIV-1 TAR-WT
  output:
  - label: W
    score: 0.875797
  - label: H
    score: 0.123927
  - label: '-'
    score: 0.000231
  - label: K
    score: 3.2e-05
  - label: M
    score: 7.0e-06
  text: GGUCUCUCUGG<mask>UAGACCAGAUCUGAGCCUGGGAGCUCUCUGGCUAACUAGGGAACC
---

# RiNALMo

Pre-trained model on non-coding RNA (ncRNA) using a masked language modeling (MLM) objective.

## Disclaimer

This is an UNOFFICIAL implementation of the [RiNALMo: General-Purpose RNA Language Models Can Generalize Well on Structure Prediction Tasks](https://doi.org/10.48550/arXiv.2403.00043) by Rafael Josip Penić, et al.

The OFFICIAL repository of RiNALMo is at [lbcb-sci/RiNALMo](https://github.com/lbcb-sci/RiNALMo).

> [!TIP]
> The MultiMolecule team has confirmed that the provided model and checkpoints are producing the same intermediate representations as the original implementation.

**The team releasing RiNALMo did not write this model card for this model so this model card has been written by the MultiMolecule team.**

## Model Details

RiNALMo 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.

### Variants

- **[multimolecule/rinalmo-mega](https://huggingface.co/multimolecule/rinalmo-mega)**: The RiNALMo model with 150 million parameters.
- **[multimolecule/rinalmo-giga](https://huggingface.co/multimolecule/rinalmo-giga)**: The RiNALMo model with 650 million parameters.
- **[multimolecule/rinalmo-micro](https://huggingface.co/multimolecule/rinalmo-micro)**: The RiNALMo model with 30 million parameters.

### Model Specification

<table>
<thead>
  <tr>
    <th>Variants</th>
    <th>Num Layers</th>
    <th>Hidden Size</th>
    <th>Num Heads</th>
    <th>Intermediate Size</th>
    <th>Num Parameters (M)</th>
    <th>FLOPs (G)</th>
    <th>MACs (G)</th>
    <th>Max Num Tokens</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>RiNALMo-Mega</td>
    <td>30</td>
    <td>640</td>
    <td rowspan="3">20</td>
    <td>2560</td>
    <td>148.04</td>
    <td>39.03</td>
    <td>19.5</td>
    <td rowspan="3">1022</td>
  </tr>
  <tr>
    <td>RiNALMo-Giga</td>
    <td>33</td>
    <td>1280</td>
    <td>5120</td>
    <td>650.88</td>
    <td>168.92</td>
    <td>84.43</td>
  </tr>
  <tr>
    <td>RiNALMo-Micro</td>
    <td>12</td>
    <td>480</td>
    <td>1920</td>
    <td>33.48</td>
    <td>8.88</td>
    <td>4.44</td>
  </tr>
</tbody>
</table>

### Links

- **Code**: [multimolecule.rinalmo](https://github.com/DLS5-Omics/multimolecule/tree/master/multimolecule/models/rinalmo)
- **Data**: [multimolecule/rnacentral](https://huggingface.co/datasets/multimolecule/rnacentral)
- **Paper**: [RiNALMo: General-Purpose RNA Language Models Can Generalize Well on Structure Prediction Tasks](https://doi.org/10.48550/arXiv.2403.00043)
- **Developed by**: Rafael Josip Penić, Tin Vlašić, Roland G. Huber, Yue Wan, Mile Šikić
- **Model type**: [BERT](https://huggingface.co/google-bert/bert-base-uncased)
- **Original Repository**: [lbcb-sci/RiNALMo](https://github.com/lbcb-sci/RiNALMo)

## Usage

The model file depends on the [`multimolecule`](https://multimolecule.danling.org) library. You can install it using pip:

```bash
pip install multimolecule
```

### Direct Use

#### Masked Language Modeling

You can use this model directly with a pipeline for masked language modeling:

```python
>>> import multimolecule  # you must import multimolecule to register models
>>> from transformers import pipeline

>>> unmasker = pipeline("fill-mask", model="multimolecule/rinalmo-mega")
>>> unmasker("gguc<mask>cucugguuagaccagaucugagccu")
[{'score': 0.2527551054954529,
  'token': 10,
  'token_str': 'N',
  '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'},
 {'score': 0.13404159247875214,
  'token': 11,
  'token_str': 'R',
  'sequence': 'G G U C R 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'},
 {'score': 0.09840001165866852,
  'token': 15,
  'token_str': 'K',
  'sequence': 'G G U C K 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'},
 {'score': 0.07807068526744843,
  'token': 14,
  'token_str': 'W',
  'sequence': 'G G U C W 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'},
 {'score': 0.06360691040754318,
  'token': 9,
  'token_str': 'U',
  'sequence': 'G G U C U 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'}]
```

### Downstream Use

#### Extract Features

Here is how to use this model to get the features of a given sequence in PyTorch:

```python
from multimolecule import RnaTokenizer, RiNALMoModel


tokenizer = RnaTokenizer.from_pretrained("multimolecule/rinalmo-mega")
model = RiNALMoModel.from_pretrained("multimolecule/rinalmo-mega")

text = "UAGCUUAUCAGACUGAUGUUG"
input = tokenizer(text, return_tensors="pt")

output = model(**input)
```

#### Sequence Classification / Regression

> [!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.

Here is how to use this model as backbone to fine-tune for a sequence-level task in PyTorch:

```python
import torch
from multimolecule import RnaTokenizer, RiNALMoForSequencePrediction


tokenizer = RnaTokenizer.from_pretrained("multimolecule/rinalmo-mega")
model = RiNALMoForSequencePrediction.from_pretrained("multimolecule/rinalmo-mega")

text = "UAGCUUAUCAGACUGAUGUUG"
input = tokenizer(text, return_tensors="pt")
label = torch.tensor([1])

output = model(**input, labels=label)
```

#### Token Classification / Regression

> [!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 token classification or regression.

Here is how to use this model as backbone to fine-tune for a nucleotide-level task in PyTorch:

```python
import torch
from multimolecule import RnaTokenizer, RiNALMoForTokenPrediction


tokenizer = RnaTokenizer.from_pretrained("multimolecule/rinalmo-mega")
model = RiNALMoForTokenPrediction.from_pretrained("multimolecule/rinalmo-mega")

text = "UAGCUUAUCAGACUGAUGUUG"
input = tokenizer(text, return_tensors="pt")
label = torch.randint(2, (len(text), ))

output = model(**input, labels=label)
```

#### Contact Classification / Regression

> [!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.

Here is how to use this model as backbone to fine-tune for a contact-level task in PyTorch:

```python
import torch
from multimolecule import RnaTokenizer, RiNALMoForContactPrediction


tokenizer = RnaTokenizer.from_pretrained("multimolecule/rinalmo-mega")
model = RiNALMoForContactPrediction.from_pretrained("multimolecule/rinalmo-mega")

text = "UAGCUUAUCAGACUGAUGUUG"
input = tokenizer(text, return_tensors="pt")
label = torch.randint(2, (len(text), len(text)))

output = model(**input, labels=label)
```

## Training Details

RiNALMo 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.

### Training Data

The RiNALMo model was pre-trained on a cocktail of databases including [RNAcentral](https://rnacentral.org), [Rfam](https://rfam.org), [Ensembl Genome Browser](https://ensembl.org), and [Nucleotide](https://ncbi.nlm.nih.gov/nucleotide).
The training data contains 36 million unique ncRNA sequences.

To ensure sequence diversity in each training batch, RiNALMo clustered the sequences with [MMSeqs2](https://github.com/soedinglab/MMseqs2) into 17 million clusters and then sampled each sequence in the batch from a different cluster.

RiNALMo preprocessed all tokens by replacing "U"s with "T"s.

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`.

### Training Procedure

#### Preprocessing

RiNALMo used masked language modeling (MLM) as the pre-training objective. The masking procedure is similar to the one used in BERT:

- 15% of the tokens are masked.
- In 80% of the cases, the masked tokens are replaced by `<mask>`.
- In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
- In the 10% remaining cases, the masked tokens are left as is.

#### Pre-training

The model was trained on 7 NVIDIA A100 GPUs with 80GiB memories.

- Batch Size: 1344
- Epochs: 6
- Learning rate: 5e-5
- Learning rate scheduler: Cosine
- Learning rate warm-up: 2,000 steps
- Learning rate minimum: 1e-5
- Dropout: 0.1

## Citation

**BibTeX**:

```bibtex
@ARTICLE{Penic2025-qf,
  title     = "{RiNALMo}: general-purpose {RNA} language models can generalize
               well on structure prediction tasks",
  author    = "Peni{\'c}, Rafael Josip and Vla{\v s}i{\'c}, Tin and Huber,
               Roland G and Wan, Yue and {\v S}iki{\'c}, Mile",
  abstract  = "While RNA has recently been recognized as an interesting
               small-molecule drug target, many challenges remain to be
               addressed before we take full advantage of it. This emphasizes
               the necessity to improve our understanding of its structures and
               functions. Over the years, sequencing technologies have produced
               an enormous amount of unlabeled RNA data, which hides a huge
               potential. Motivated by the successes of protein language
               models, we introduce RiboNucleic Acid Language Model (RiNALMo)
               to unveil the hidden code of RNA. RiNALMo is the largest RNA
               language model to date, with 650M parameters pre-trained on 36M
               non-coding RNA sequences from several databases. It can extract
               hidden knowledge and capture the underlying structure
               information implicitly embedded within the RNA sequences.
               RiNALMo achieves state-of-the-art results on several downstream
               tasks. Notably, we show that its generalization capabilities
               overcome the inability of other deep learning methods for
               secondary structure prediction to generalize on unseen RNA
               families.",
  journal   = "Nature Communications",
  publisher = "Springer Science and Business Media LLC",
  volume    =  16,
  number    =  1,
  pages     = "5671",
  month     =  jul,
  year      =  2025,
  copyright = "https://creativecommons.org/licenses/by-nc-nd/4.0",
  language  = "en"
}
```

## Contact

Please use GitHub issues of [MultiMolecule](https://github.com/DLS5-Omics/multimolecule/issues) for any questions or comments on the model card.

Please contact the authors of the [RiNALMo paper](https://doi.org/10.48550/arXiv.2403.00043) for questions or comments on the paper/model.

## License

This model is licensed under the [AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html).

```spdx
SPDX-License-Identifier: AGPL-3.0-or-later
```