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) |
| 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 | ~10000 nt (practical; ALiBi resizes dynamically) |
| Parameters | ~117M |
PreTrainedTokenizerFast.
No k-mer pre-processing required.pytorch_model.bin from zhihan1996/DNABERT-2-117M| 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 | This model |
| DNABERT-S | MosaicBERT + BPE + ALiBi | Species-aware contrastive fine-tune |
1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/DNABERT2", trust_remote_code=True)
5model = AutoModel.from_pretrained("Taykhoom/DNABERT2", 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)
15mean_emb = out.last_hidden_state.mean(dim=1) # (batch, 768) -- mean pooling
16
17# Intermediate layers
18out_all = model(**enc, output_hidden_states=True)
19layer6_emb = out_all.hidden_states[6]1import torch
2from transformers import AutoTokenizer, AutoModelForMaskedLM
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/DNABERT2", trust_remote_code=True)
5model = AutoModelForMaskedLM.from_pretrained("Taykhoom/DNABERT2", trust_remote_code=True)
6model.eval()
7
8enc = tokenizer(["ACGTAGCAT[MASK]GGATCTATC"], return_tensors="pt")
9with torch.no_grad():
10 logits = model(**enc).logits # (1, seq_len, 4096)1# SDPA (default on PyTorch >= 2.0)
2model = AutoModel.from_pretrained("Taykhoom/DNABERT2", trust_remote_code=True,
3 attn_implementation="sdpa")
4
5# Flash Attention 2
6model = AutoModel.from_pretrained("Taykhoom/DNABERT2", trust_remote_code=True,
7 attn_implementation="flash_attention_2",
8 torch_dtype=torch.bfloat16)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@inproceedings{zhou2024_dnabert2,
2 title = {{DNABERT}-2: Efficient Foundation Model and Benchmark for Multi-Species Genomes},
3 author = {Zhou, Zhihan and Ji, Yanrong and Li, Weijian and Dutta, Pratik and Davuluri, Ramana and Liu, Han},
4 booktitle = {International Conference on Learning Representations},
5 volume = {2024},
6 pages = {41642--41665},
7 year = {2024}
8}