Add inference example output to model card
Browse files
README.md
CHANGED
|
@@ -69,3 +69,33 @@ If you use this model, please cite:
|
|
| 69 |
url={{https://huggingface.co/kojima-lab/molcrawl-genome-sequence-bert-small}}
|
| 70 |
}
|
| 71 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
url={{https://huggingface.co/kojima-lab/molcrawl-genome-sequence-bert-small}}
|
| 70 |
}
|
| 71 |
```
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
## Example Output
|
| 75 |
+
|
| 76 |
+
Inference test performed on the uploaded checkpoint (CPU):
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 80 |
+
import torch
|
| 81 |
+
|
| 82 |
+
model = AutoModelForMaskedLM.from_pretrained("kojima-lab/molcrawl-genome-sequence-bert-small")
|
| 83 |
+
tokenizer = AutoTokenizer.from_pretrained("kojima-lab/molcrawl-genome-sequence-bert-small")
|
| 84 |
+
|
| 85 |
+
# DNA masked token prediction (SentencePiece BPE subword vocabulary)
|
| 86 |
+
# Mask token: '[MASK]'
|
| 87 |
+
prompt = "ATCGATCGATCG[MASK]GCTTATCAAGCT"
|
| 88 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 89 |
+
mask_token_id = tokenizer.mask_token_id
|
| 90 |
+
mask_index = (inputs["input_ids"] == mask_token_id).nonzero(as_tuple=True)[1]
|
| 91 |
+
|
| 92 |
+
with torch.no_grad():
|
| 93 |
+
outputs = model(**inputs)
|
| 94 |
+
logits = outputs.logits
|
| 95 |
+
|
| 96 |
+
predicted_token_id = logits[0, mask_index].argmax(dim=-1)
|
| 97 |
+
predicted_token = tokenizer.decode(predicted_token_id)
|
| 98 |
+
result = prompt.replace(tokenizer.mask_token, predicted_token)
|
| 99 |
+
print(f"Predicted: {result}")
|
| 100 |
+
# => Predicted: ATCGATCGATCGCGCTTATCAAGCT
|
| 101 |
+
```
|