Instructions to use Taykhoom/UTRBERT-3mer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Taykhoom/UTRBERT-3mer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="Taykhoom/UTRBERT-3mer", trust_remote_code=True)# Load model directly from transformers import AutoModelForMaskedLM model = AutoModelForMaskedLM.from_pretrained("Taykhoom/UTRBERT-3mer", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- config.json +7 -9
- model.safetensors +3 -0
- special_tokens_map.json +7 -0
- tokenization_utrbert.py +100 -0
- tokenizer_config.json +15 -0
- vocab.txt +69 -0
config.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
-
"
|
| 4 |
],
|
| 5 |
"model_type": "bert_updated",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"attention_probs_dropout_prob": 0.1,
|
| 7 |
"hidden_act": "gelu",
|
| 8 |
"hidden_dropout_prob": 0.1,
|
|
@@ -15,12 +20,5 @@
|
|
| 15 |
"pad_token_id": 0,
|
| 16 |
"type_vocab_size": 2,
|
| 17 |
"vocab_size": 69,
|
| 18 |
-
"kmer": 3
|
| 19 |
-
"auto_map": {
|
| 20 |
-
"AutoConfig": "Taykhoom/BERT-updated--configuration_bert_updated.BertUpdatedConfig",
|
| 21 |
-
"AutoModel": "Taykhoom/BERT-updated--modeling_bert.BertModel",
|
| 22 |
-
"AutoModelForMaskedLM": "Taykhoom/BERT-updated--modeling_bert.BertForMaskedLM"
|
| 23 |
-
},
|
| 24 |
-
"layer_norm_eps": 1e-12,
|
| 25 |
-
"transformers_version": "4.57.6"
|
| 26 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
+
"BertForMaskedLM"
|
| 4 |
],
|
| 5 |
"model_type": "bert_updated",
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "Taykhoom/BERT-updated--configuration_bert_updated.BertUpdatedConfig",
|
| 8 |
+
"AutoModel": "Taykhoom/BERT-updated--modeling_bert.BertModel",
|
| 9 |
+
"AutoModelForMaskedLM": "Taykhoom/BERT-updated--modeling_bert.BertForMaskedLM"
|
| 10 |
+
},
|
| 11 |
"attention_probs_dropout_prob": 0.1,
|
| 12 |
"hidden_act": "gelu",
|
| 13 |
"hidden_dropout_prob": 0.1,
|
|
|
|
| 20 |
"pad_token_id": 0,
|
| 21 |
"type_vocab_size": 2,
|
| 22 |
"vocab_size": 69,
|
| 23 |
+
"kmer": 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5f005c257c82ff99aea0f5a64ff0b798abc49166acee01a9c03ba46fa41caaa
|
| 3 |
+
size 346981836
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"unk_token": "[UNK]",
|
| 3 |
+
"sep_token": "[SEP]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"cls_token": "[CLS]",
|
| 6 |
+
"mask_token": "[MASK]"
|
| 7 |
+
}
|
tokenization_utrbert.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from typing import List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
from transformers import PreTrainedTokenizer
|
| 7 |
+
|
| 8 |
+
VOCAB_FILES_NAMES = {"vocab_file": "vocab.txt"}
|
| 9 |
+
|
| 10 |
+
VOCAB_SIZE_TO_KMER = {69: 3, 261: 4, 1029: 5, 4101: 6}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def load_vocab(vocab_file):
|
| 14 |
+
vocab = collections.OrderedDict()
|
| 15 |
+
with open(vocab_file, "r", encoding="utf-8") as f:
|
| 16 |
+
for index, line in enumerate(f):
|
| 17 |
+
token = line.rstrip("\n")
|
| 18 |
+
vocab[token] = index
|
| 19 |
+
return vocab
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class UTRBertTokenizer(PreTrainedTokenizer):
|
| 23 |
+
vocab_files_names = VOCAB_FILES_NAMES
|
| 24 |
+
model_input_names = ["input_ids", "attention_mask"]
|
| 25 |
+
|
| 26 |
+
def __init__(
|
| 27 |
+
self,
|
| 28 |
+
vocab_file,
|
| 29 |
+
unk_token="[UNK]",
|
| 30 |
+
sep_token="[SEP]",
|
| 31 |
+
pad_token="[PAD]",
|
| 32 |
+
cls_token="[CLS]",
|
| 33 |
+
mask_token="[MASK]",
|
| 34 |
+
**kwargs,
|
| 35 |
+
):
|
| 36 |
+
self._vocab = load_vocab(vocab_file)
|
| 37 |
+
self._ids_to_tokens = {v: k for k, v in self._vocab.items()}
|
| 38 |
+
vocab_size = len(self._vocab)
|
| 39 |
+
if vocab_size not in VOCAB_SIZE_TO_KMER:
|
| 40 |
+
raise ValueError(f"Unrecognised vocab size {vocab_size}; expected one of {list(VOCAB_SIZE_TO_KMER)}")
|
| 41 |
+
self.kmer = VOCAB_SIZE_TO_KMER[vocab_size]
|
| 42 |
+
super().__init__(
|
| 43 |
+
unk_token=unk_token,
|
| 44 |
+
sep_token=sep_token,
|
| 45 |
+
pad_token=pad_token,
|
| 46 |
+
cls_token=cls_token,
|
| 47 |
+
mask_token=mask_token,
|
| 48 |
+
**kwargs,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
@property
|
| 52 |
+
def vocab_size(self):
|
| 53 |
+
return len(self._vocab)
|
| 54 |
+
|
| 55 |
+
def get_vocab(self):
|
| 56 |
+
return dict(self._vocab)
|
| 57 |
+
|
| 58 |
+
def _tokenize(self, text: str) -> List[str]:
|
| 59 |
+
seq = text.upper().replace("T", "U").replace(" ", "")
|
| 60 |
+
k = self.kmer
|
| 61 |
+
return [seq[i : i + k] for i in range(len(seq) + 1 - k)]
|
| 62 |
+
|
| 63 |
+
def _convert_token_to_id(self, token: str) -> int:
|
| 64 |
+
return self._vocab.get(token, self._vocab.get(self.unk_token, 0))
|
| 65 |
+
|
| 66 |
+
def _convert_id_to_token(self, index: int) -> str:
|
| 67 |
+
return self._ids_to_tokens.get(index, self.unk_token)
|
| 68 |
+
|
| 69 |
+
def convert_tokens_to_string(self, tokens: List[str]) -> str:
|
| 70 |
+
return " ".join(tokens)
|
| 71 |
+
|
| 72 |
+
def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None) -> List[int]:
|
| 73 |
+
cls = [self.cls_token_id]
|
| 74 |
+
sep = [self.sep_token_id]
|
| 75 |
+
if token_ids_1 is None:
|
| 76 |
+
return cls + token_ids_0 + sep
|
| 77 |
+
return cls + token_ids_0 + sep + token_ids_1 + sep
|
| 78 |
+
|
| 79 |
+
def get_special_tokens_mask(self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False) -> List[int]:
|
| 80 |
+
if already_has_special_tokens:
|
| 81 |
+
return super().get_special_tokens_mask(token_ids_0, token_ids_1, already_has_special_tokens=True)
|
| 82 |
+
if token_ids_1 is None:
|
| 83 |
+
return [1] + [0] * len(token_ids_0) + [1]
|
| 84 |
+
return [1] + [0] * len(token_ids_0) + [1] + [0] * len(token_ids_1) + [1]
|
| 85 |
+
|
| 86 |
+
def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None) -> List[int]:
|
| 87 |
+
sep = [self.sep_token_id]
|
| 88 |
+
cls = [self.cls_token_id]
|
| 89 |
+
if token_ids_1 is None:
|
| 90 |
+
return [0] * len(cls + token_ids_0 + sep)
|
| 91 |
+
return [0] * len(cls + token_ids_0 + sep) + [1] * len(token_ids_1 + sep)
|
| 92 |
+
|
| 93 |
+
def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
|
| 94 |
+
os.makedirs(save_directory, exist_ok=True)
|
| 95 |
+
fname = (filename_prefix + "-" if filename_prefix else "") + "vocab.txt"
|
| 96 |
+
path = os.path.join(save_directory, fname)
|
| 97 |
+
with open(path, "w", encoding="utf-8") as f:
|
| 98 |
+
for token, _ in sorted(self._vocab.items(), key=lambda kv: kv[1]):
|
| 99 |
+
f.write(token + "\n")
|
| 100 |
+
return (path,)
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"auto_map": {
|
| 3 |
+
"AutoTokenizer": [
|
| 4 |
+
"tokenization_utrbert.UTRBertTokenizer",
|
| 5 |
+
null
|
| 6 |
+
]
|
| 7 |
+
},
|
| 8 |
+
"model_max_length": 512,
|
| 9 |
+
"tokenizer_class": "UTRBertTokenizer",
|
| 10 |
+
"unk_token": "[UNK]",
|
| 11 |
+
"sep_token": "[SEP]",
|
| 12 |
+
"pad_token": "[PAD]",
|
| 13 |
+
"cls_token": "[CLS]",
|
| 14 |
+
"mask_token": "[MASK]"
|
| 15 |
+
}
|
vocab.txt
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[PAD]
|
| 2 |
+
[UNK]
|
| 3 |
+
[CLS]
|
| 4 |
+
[SEP]
|
| 5 |
+
[MASK]
|
| 6 |
+
AAA
|
| 7 |
+
AAU
|
| 8 |
+
AAC
|
| 9 |
+
AAG
|
| 10 |
+
AUA
|
| 11 |
+
AUU
|
| 12 |
+
AUC
|
| 13 |
+
AUG
|
| 14 |
+
ACA
|
| 15 |
+
ACU
|
| 16 |
+
ACC
|
| 17 |
+
ACG
|
| 18 |
+
AGA
|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