feat: improve example
Browse files
README.md
CHANGED
@@ -10,6 +10,32 @@ Program synthesis strives to generate a computer program as a solution to a give
|
|
10 |
|
11 |
# How to use
|
12 |
```python
|
|
|
|
|
|
|
13 |
tokenizer = AutoTokenizer.from_pretrained("shpotes/codegen-350M-mono")
|
14 |
model = AutoModelForCausalLM.from_pretrained("shpotes/codegen-350M-mono", trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
```
|
|
|
10 |
|
11 |
# How to use
|
12 |
```python
|
13 |
+
import torch
|
14 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
15 |
+
|
16 |
tokenizer = AutoTokenizer.from_pretrained("shpotes/codegen-350M-mono")
|
17 |
model = AutoModelForCausalLM.from_pretrained("shpotes/codegen-350M-mono", trust_remote_code=True)
|
18 |
+
|
19 |
+
input_ids = tokenizer(
|
20 |
+
context,
|
21 |
+
truncation=True,
|
22 |
+
padding=True,
|
23 |
+
return_tensors='pt',
|
24 |
+
pad_token_id=pad_token_id,
|
25 |
+
).input_ids
|
26 |
+
|
27 |
+
input_ids_len = input_ids.shape[1]
|
28 |
+
|
29 |
+
with torch.no_grad():
|
30 |
+
input_ids = input_ids
|
31 |
+
tokens = model.generate(
|
32 |
+
input_ids,
|
33 |
+
do_sample=True,
|
34 |
+
num_return_sequences=num_return_sequences,
|
35 |
+
temperature=temp,
|
36 |
+
max_length=input_ids_len + max_length_sample,
|
37 |
+
top_p=top_p,
|
38 |
+
use_cache=True,
|
39 |
+
)
|
40 |
+
text = tokenizer.batch_decode(tokens[:, input_ids_len:, ...])
|
41 |
```
|