Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,43 @@
|
|
1 |
-
---
|
2 |
-
license: bsd-3-clause
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: bsd-3-clause
|
3 |
+
---
|
4 |
+
# ProGen2-small
|
5 |
+
|
6 |
+
HF mirror for ProGen2-small for **Protein Engineering**
|
7 |
+
|
8 |
+
[Official GitHub](https://github.com/salesforce/progen/tree/main/progen2) of [ProGen2 by Nijkamp et al.](https://www.cell.com/cell-systems/fulltext/S2405-4712(23)00272-7).
|
9 |
+
|
10 |
+
- The ProGen2 suite of protein language models are scaled to 6.4B parameters
|
11 |
+
- Models with increased scale better capture the distribution of protein sequences
|
12 |
+
- ProGen2 models generate novel protein sequences adopting natural folds
|
13 |
+
- ProGen2 model likelihoods are effective for zero-shot fitness prediction
|
14 |
+
|
15 |
+
```python
|
16 |
+
import torch
|
17 |
+
from faesm.progen2 import ProGenForCausalLM
|
18 |
+
from transformers import AutoTokenizer
|
19 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
20 |
+
model = ProGenForCausalLM.from_pretrained("jinyuan22/ProGen2-xlarge").to(torch.float16).to(device).eval()
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained("jinyuan22/ProGen2-xlarge")
|
22 |
+
|
23 |
+
# sequence = "1" + "ACDEFGHIKLMNPQRSTVWY" * 50 + "2" # 1002 token
|
24 |
+
|
25 |
+
sequence = "2GFLPFRGADEGLAAREAATLAARGTAARAYREDSWAVPVPRGLLGDLTARVAALGAASPPPADPLAVTLDLHHVTAEVALTTVLDAATLVHGQTRVLSAEDAAEAATAAAAATEAYLERLQDFVLFMSASVRVWRRGNAAGATGPEWDQWYTVADRDALGSAPTHLAVLGRQADALCHFVLDRVAWGTCGTPLWSGDEDLGNVVATFAGYADRLATAPRDLIM1"
|
26 |
+
|
27 |
+
inputs = tokenizer(sequence, return_tensors="pt").to(device)
|
28 |
+
|
29 |
+
with torch.no_grad():
|
30 |
+
logits = model(inputs.input_ids, labels=inputs.input_ids).logits
|
31 |
+
|
32 |
+
logits = logits[0][:-1, ...]
|
33 |
+
target = inputs.input_ids[0, 1:]
|
34 |
+
|
35 |
+
# remove unused logits
|
36 |
+
first_token, last_token = 5, 29
|
37 |
+
logits = logits[:, first_token:(last_token+1)]
|
38 |
+
target = target - first_token
|
39 |
+
|
40 |
+
ce_eval = torch.nn.functional.cross_entropy(input=logits.view(-1, logits.size(-1)), target=target.view(-1), reduction="mean").item()
|
41 |
+
print(ce_eval)
|
42 |
+
assert abs(ce_eval - 1.0) < 0.1
|
43 |
+
```
|