AmelieSchreiber commited on
Commit
2839395
1 Parent(s): 9a1d58d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -0
README.md CHANGED
@@ -1,3 +1,53 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ # ESM-2 for Predicting Binding Sites
6
+
7
+ ## Using the Model
8
+
9
+ ```python
10
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
11
+ from peft import PeftModel
12
+ import torch
13
+
14
+ # Path to the saved LoRA model
15
+ model_path = "AmelieSchreiber/esm2_t33_650M_qlora_binding_12M"
16
+ # ESM2 base model
17
+ base_model_path = "facebook/esm2_t12_35M_UR50D"
18
+
19
+ # Load the model
20
+ base_model = AutoModelForTokenClassification.from_pretrained(base_model_path)
21
+ loaded_model = PeftModel.from_pretrained(base_model, model_path)
22
+
23
+ # Ensure the model is in evaluation mode
24
+ loaded_model.eval()
25
+
26
+ # Load the tokenizer
27
+ loaded_tokenizer = AutoTokenizer.from_pretrained(base_model_path)
28
+
29
+ # Protein sequence for inference
30
+ protein_sequence = "MAVPETRPNHTIYINNLNEKIKKDELKKSLHAIFSRFGQILDILVSRSLKMRGQAFVIFKEVSSATNALRSMQGFPFYDKPMRIQYAKTDSDIIAKMKGT" # Replace with your actual sequence
31
+
32
+ # Tokenize the sequence
33
+ inputs = loaded_tokenizer(protein_sequence, return_tensors="pt", truncation=True, max_length=1024, padding='max_length')
34
+
35
+ # Run the model
36
+ with torch.no_grad():
37
+ logits = loaded_model(**inputs).logits
38
+
39
+ # Get predictions
40
+ tokens = loaded_tokenizer.convert_ids_to_tokens(inputs["input_ids"][0]) # Convert input ids back to tokens
41
+ predictions = torch.argmax(logits, dim=2)
42
+
43
+ # Define labels
44
+ id2label = {
45
+ 0: "No binding site",
46
+ 1: "Binding site"
47
+ }
48
+
49
+ # Print the predicted labels for each token
50
+ for token, prediction in zip(tokens, predictions[0].numpy()):
51
+ if token not in ['<pad>', '<cls>', '<eos>']:
52
+ print((token, id2label[prediction]))
53
+ ```