Views
No views yet
A / C / G / T / N, pretrained with
masked language modeling on genomic sequence, built on a ModernBERT encoder with
an 8192-nucleotide context window.trust_remote_code=True.| variant | hidden | layers | heads | parameters | download | how to load |
|---|---|---|---|---|---|---|
mini | 384 | 8 | 6 | ~150M | 0.60 GB | subfolder="mini" |
base | 512 | 22 | 16 | ~229M | 0.92 GB | (default — repo root) |
pro | 768 | 24 | 12 | ~364M | 1.46 GB | subfolder="pro" |
max | 1024 | 24 | 16 | ~542M | 2.17 GB | subfolder="max" |
mini is the fastest / lightest and a good default for large
screens or limited GPU memory; max gives the strongest representations at
the highest compute cost; base / pro sit in between. Same API for all.1from transformers import AutoModel
2
3# base (default, repo root)
4base = AutoModel.from_pretrained("FreakingPotato/NucEngram", trust_remote_code=True)
5
6# any other size via subfolder
7mini = AutoModel.from_pretrained("FreakingPotato/NucEngram", subfolder="mini", trust_remote_code=True)
8pro = AutoModel.from_pretrained("FreakingPotato/NucEngram", subfolder="pro", trust_remote_code=True)
9maxm = AutoModel.from_pretrained("FreakingPotato/NucEngram", subfolder="max", trust_remote_code=True)pip install "transformers>=4.44" torch safetensors1from transformers import AutoModel
2
3model = AutoModel.from_pretrained("FreakingPotato/NucEngram",
4 trust_remote_code=True).eval()
5
6# convenience helper: sequence(s) -> pooled embedding [B, hidden]
7emb = model.embed(["ACGTACGTACGTGGTAAGT", "TTGCCGCGCGATCGATCG"])
8print(emb.shape) # torch.Size([2, 512]) (512 = base hidden size)1ids, attention_mask = model.encode("ACGT...") # char-level tokenizer, pad id 0
2out = model(ids, attention_mask)
3h = out.last_hidden_state # [B, T, hidden]base for linear probing).
Swap the subfolder= argument to choose a size:1import torch, torch.nn as nn
2from transformers import AutoModel
3
4class SequenceClassifier(nn.Module):
5 def __init__(self, n_classes, size=None, freeze_base=False):
6 super().__init__()
7 kw = {"trust_remote_code": True}
8 if size: # None -> base (root); else "mini"/"pro"/"max"
9 kw["subfolder"] = size
10 self.base = AutoModel.from_pretrained("FreakingPotato/NucEngram", **kw)
11 hidden = self.base.config.hidden_size
12 if freeze_base:
13 for p in self.base.parameters():
14 p.requires_grad_(False)
15 self.head = nn.Linear(hidden, n_classes)
16
17 def forward(self, input_ids, attention_mask):
18 h = self.base(input_ids, attention_mask).last_hidden_state # [B, T, hidden]
19 m = attention_mask.unsqueeze(-1).float()
20 pooled = (h * m).sum(1) / m.sum(1).clamp(min=1.0) # mean-pool
21 return self.head(pooled)
22
23clf = SequenceClassifier(n_classes=2, size="mini").train()
24ids, am = clf.base.encode(["ACGT...", "GGGT..."]) # your batch of sequences
25logits = clf(ids, am)
26# ... standard cross-entropy training loop on your labelled dataset ...1from transformers import AutoModelForMaskedLM
2mlm = AutoModelForMaskedLM.from_pretrained("FreakingPotato/NucEngram",
3 trust_remote_code=True).eval()
4ids, am = mlm.encode("ACGTACGT")
5logits = mlm(ids, am).logits # [B, T, 9] over A/C/G/T/N + special tokens| Backbone | ModernBERT encoder (see the size table above) |
| Context | up to 8192 nucleotides |
| Vocabulary | 9 tokens (A, C, G, T, N + pad/bos/eos/mask), char-level |
| Attention | sdpa by default (no flash-attn required) |
| Precision | fp32 weights (cast with .half() / .bfloat16() as you like) |
encode() maps
characters to ids and pads with id 0. Use attention_mask to ignore padding.