File size: 2,306 Bytes
016b28c
c0e5a8d
 
 
6b75dc3
f5a6d3e
 
89cdda1
 
 
 
 
 
 
7a83b55
89cdda1
7a83b55
 
f0736df
f4fe3cc
 
 
324444c
 
f0736df
324444c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782f67a
324444c
 
 
 
 
 
 
 
782f67a
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
language:
- th
- en
license: cc-by-nc-3.0
datasets:
- airesearch/concat_six_dataset_th_en
---

# typhoon-7b-WangchanX-sft-Demo

This model is based on [WangchanX Fine-tuning Pipeline](https://github.com/vistec-AI/WangchanX).

GitHub: [WangchanX Fine-tuning Pipeline](https://github.com/vistec-AI/WangchanX).
Pre-train model from scb10x/typhoon-7b and fine tuning with Qlora.

License: cc-by-nc-3.0

## Train Example

Train WangchanX pipeline: [Colab](https://colab.research.google.com/github/vistec-AI/WangchanX/blob/main/notebooks/Train_WangchanX_pipeline.ipynb)

## Inference Example

Run on [Colab](https://colab.research.google.com/drive/1PeUnv89Ao2uHRYYzZVOlUwoBUdYKFbLS?usp=sharing)

### Prepare your model and tokenizer:

```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

# Model path
path = "airesearch/typhoon-7b-WangchanX-sft-Demo"

# Device
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(path, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(path, device_map="auto")
```

### Define chat messages:

```python
messages = [
    {"role": "user", "content": "ลิเก กับ งิ้ว ต่างกันอย่างไร"},
]
```

### Tokenize chat messages:

```python
tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(device)
print(tokenizer.decode(tokenized_chat[0]))
```

<details close>
  <summary>Output: </summary>
  <br>
    <pre lang="markdown">
<|user|>
ลิเก กับ งิ้ว ต่างกันอย่างไร</s>
<|assistant|></pre>
</details>

### Generate responses:

```python
outputs = model.generate(tokenized_chat, max_length=2048)
print(tokenizer.decode(outputs[0]))
```


<details close>
  <summary>Output: </summary>
  <br>
    <pre lang="markdown">
<|user|>
ลิเก กับ งิ้ว ต่างกันอย่างไร</s> 
<|assistant|>
ต่างกันที่วัฒนธรรมการแสดง ลิเกเป็นละครเพลงของไทย ส่วนงิ้วเป็นการแสดงพื้นบ้านของจีน</s></pre>
</details>