Update README.md
Browse files
README.md
CHANGED
@@ -1,52 +1,53 @@
|
|
1 |
-
---
|
2 |
-
library_name: transformers
|
3 |
-
license: apache-2.0
|
4 |
-
datasets:
|
5 |
-
-
|
6 |
-
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
import
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
1 |
+
---
|
2 |
+
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
datasets:
|
5 |
+
- DavidLanz/TaiwanChat
|
6 |
+
- benchang1110/pretrainedtw
|
7 |
+
- HuggingFaceTB/cosmopedia-100k
|
8 |
+
language:
|
9 |
+
- zh
|
10 |
+
widget:
|
11 |
+
- text: '在很久以前,這座島上'
|
12 |
+
example_title: Example1
|
13 |
+
|
14 |
+
---
|
15 |
+
|
16 |
+
# Model Card for Model ID
|
17 |
+
|
18 |
+
This is a continue-pretrained version of [Tinyllama](TinyLlama/TinyLlama-1.1B-intermediate-step-1431k-3T) tailored for traditional Chinese. The continue-pretraining dataset contains roughly 2B tokens.
|
19 |
+
|
20 |
+
# Usage
|
21 |
+
```python
|
22 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
23 |
+
import torch
|
24 |
+
|
25 |
+
def generate_response(input):
|
26 |
+
'''
|
27 |
+
simple test for the model
|
28 |
+
'''
|
29 |
+
# tokenzize the input
|
30 |
+
tokenized_input = tokenizer.encode_plus(input, return_tensors='pt').to(device)
|
31 |
+
|
32 |
+
# generate the response
|
33 |
+
outputs = model.generate(
|
34 |
+
input_ids=tokenized_input['input_ids'],
|
35 |
+
attention_mask=tokenized_input['attention_mask'],
|
36 |
+
pad_token_id=tokenizer.pad_token_id,
|
37 |
+
do_sample=False,
|
38 |
+
repetition_penalty=1.3,
|
39 |
+
max_length=500
|
40 |
+
)
|
41 |
+
|
42 |
+
# decode the response
|
43 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
44 |
+
|
45 |
+
if __name__ == '__main__':
|
46 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
47 |
+
model = AutoModelForCausalLM.from_pretrained("DavidLanz/Taiwan-tinyllama-v1.0-chat",device_map=device,torch_dtype=torch.bfloat16)
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained("DavidLanz/Taiwan-tinyllama-v1.0-chat")
|
49 |
+
while(True):
|
50 |
+
text = input("input a simple prompt:")
|
51 |
+
print('System:', generate_response(text))
|
52 |
+
```
|
53 |
+
Using bfloat16, the VRAM required is around 3GB!!!
|