Views
No views yet
Taykhoom/MosaicBERT-updated via trust_remote_code=True.| Parameter | Value |
|---|---|
| Layers | 12 |
| Attention heads | 12 |
| Embedding dimension | 768 |
| FFN hidden dimension | 3,072 (GeGLU; bias-free 6,144-value gate projection) |
| Vocabulary size | 4096 (BPE, identical to DNABERT-2) |
| Positional encoding | ALiBi (no hard length limit) |
| Normalization | LayerNorm (post-LN; eps=1e-12) |
| Architecture | Post-LN MosaicBERT encoder with unpadding and GeGLU |
| Max sequence length | ~10,000 tokens (configured practical limit; ALiBi resizes dynamically) |
| Parameters | 117,068,544 (including pooler; no MLM head) |
PreTrainedTokenizerFast,
identical vocabulary to DNABERT-2. No k-mer pre-processing required.pytorch_model.bin from zhihan1996/DNABERT-S| Model | Architecture | Notes |
|---|---|---|
| DNABERT-3mer | BERT + k-mer | k=3 |
| DNABERT-4mer | BERT + k-mer | k=4 |
| DNABERT-5mer | BERT + k-mer | k=5 |
| DNABERT-6mer | BERT + k-mer | k=6 |
| DNABERT-2 | MosaicBERT + BPE + ALiBi | Pre-trained |
| DNABERT-S | MosaicBERT + BPE + ALiBi | This model |
[CLS], and the terminal
[SEP] token.1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/DNABERT-S", trust_remote_code=True)
5model = AutoModel.from_pretrained("Taykhoom/DNABERT-S", trust_remote_code=True)
6model.eval()
7
8sequences = ["ACGTAGCATCGGATCTATCTATCGACACTTGG", "ATCGATCGATCGATCG"]
9enc = tokenizer(sequences, return_tensors="pt", padding=True)
10
11with torch.no_grad():
12 out = model(**enc)
13
14cls_emb = out.last_hidden_state[:, 0, :] # (batch, 768)
15
16pool_mask = enc["attention_mask"].clone()
17pool_mask[:, 0] = 0 # exclude [CLS]
18sep_positions = enc["attention_mask"].sum(dim=1) - 1
19pool_mask[torch.arange(pool_mask.size(0)), sep_positions] = 0 # exclude [SEP]
20
21pool_mask = pool_mask.unsqueeze(-1).to(out.last_hidden_state.dtype)
22mean_emb = (out.last_hidden_state * pool_mask).sum(dim=1)
23mean_emb = mean_emb / pool_mask.sum(dim=1).clamp_min(1) # (batch, 768)1# SDPA (default on PyTorch >= 2.0)
2model = AutoModel.from_pretrained("Taykhoom/DNABERT-S", trust_remote_code=True,
3 attn_implementation="sdpa")
4
5# Flash Attention 2
6model = AutoModel.from_pretrained("Taykhoom/DNABERT-S", trust_remote_code=True,
7 attn_implementation="flash_attention_2",
8 torch_dtype=torch.bfloat16)AutoModel; AutoModelForMaskedLM raises a clear error rather than initializing random prediction weights.flash_attn_triton.py). This HF port uses
Taykhoom/MosaicBERT-updated
which replaces it with the standard flash-attn package, and also adds
attn_implementation="sdpa" support. These were not part of the original codebase.1@article{zhou2025_dnaberts,
2 title = {{DNABERT}-S: Pioneering Species Differentiation with Species-Aware {DNA} Embeddings},
3 author = {Zhou, Zhihan and Wu, Weimin and Ho, Harrison and Wang, Jiayi and Shi, Lizhen and Davuluri, Ramana V. and Wang, Zhong and Liu, Han},
4 journal = {Bioinformatics},
5 volume = {41},
6 number = {Supplement_1},
7 pages = {i255--i264},
8 year = {2025},
9 doi = {10.1093/bioinformatics/btaf188}
10}