Views
No views yet
| Parameter | Value |
|---|---|
| Layers | 12 |
| Attention heads | 12 |
| Embedding dimension | 768 |
| FFN hidden dimension | 3072 (GELU) |
| Vocabulary size | 69 (5 special tokens + 64 RNA 3-mers) |
| Positional encoding | Learned absolute (BERT-style) |
| Normalization | LayerNorm (post-LN, eps=1e-12) |
| Architecture | Post-LN BERT-base encoder |
| Max sequence length | 512 tokens (up to 512 raw nucleotides) |
3-new-12w-0/pytorch_model.bin from figshare software record 22847354 (direct download)3-new-12w-0.3-new-12w-0 weights. Maximum
float32 absolute differences were 1.45e-5 / 3.00e-5 for eager hidden states /
logits and 8.11e-6 / 2.46e-5 for SDPA. Verified on GPU with PyTorch 2.7.1 /
CUDA 12.9 and transformers 4.57.6.| Model | k-mer | Vocab size | Notes |
|---|---|---|---|
| UTRBERT-3mer | 3 | 69 | This model |
| UTRBERT-4mer | 4 | 261 | |
| UTRBERT-5mer | 5 | 1029 | |
| UTRBERT-6mer | 6 | 4101 |
1import torch
2from transformers import AutoTokenizer, AutoModel
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True)
5model = AutoModel.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True)
6model.eval()
7
8sequences = ["AUGCAUGCAUGCAUGCAUGC", "GCGCGCGCGCGCGCGCGCGC"]
9enc = tokenizer(
10 sequences,
11 return_tensors="pt",
12 padding=True,
13 truncation=True,
14 max_length=512,
15 return_special_tokens_mask=True,
16)
17model_inputs = {k: v for k, v in enc.items() if k != "special_tokens_mask"}
18
19with torch.no_grad():
20 out = model(**model_inputs)
21
22cls_emb = out.last_hidden_state[:, 0, :] # (batch, 768) -- CLS token
23token_emb = out.last_hidden_state # (batch, seq_len, 768)
24
25# Mean-pool only biological k-mer tokens (exclude padding, CLS, and SEP).
26pool_mask = enc["attention_mask"].bool() & ~enc["special_tokens_mask"].bool()
27mean_emb = (
28 (token_emb * pool_mask.unsqueeze(-1)).sum(dim=1)
29 / pool_mask.sum(dim=1, keepdim=True)
30)
31
32# Intermediate layers
33out_all = model(**model_inputs, output_hidden_states=True)
34layer6_emb = out_all.hidden_states[6] # (batch, seq_len, 768)1import torch
2from transformers import AutoTokenizer, AutoModelForMaskedLM
3
4tokenizer = AutoTokenizer.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True)
5model = AutoModelForMaskedLM.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True)
6model.eval()
7
8# Tokenize first, then replace one overlapping k-mer token with MASK.
9enc = tokenizer(["AUGCAUGCAUG"], return_tensors="pt")
10mask_position = 3 # position 0 is CLS
11enc["input_ids"][0, mask_position] = tokenizer.mask_token_id
12with torch.no_grad():
13 logits = model(**enc).logits # (1, seq_len, 69)1# SDPA (PyTorch 2.0+)
2model = AutoModel.from_pretrained(
3 "Taykhoom/UTRBERT-3mer",
4 trust_remote_code=True,
5 attn_implementation="sdpa",
6)
7
8# Flash Attention 2 (requires flash-attn)
9model = AutoModel.from_pretrained(
10 "Taykhoom/UTRBERT-3mer",
11 trust_remote_code=True,
12 attn_implementation="flash_attention_2",
13 dtype=torch.float16,
14)1import torch.nn as nn
2from transformers import AutoModel
3
4model = AutoModel.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True)
5
6class UTRClassifier(nn.Module):
7 def __init__(self, base, num_labels):
8 super().__init__()
9 self.base = base
10 self.head = nn.Linear(768, num_labels)
11
12 def forward(self, input_ids, attention_mask):
13 cls = self.base(input_ids, attention_mask=attention_mask).last_hidden_state[:, 0]
14 return self.head(cls)BERT-updated code backend
through its cross-repository auto_map, plus the custom k-mer tokenizer stored
in this repository. trust_remote_code=True is required. Loading a local
checkpoint directory also requires network access to BERT-updated, unless
that code is already cached.sdpa and flash_attention_2 inference backends.1@article{yang2024_3utrbert,
2 title = {Deciphering 3'{UTR} Mediated Gene Regulation Using Interpretable Deep Representation Learning},
3 author = {Yang, Yuning and Li, Gen and Pang, Kuan and Cao, Wuxinhao and Zhang, Zhaolei and Li, Xiangtao},
4 journal = {Advanced Science},
5 volume = {11},
6 number = {39},
7 pages = {e2407013},
8 year = {2024},
9 doi = {10.1002/advs.202407013}
10}