Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1 |
---
|
2 |
license: bigscience-openrail-m
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: bigscience-openrail-m
|
3 |
---
|
4 |
+
|
5 |
+
|
6 |
+
how to use
|
7 |
+
|
8 |
+
```
|
9 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
10 |
+
import textwrap, time
|
11 |
+
|
12 |
+
MAX_NEW_TOKENS = 300
|
13 |
+
model_name = "acul3/bloomz-3b-Instruction"
|
14 |
+
|
15 |
+
model = AutoModelForCausalLM.from_pretrained(
|
16 |
+
model_name,
|
17 |
+
device_map='auto',
|
18 |
+
load_in_8bit= True
|
19 |
+
)
|
20 |
+
|
21 |
+
|
22 |
+
def generate_text(text):
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
24 |
+
text = "User: " + text + "\n\Asisten: "
|
25 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids.to("cuda")
|
26 |
+
generated_ids = model.generate(input_ids, max_length=MAX_NEW_TOKENS, pad_token_id=tokenizer.eos_token_id, do_sample=True, top_p=0.95, temperature=0.5, penalty_alpha=0.6, top_k=4, repetition_penalty=1.03, num_return_sequences=1)
|
27 |
+
result = textwrap.wrap(tokenizer.decode(generated_ids[0], skip_special_tokens=True), width=128)
|
28 |
+
result[0] = result[0].split("Asisten:")[-1]
|
29 |
+
return "\n".join(result)
|
30 |
+
|
31 |
+
print(generate_text("cara merebus telur"))
|
32 |
+
```
|