Commit
·
a85ac51
1
Parent(s):
c5d92aa
Update README.md
Browse files
README.md
CHANGED
@@ -24,4 +24,61 @@ Test metrics:
|
|
24 |
'eval_f1': 0.08376472210171558,
|
25 |
'eval_auc': 0.8539155251667717,
|
26 |
'eval_mcc': 0.17519724897930178}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
```
|
|
|
24 |
'eval_f1': 0.08376472210171558,
|
25 |
'eval_auc': 0.8539155251667717,
|
26 |
'eval_mcc': 0.17519724897930178}
|
27 |
+
```
|
28 |
+
|
29 |
+
## Using the Model
|
30 |
+
|
31 |
+
To use this model, firts run:
|
32 |
+
|
33 |
+
```
|
34 |
+
!pip install transformers -q
|
35 |
+
!pip install peft -q
|
36 |
+
```
|
37 |
+
|
38 |
+
Then run the following on your protein sequence to predict post translational modification sites:
|
39 |
+
|
40 |
+
```python
|
41 |
+
from transformers import AutoModelForTokenClassification, AutoTokenizer
|
42 |
+
from peft import PeftModel
|
43 |
+
import torch
|
44 |
+
|
45 |
+
# Path to the saved LoRA model
|
46 |
+
model_path = "AmelieSchreiber/esm2_t6_8M_ptm_lora_500K"
|
47 |
+
# ESM2 base model
|
48 |
+
base_model_path = "facebook/esm2_t6_8M_UR50D"
|
49 |
+
|
50 |
+
# Load the model
|
51 |
+
base_model = AutoModelForTokenClassification.from_pretrained(base_model_path)
|
52 |
+
loaded_model = PeftModel.from_pretrained(base_model, model_path)
|
53 |
+
|
54 |
+
# Ensure the model is in evaluation mode
|
55 |
+
loaded_model.eval()
|
56 |
+
|
57 |
+
# Load the tokenizer
|
58 |
+
loaded_tokenizer = AutoTokenizer.from_pretrained(base_model_path)
|
59 |
+
|
60 |
+
# Protein sequence for inference
|
61 |
+
protein_sequence = "MAVPETRPNHTIYINNLNEKIKKDELKKSLHAIFSRFGQILDILVSRSLKMRGQAFVIFKEVSSATNALRSMQGFPFYDKPMRIQYAKTDSDIIAKMKGT" # Replace with your actual sequence
|
62 |
+
|
63 |
+
# Tokenize the sequence
|
64 |
+
inputs = loaded_tokenizer(protein_sequence, return_tensors="pt", truncation=True, max_length=1024, padding='max_length')
|
65 |
+
|
66 |
+
# Run the model
|
67 |
+
with torch.no_grad():
|
68 |
+
logits = loaded_model(**inputs).logits
|
69 |
+
|
70 |
+
# Get predictions
|
71 |
+
tokens = loaded_tokenizer.convert_ids_to_tokens(inputs["input_ids"][0]) # Convert input ids back to tokens
|
72 |
+
predictions = torch.argmax(logits, dim=2)
|
73 |
+
|
74 |
+
# Define labels
|
75 |
+
id2label = {
|
76 |
+
0: "No ptm site",
|
77 |
+
1: "ptm site"
|
78 |
+
}
|
79 |
+
|
80 |
+
# Print the predicted labels for each token
|
81 |
+
for token, prediction in zip(tokens, predictions[0].numpy()):
|
82 |
+
if token not in ['<pad>', '<cls>', '<eos>']:
|
83 |
+
print((token, id2label[prediction]))
|
84 |
```
|