AmelieSchreiber commited on
Commit
c726944
1 Parent(s): 287b523

Update README.md

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