Views
No views yet
| Parameter | Value |
|---|---|
| Layers | 12 |
| Attention heads | 20 |
| Embedding dimension | 1280 |
| FFN hidden dimension | 5120 (GELU) |
| Vocabulary size | 73 |
| Positional encoding | Learned |
| Normalization | LayerNorm (pre-attention/pre-FFN and final) |
| Architecture | ESM-1b-style pre-LN Transformer encoder |
| Max sequence length | 1024 total tokens (1022 codons = 3066 nucleotides, plus CLS/EOS) |
<cls> (0), <pad> (1), <eos> (2), <unk> (3), 64 standard RNA codons
(indices 4-67), 4 null-padding tokens (68-71), <mask> (72).mRNA-FM_pretrained.pth from cuhkaih/rnafmseq = seq.replace("T", "U")| Model | Training data | Embedding dim | Notes |
|---|---|---|---|
| RNA-FM | 23.7 M ncRNA | 640 | Character tokenisation |
| mRNA-FM | 45 M CDS | 1280 | This model |
1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
5model = AutoModel.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
6model.eval()
7
8# Sequences must be RNA (U not T) and length divisible by 3 (codons)
9sequences = [
10 "AUGGGGUGCGAUCAUACCAGCACUAAUGCCCUCCUGGGAAGUCCUCGUGUUGCA",
11 "AUGCUAGCUAGCUAGCUAUG",
12]
13enc = tokenizer(sequences, return_tensors="pt", padding=True)
14
15with torch.no_grad():
16 out = model(**enc)
17
18cls_emb = out.last_hidden_state[:, 0, :] # (batch, 1280) -- CLS token
19token_emb = out.last_hidden_state # (batch, n_codons+2, 1280) -- per-codon
20
21# Intermediate layers
22out_all = model(**enc, output_hidden_states=True)
23layer6_emb = out_all.hidden_states[6]batch_encode_with_cds to apply T→U conversion,
extract only the coding region, chunk to codon boundaries, and encode — all in one call.1import numpy as np
2import torch
3from transformers import AutoTokenizer, AutoModel
4
5tokenizer = AutoTokenizer.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
6model = AutoModel.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
7model.eval()
8
9# Binary CDS track: 1 at the first nucleotide of each codon in the CDS, 0 elsewhere
10sequences = ["ATGCTAGCTAGCTAGCTATGCTAGCTAGCTAGCT"]
11cds = [np.array([0]*5 + [1, 0, 0]*9 + [0]*2)] # example
12
13enc, chunk_counts = tokenizer.batch_encode_with_cds(
14 sequences, cds, return_tensors="pt", padding=True, add_special_tokens=True
15)
16with torch.no_grad():
17 out = model(**enc)
18
19# chunk_counts[i] = number of chunks produced for sequences[i]
20# mean-pool non-special tokens for each sequence:
21hidden = out.last_hidden_state # (total_chunks, seq_len, 1280)1import torch
2from transformers import AutoTokenizer, AutoModelForMaskedLM
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
5model = AutoModelForMaskedLM.from_pretrained("Taykhoom/mRNA-FM", trust_remote_code=True)
6model.eval()
7
8enc = tokenizer(["AUG<mask>GCUAUG"], return_tensors="pt")
9with torch.no_grad():
10 logits = model(**enc).logits # (1, n_codons+2, 73)out.last_hidden_state[:, 0, :]) as
input to a classification or regression head for sequence-level tasks. Mean-pool over codon
positions (excluding CLS and EOS) for codon-level aggregation.F.multi_head_attention_forward (eager). This HF port adds
attn_implementation="sdpa" and attn_implementation="flash_attention_2" support, which were
not part of the original codebase.1@article{chen2022_rnafm,
2 title = {Interpretable {RNA} Foundation Model from Unannotated Data for Highly Accurate {RNA} Structure and Function Predictions},
3 author = {Chen, Jiayang and Hu, Zhihang and Sun, Siqi and Tan, Qingxiong and Wang, Yixuan and Yu, Qinze and Zong, Licheng and Hong, Liang and Xiao, Jin and Shen, Tao and King, Irwin and Li, Yu},
4 journal = {arXiv preprint arXiv:2204.00300},
5 year = {2022},
6 doi = {10.48550/arXiv.2204.00300}
7}