AmelieSchreiber commited on
Commit
057fb11
1 Parent(s): 20d7597

Update README.md

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