deskull commited on
Commit
8cfd2d0
·
verified ·
1 Parent(s): dff2c2a

Add download-verified inference example

Browse files
Files changed (1) hide show
  1. README.md +27 -0
README.md CHANGED
@@ -69,3 +69,30 @@ If you use this model, please cite:
69
  url={{https://huggingface.co/kojima-lab/molcrawl-protein-sequence-bert-medium}}
70
  }
71
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  url={{https://huggingface.co/kojima-lab/molcrawl-protein-sequence-bert-medium}}
70
  }
71
  ```
72
+
73
+
74
+ ## Example Output
75
+
76
+ End-to-end inference test (downloaded the model from this repo on CPU).
77
+
78
+ ```python
79
+ import torch
80
+ from transformers import AutoTokenizer, AutoModelForMaskedLM
81
+
82
+ REPO_ID = "kojima-lab/molcrawl-protein-sequence-bert-medium"
83
+ tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
84
+ model = AutoModelForMaskedLM.from_pretrained(REPO_ID)
85
+ model.eval()
86
+
87
+ sequence = "MKTVRQERLKSIVRILERSKEPVSGAQLAEELSVSR<mask>VIVQDIAYLRSLGYNIVATPRGYVLAGG"
88
+ inputs = tokenizer(sequence, return_tensors="pt")
89
+ mask_index = (inputs["input_ids"][0] == tokenizer.mask_token_id).nonzero(as_tuple=True)[0]
90
+
91
+ with torch.no_grad():
92
+ outputs = model(**inputs)
93
+
94
+ predicted_id = outputs.logits[0, mask_index].argmax(dim=-1)
95
+ predicted_aa = tokenizer.convert_ids_to_tokens(predicted_id.tolist())[0]
96
+ print(f"Predicted amino acid at mask: {predicted_aa}")
97
+ # => Predicted amino acid at mask: W
98
+ ```