AmelieSchreiber commited on
Commit
c131a47
1 Parent(s): b90e0fc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -0
README.md CHANGED
@@ -21,4 +21,54 @@ tags:
21
  'eval_f1': 0.5140592704923245,
22
  'eval_auc': 0.797965030682904,
23
  'eval_mcc': 0.5074876628479288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  ```
 
21
  'eval_f1': 0.5140592704923245,
22
  'eval_auc': 0.797965030682904,
23
  'eval_mcc': 0.5074876628479288
24
+ ```
25
+
26
+ ## Using the Model
27
+
28
+ To use the model, run the following:
29
+
30
+ ```python
31
+ from transformers import AutoModelForTokenClassification, AutoTokenizer
32
+ from peft import PeftModel
33
+ import torch
34
+
35
+ # Path to the saved LoRA model
36
+ model_path = "AmelieSchreiber/esm2_t33_650M_qlora_binding_16M"
37
+ # ESM2 base model
38
+ base_model_path = "facebook/esm2_t33_650M_UR50D"
39
+
40
+ # Load the model
41
+ base_model = AutoModelForTokenClassification.from_pretrained(base_model_path)
42
+ loaded_model = PeftModel.from_pretrained(base_model, model_path)
43
+
44
+ # Ensure the model is in evaluation mode
45
+ loaded_model.eval()
46
+
47
+ # Load the tokenizer
48
+ loaded_tokenizer = AutoTokenizer.from_pretrained(base_model_path)
49
+
50
+ # Protein sequence for inference
51
+ protein_sequence = "MAVPETRPNHTIYINNLNEKIKKDELKKSLHAIFSRFGQILDILVSRSLKMRGQAFVIFKEVSSATNALRSMQGFPFYDKPMRIQYAKTDSDIIAKMKGT" # Replace with your actual sequence
52
+
53
+ # Tokenize the sequence
54
+ inputs = loaded_tokenizer(protein_sequence, return_tensors="pt", truncation=True, max_length=1024, padding='max_length')
55
+
56
+ # Run the model
57
+ with torch.no_grad():
58
+ logits = loaded_model(**inputs).logits
59
+
60
+ # Get predictions
61
+ tokens = loaded_tokenizer.convert_ids_to_tokens(inputs["input_ids"][0]) # Convert input ids back to tokens
62
+ predictions = torch.argmax(logits, dim=2)
63
+
64
+ # Define labels
65
+ id2label = {
66
+ 0: "No binding site",
67
+ 1: "Binding site"
68
+ }
69
+
70
+ # Print the predicted labels for each token
71
+ for token, prediction in zip(tokens, predictions[0].numpy()):
72
+ if token not in ['<pad>', '<cls>', '<eos>']:
73
+ print((token, id2label[prediction]))
74
  ```