Update README.md
Browse files
README.md
CHANGED
@@ -11,17 +11,18 @@ Example usage:
|
|
11 |
|
12 |
```python
|
13 |
from transformers import AutoModelForCausalLM
|
14 |
-
from
|
15 |
import torch
|
16 |
import torch.nn.functional as F
|
17 |
|
18 |
# load model and tokenizer
|
19 |
-
model = AutoModelForCausalLM.from_pretrained("hugohrban/progen2-small", trust_remote_code=True)
|
20 |
-
tokenizer =
|
|
|
21 |
|
22 |
# prepare input
|
23 |
prompt = "1MEVVIVTGMSGAGK"
|
24 |
-
input_ids = torch.tensor(tokenizer.encode(prompt)).to(model.device)
|
25 |
|
26 |
# forward pass
|
27 |
logits = model(input_ids).logits
|
@@ -29,6 +30,6 @@ logits = model(input_ids).logits
|
|
29 |
# print output probabilities
|
30 |
next_token_logits = logits[-1, :]
|
31 |
next_token_probs = F.softmax(next_token_logits, dim=-1)
|
32 |
-
for i
|
33 |
-
print(f"{tokenizer.
|
34 |
```
|
|
|
11 |
|
12 |
```python
|
13 |
from transformers import AutoModelForCausalLM
|
14 |
+
from tokenizers import Tokenizer
|
15 |
import torch
|
16 |
import torch.nn.functional as F
|
17 |
|
18 |
# load model and tokenizer
|
19 |
+
model = AutoModelForCausalLM.from_pretrained("hugohrban/progen2-small-mix7", trust_remote_code=True)
|
20 |
+
tokenizer = Tokenizer.from_pretrained("hugohrban/progen2-small-mix7")
|
21 |
+
tokenizer.no_padding()
|
22 |
|
23 |
# prepare input
|
24 |
prompt = "1MEVVIVTGMSGAGK"
|
25 |
+
input_ids = torch.tensor(tokenizer.encode(prompt).ids).to(model.device)
|
26 |
|
27 |
# forward pass
|
28 |
logits = model(input_ids).logits
|
|
|
30 |
# print output probabilities
|
31 |
next_token_logits = logits[-1, :]
|
32 |
next_token_probs = F.softmax(next_token_logits, dim=-1)
|
33 |
+
for i in range(tokenizer.get_vocab_size(with_added_tokens=False)):
|
34 |
+
print(f"{tokenizer.id_to_token(i)}: {round(100 * next_token_probs[i].item(), 2):.2f} %")
|
35 |
```
|