dreamerdeo
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -70,53 +70,31 @@ Refer to [Sailor2 Website](https://sailorllm.github.io/) for more training detai
|
|
70 |
## Requirements
|
71 |
The code of Sailor2 has been in the latest Hugging face transformers and we advise you to install `transformers==4.46.3`.
|
72 |
|
73 |
-
|
74 |
|
75 |
Here provides a code snippet to show you how to load the tokenizer and model and how to generate contents.
|
76 |
|
77 |
```python
|
78 |
-
import torch
|
79 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
80 |
-
device = "cuda"
|
81 |
|
82 |
-
model = AutoModelForCausalLM.from_pretrained(
|
83 |
-
|
84 |
-
torch_dtype=torch.bfloat16,
|
85 |
-
device_map="auto"
|
86 |
-
)
|
87 |
-
|
88 |
-
tokenizer = AutoTokenizer.from_pretrained('sail/Sailor2-1B-Chat')
|
89 |
-
system_prompt= \
|
90 |
-
'You are an AI assistant named Sailor2, created by Sea AI Lab. \
|
91 |
-
As an AI assistant, you can answer questions in English, Chinese, and Southeast Asian languages \
|
92 |
-
such as Burmese, Cebuano, Ilocano, Indonesian, Javanese, Khmer, Lao, Malay, Sundanese, Tagalog, Thai, Vietnamese, and Waray. \
|
93 |
-
Your responses should be friendly, unbiased, informative, detailed, and faithful.'
|
94 |
-
|
95 |
-
prompt = "Beri saya pengenalan singkat tentang model bahasa besar."
|
96 |
-
# prompt = "Hãy cho tôi một giới thiệu ngắn gọn về mô hình ngôn ngữ lớn."
|
97 |
-
# prompt = "ให้ฉันแนะนำสั้น ๆ เกี่ยวกับโมเดลภาษาขนาดใหญ่"
|
98 |
|
99 |
-
|
100 |
-
|
101 |
-
{"role": "user", "content": prompt}
|
102 |
-
]
|
103 |
-
text = tokenizer.apply_chat_template(
|
104 |
-
messages,
|
105 |
-
tokenize=False,
|
106 |
-
add_generation_prompt=True
|
107 |
-
)
|
108 |
|
109 |
-
model_inputs = tokenizer([
|
110 |
-
input_ids = model_inputs.input_ids.to(device)
|
111 |
|
112 |
generated_ids = model.generate(
|
113 |
-
input_ids,
|
114 |
-
max_new_tokens=
|
115 |
)
|
116 |
|
117 |
generated_ids = [
|
118 |
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
119 |
]
|
|
|
120 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
121 |
print(response)
|
122 |
```
|
|
|
70 |
## Requirements
|
71 |
The code of Sailor2 has been in the latest Hugging face transformers and we advise you to install `transformers==4.46.3`.
|
72 |
|
73 |
+
### Quickstart
|
74 |
|
75 |
Here provides a code snippet to show you how to load the tokenizer and model and how to generate contents.
|
76 |
|
77 |
```python
|
|
|
78 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
79 |
+
device = "cuda" # the device to load the model
|
80 |
|
81 |
+
model = AutoModelForCausalLM.from_pretrained("sail/Sailor2-1B", device_map="auto")
|
82 |
+
tokenizer = AutoTokenizer.from_pretrained("sail/Sailor2-1B")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
input_message = "Model bahasa adalah model probabilistik"
|
85 |
+
### The given Indonesian input translates to 'A language model is a probabilistic model of.'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
model_inputs = tokenizer([input_message], return_tensors="pt").to(device)
|
|
|
88 |
|
89 |
generated_ids = model.generate(
|
90 |
+
model_inputs.input_ids,
|
91 |
+
max_new_tokens=64
|
92 |
)
|
93 |
|
94 |
generated_ids = [
|
95 |
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
96 |
]
|
97 |
+
|
98 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
99 |
print(response)
|
100 |
```
|