Commit
·
4025bf2
1
Parent(s):
2c0808a
DOC: Blacken example code block
Browse files
README.md
CHANGED
|
@@ -16,19 +16,21 @@ To use **BarcodeBERT** as a feature extractor:
|
|
| 16 |
from transformers import AutoTokenizer, AutoModel
|
| 17 |
|
| 18 |
# Load the tokenizer
|
| 19 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
#Load the model
|
| 22 |
model = AutoModel.from_pretrained("bioscan-ml/BarcodeBERT", trust_remote_code=True)
|
| 23 |
|
| 24 |
# Sample sequence
|
| 25 |
-
dna_seq =
|
| 26 |
|
| 27 |
# Tokenize
|
| 28 |
-
input_seq = tokenizer(dna_seq, return_tensors
|
| 29 |
|
| 30 |
# Pass through the model
|
| 31 |
-
output = model(input_seq.unsqueeze(0))[
|
| 32 |
|
| 33 |
# Compute Global Average Pooling
|
| 34 |
features = output.mean(1)
|
|
|
|
| 16 |
from transformers import AutoTokenizer, AutoModel
|
| 17 |
|
| 18 |
# Load the tokenizer
|
| 19 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 20 |
+
"bioscan-ml/BarcodeBERT", trust_remote_code=True
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
# Load the model
|
| 24 |
model = AutoModel.from_pretrained("bioscan-ml/BarcodeBERT", trust_remote_code=True)
|
| 25 |
|
| 26 |
# Sample sequence
|
| 27 |
+
dna_seq = "ACGCGCTGACGCATCAGCATACGA"
|
| 28 |
|
| 29 |
# Tokenize
|
| 30 |
+
input_seq = tokenizer(dna_seq, return_tensors="pt")["input_ids"]
|
| 31 |
|
| 32 |
# Pass through the model
|
| 33 |
+
output = model(input_seq.unsqueeze(0))["hidden_states"][-1]
|
| 34 |
|
| 35 |
# Compute Global Average Pooling
|
| 36 |
features = output.mean(1)
|