CoolFace
Modelpublic

Imranyai/CodonFM-80M-mRNA-stability

sourceHugging Faceotherupdated 5mo agoView on Hugging Face
0likes
Model Card

๐Ÿงฌ CodonFM-80M โ€” Fine-tuned for mRNA Stability Prediction

Fine-tuned version of NVIDIA NV-CodonFM-Encodon-80M-v1 for predicting mRNA stability (half-life) from coding sequences.

Model Overview

PropertyValue
Base Modelnvidia/NV-CodonFM-Encodon-80M-v1
Parameters80M (77.9M total)
ArchitectureBERT-style Transformer with Rotary Position Embeddings (RoPE)
TokenizationCodon-level (69 vocab: 64 codons + 5 special tokens)
Max Length2,046 codons (~6,138 nucleotides)
TaskRegression โ€” predict mRNA stability score
InputmRNA/DNA coding sequence
OutputContinuous stability score (higher = more stable)

Architecture Details

Encoder: 6 Transformer layers, hidden_size=1024, 8 attention heads, 4096 FFN
Position: Rotary Position Embeddings (RoPE, ฮธ=10000)
Pretraining: Masked Language Modeling (MLM) on >130M coding sequences from NCBI RefSeq
Fine-tuning: Regression head (mean-pooled โ†’ Dense โ†’ Tanh โ†’ Dense โ†’ scalar)
Strategy: Freeze first 4/6 layers, unfreeze last 2 + regression head

Training

Datasets

DatasetSamplesDescription
mogam-ai/CDS-BART-mRNA-stability41,063iCodon vertebrate mRNA stability (human, mouse, frog, fish)
GleghornLab/mrna_stability_other65,356Additional multi-species mRNA stability data
Combined106,419Train: 74,519 / Val: 16,010 / Test: 15,890

Training Recipe

Based on Helix-mRNA and BEACON:

ParameterValue
OptimizerAdamW (backbone lr=5e-5, head lr=5e-4)
Weight Decay0.01
SchedulerCosine with 100-step warmup
Epochs20
Batch Size16 ร— 2 grad_accum = 32 effective
Max Length1024 codons
PrecisionFP16 mixed precision
Frozen LayersFirst 4 of 6 (embeddings + layers 0-3)
TrainableLayers 4-5 + regression head (~26.3M params)

Literature Comparison (Spearman ฯ on mRNA Stability)

ModelSpearman ฯ
CodonBERT0.35
XE0.50
Helix-mRNA0.52
HELM0.53

๐Ÿš€ Quick Start

Installation

bash
pip install -r requirements.txt

Inference โ€” Single Sequence

python
from inference import CodonFMStabilityPredictor

# Load fine-tuned model
predictor = CodonFMStabilityPredictor.from_hub("Imranyai/CodonFM-80M-mRNA-stability")

# Predict stability
result = predictor.predict("AUGGCAGCCGAGACUCGGAACGUGGCCGGAGCAGAGGCCCCACCG...")
print(f"Stability score: {result['stability_score']:.4f}")
print(f"Sequence: {result['num_codons']} codons ({result['sequence_length_nt']} nt)")

Inference โ€” Batch Prediction

python
sequences = [
    "AUGGCAGCCGAGACUCGG...",
    "AUGACAAUCGGUCAGACAAUG...",
    "AUGGGGUCUUCAUCAUCAUC...",
]
results = predictor.predict_batch(sequences, batch_size=32)
for r in results:
    print(f"Score: {r['stability_score']:.4f} ({r['num_codons']} codons)")

Inference โ€” Command Line

bash
# Single sequence
python inference.py --sequence "AUGGCAGCCGAGACUCGG..."

# FASTA file
python inference.py --fasta input.fasta --output predictions.csv

# CSV file
python inference.py --csv data.csv --seq_column mRNA_seq --output results.csv

# Extract embeddings
python inference.py --fasta input.fasta --mode embeddings --output embeddings.npy

# Zero-shot MLM stability proxy (base model)
python inference.py --sequence "AUGGCAGCC..." --mode base_mlm

Extract Embeddings (for downstream tasks)

python
embeddings = predictor.get_embeddings(sequences, batch_size=32)
# Shape: [N, 1024] โ€” use for clustering, classification, etc.

๐Ÿ“Š Benchmarking

Run the full CodonFM/CodonBERT benchmark suite (5 tasks):

bash
# Benchmark with base CodonFM model
python benchmark.py --mode base

# Benchmark with fine-tuned model
python benchmark.py --mode finetuned --model_repo Imranyai/CodonFM-80M-mRNA-stability

# Specific tasks only
python benchmark.py --mode base --tasks stability mrfp vaccine

# With GPU
python benchmark.py --mode base --device cuda --batch_size 64

Benchmark Tasks

TaskDatasetSamplesMetricDescription
stabilityiCodon (CodonBERT)65,356Spearman ฯmRNA half-life prediction
mrfpmRFP Expression1,459Spearman ฯProtein expression in E. coli
vaccineCoV Vaccine Degradation2,400Spearman ฯSARS-CoV-2 mRNA vaccine degradation
riboswitchTc-Riboswitches355Spearman ฯTetracycline riboswitch activity
mlosMLOS Flu Vaccine167Spearman ฯFlu vaccine antigen expression

Evaluation method: Frozen embeddings โ†’ RandomForest regression (matching CodonFM evaluation methodology).

๐Ÿ“‹ Dataset Setup & Preprocessing

Full dataset documentation: [DATASETS.md](DATASETS.md)

bash
# Download and audit all datasets
python data_setup.py --all

# Just download training data
python data_setup.py --training

# Preprocess, deduplicate, and export clean CSVs
python data_setup.py --preprocess --export ./processed_data

# Show the 69-token codon vocabulary
python data_setup.py --vocab

Key findings from data audit:

  • โ€”Training data: 65,356 samples from multi-species mRNA stability profiles (z-normalized half-life)
  • โ€”mogam-ai dataset is a complete subset of GleghornLab โ€” no need to combine both
  • โ€”All sequences use RNA alphabet (A,U,G,C), all divisible by 3, mean ~447 codons
  • โ€”Benchmark datasets auto-download from CodonBERT GitHub (5 tasks, 355โ€“65K samples each)

๐Ÿ”ฌ Training from Scratch

bash
# Install dependencies
pip install -r requirements.txt

# Run training (GPU recommended)
python train_codonfm_stability.py

# Environment variables for customization:
LEARNING_RATE=5e-5 \
NUM_EPOCHS=20 \
BATCH_SIZE=16 \
FREEZE_LAYERS=4 \
MAX_LENGTH=1024 \
HUB_MODEL_ID=your-name/your-model \
python train_codonfm_stability.py

Repository Contents

โ”œโ”€โ”€ README.md                         # This file
โ”œโ”€โ”€ DATASETS.md                       # Comprehensive dataset documentation
โ”œโ”€โ”€ requirements.txt                  # Python dependencies
โ”œโ”€โ”€ data_setup.py                     # Dataset download, preprocessing & audit
โ”œโ”€โ”€ train_codonfm_stability.py        # Fine-tuning script
โ”œโ”€โ”€ inference.py                      # Inference API + CLI
โ”œโ”€โ”€ benchmark.py                      # Benchmark suite (5 tasks)
โ”œโ”€โ”€ config.json                       # Model configuration (after training)
โ”œโ”€โ”€ codon_vocab.json                  # Codon tokenizer vocabulary (after training)
โ””โ”€โ”€ pytorch_model.bin                 # Fine-tuned model weights (after training)

Citation

bibtex
@article{diez2022icodon,
  title={iCodon customizes gene expression based on the codon composition},
  author={Diez, Michay and others},
  journal={Scientific Reports},
  volume={12},
  pages={12126},
  year={2022}
}

@article{li2024codonbert,
  title={CodonBERT large language model for mRNA vaccines},
  author={Li, Sizhen and others},
  journal={Genome Research},
  volume={34},
  number={7},
  pages={1027--1035},
  year={2024}
}

License

This model is governed by the NVIDIA Open Model License Agreement (inherited from the base model).

Acknowledgements