KazukiNakamae commited on
Commit
11c6e7b
·
1 Parent(s): 845471f

Uploaded model and tokenizer files

Browse files
README.md CHANGED
@@ -1,5 +1,95 @@
1
  ---
2
  license: apache-2.0
3
  base_model:
4
- - zhihan1996/DNABERT-2-117M
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  base_model:
4
+ - zhihan1996/DNABERT-2-117M
5
+ tags:
6
+ - biology
7
+ - medical
8
+ ---
9
+ This is one of the fine-tuned models, named STL model, from [zhihan1996/DNABERT-2-117M
10
+ ](https://huggingface.co/zhihan1996/DNABERT-2-117M).
11
+
12
+ The STL model can predict the RNA offtarget induced by cytosine base editors (CBEs).
13
+
14
+ Here is an example of using the model for RNA-off-target prediction.
15
+
16
+ **pred_rna_offtarget.py:**
17
+
18
+ ```python
19
+ import sys
20
+ import numpy as np
21
+ import torch
22
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
23
+
24
+ __authors__ = ["Kazuki Nakamae"]
25
+ __version__ = "1.0.0"
26
+
27
+ def pred_rna_offtarget(dna, model_dir):
28
+ try:
29
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu") # モデル仕様に利用するデバイスの設定:CUDAが使えなければCPUを使うように設定
30
+ tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True) # 訓練済みモデルが理解できるフォーマットを指定
31
+ model = AutoModelForSequenceClassification.from_pretrained(model_dir, trust_remote_code=True).to(device) # 分類処理用に訓練済みモデルを読み込み
32
+ except Exception as e:
33
+ print(f"Error loading model from {model_dir}: {e}")
34
+ sys.exit(1)
35
+
36
+ inputs = tokenizer(dna, return_tensors='pt') # 入力テキストを訓練済みモデルが理解できるフォーマット(トークン)に分割し、各トークンを「トークンID」に変換
37
+ model.eval() # モデルの状態を推論モード(訓練モードでない)に指定
38
+ with torch.no_grad():# テンソルの勾配計算OFF:省メモリ化
39
+ # モデルのインプットとして渡して評価
40
+ outputs = model(
41
+ inputs["input_ids"].to(device),
42
+ inputs["attention_mask"].to(device),
43
+ )
44
+ # print(outputs.logits)
45
+ # 例:tensor([[-1.6488, 1.4636]])という形で出力
46
+ # [Negativeの評価値, Positiveの評価値]というような形式となっている。
47
+ y_preds = np.argmax(outputs.logits.to('cpu').detach().numpy().copy(), axis=1) # 評価値が高い方のインデックス取り出し+numpy化
48
+
49
+ # モデルからラベル判定を読み出す
50
+ def id2label(x):
51
+ return model.config.id2label[x]
52
+ y_dash = [id2label(x) for x in y_preds] # 評価値が高い方のラベル判定を取り出す
53
+ print(y_dash)
54
+ # 例:['LABEL_1']という形で出力
55
+ # LABEL_0: Negative / LABEL_1: Positive という意味
56
+ return (dna, y_dash)
57
+
58
+ def print_usage():
59
+ print(f"Usage: {sys.argv[0]} <input DNA sequence> <DNABERT-2 model directory>")
60
+ print("Options:")
61
+ print(" -h, --help Show this help message and exit")
62
+ print(" -v, --version Show version information and exit")
63
+
64
+ def print_version():
65
+ print(f"{sys.argv[0]} version {__version__}")
66
+ print("Authors:", ", ".join(__authors__))
67
+
68
+ if __name__ == "__main__":
69
+ if len(sys.argv) != 3:
70
+ if len(sys.argv) == 2 and sys.argv[1] in ("-h", "--help"):
71
+ print_usage()
72
+ sys.exit(0)
73
+ elif len(sys.argv) == 2 and sys.argv[1] in ("-v", "--version"):
74
+ print_version()
75
+ sys.exit(0)
76
+ else:
77
+ print_usage()
78
+ sys.exit(1)
79
+
80
+ dna = sys.argv[1]
81
+ model_dir = sys.argv[2]
82
+
83
+ pred_rna_offtarget(dna, model_dir)
84
+
85
+ ```
86
+
87
+ ```bash
88
+ $ python pred_rna_offtarget.py GGCAGGGCTGGGGAAGCTTACTGTGTCCAAGAGCCTGCTG KazukiNakamae/STLmodel;
89
+ ['LABEL_1']
90
+ $ python pred_rna_offtarget.py GTCATCTAACAAAAATATTCCGTTGCAGGAAAAGCAAGCT KazukiNakamae/STLmodel;
91
+ ['LABEL_0']
92
+ ```
93
+
94
+ #### Developers of the fine-tuned model
95
+ - [Takayuki Suzuki](https://github.com/szktkyk)
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "tmp/DNABERT-2-CBE_Suzuki_v1/",
3
+ "alibi_starting_size": 512,
4
+ "architectures": [
5
+ "BertForSequenceClassification"
6
+ ],
7
+ "attention_probs_dropout_prob": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "zhihan1996/DNABERT-2-117M--configuration_bert.BertConfig",
10
+ "AutoModel": "zhihan1996/DNABERT-2-117M--bert_layers.BertModel",
11
+ "AutoModelForMaskedLM": "zhihan1996/DNABERT-2-117M--bert_layers.BertForMaskedLM",
12
+ "AutoModelForSequenceClassification": "zhihan1996/DNABERT-2-117M--bert_layers.BertForSequenceClassification"
13
+ },
14
+ "classifier_dropout": null,
15
+ "gradient_checkpointing": false,
16
+ "hidden_act": "gelu",
17
+ "hidden_dropout_prob": 0.1,
18
+ "hidden_size": 768,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 3072,
21
+ "layer_norm_eps": 1e-12,
22
+ "max_position_embeddings": 512,
23
+ "num_attention_heads": 12,
24
+ "num_hidden_layers": 12,
25
+ "pad_token_id": 0,
26
+ "position_embedding_type": "absolute",
27
+ "problem_type": "single_label_classification",
28
+ "torch_dtype": "float32",
29
+ "transformers_version": "4.29.2",
30
+ "type_vocab_size": 2,
31
+ "use_cache": true,
32
+ "vocab_size": 4096
33
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61fd38248ed199c7b809140a8ae0c96267228f6adea1bd73d6145e14dfdafe08
3
+ size 468326010
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "mask_token": "[MASK]",
5
+ "model_max_length": 10,
6
+ "pad_token": "[PAD]",
7
+ "padding_side": "right",
8
+ "sep_token": "[SEP]",
9
+ "tokenizer_class": "PreTrainedTokenizerFast",
10
+ "unk_token": "[UNK]"
11
+ }