Update README.md
Browse files
README.md
CHANGED
|
@@ -10,4 +10,32 @@ library_name: adapter-transformers
|
|
| 10 |
tags:
|
| 11 |
- biology
|
| 12 |
pipeline_tag: text-classification
|
| 13 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
tags:
|
| 11 |
- biology
|
| 12 |
pipeline_tag: text-classification
|
| 13 |
+
---
|
| 14 |
+
## Example
|
| 15 |
+
```
|
| 16 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 17 |
+
import torch
|
| 18 |
+
|
| 19 |
+
# Load the fine-tuned model and tokenizer
|
| 20 |
+
model_name = "sihuapeng/ESM2-finetuned-PPSL"
|
| 21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 22 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 23 |
+
|
| 24 |
+
# Simulate a protein sequence
|
| 25 |
+
protein_sequence = "MSKKVLITGGAGYIGSVLTPILLEKGYEVCVIDNLMFDQISLLSCFHNKNFTFINGDAMDENLIRQEVAKADIIIPLAALVGAPLCKRNPKLAKMINYEAVKMISDFASPSQIFIYPNTNSGYGIGEKDAMCTEESPLRPISEYGIDKVHAEQYLLDKGNCVTFRLATVFGISPRMRLDLLVNDFTYRAYRDKFIVLFEEHFRRNYIHVRDVVKGFIHGIENYDKMKGQAYNMGLSSANLTKRQLAETIKKYIPDFYIHSANIGEDPDKRDYLVSNTKLEATGWKPDNTLEDGIKELLRAFKMMKVNRFANFN"
|
| 26 |
+
|
| 27 |
+
# Encode the sequence as model input
|
| 28 |
+
inputs = tokenizer(protein_sequence, return_tensors="pt")
|
| 29 |
+
|
| 30 |
+
# Perform inference using the model
|
| 31 |
+
with torch.no_grad():
|
| 32 |
+
outputs = model(**inputs)
|
| 33 |
+
|
| 34 |
+
# Get the prediction results
|
| 35 |
+
logits = outputs.logits
|
| 36 |
+
predicted_class_id = torch.argmax(logits, dim=-1).item()
|
| 37 |
+
|
| 38 |
+
# Output the predicted class
|
| 39 |
+
print(f"Predicted class ID: {predicted_class_id}")
|
| 40 |
+
|
| 41 |
+
```
|