|
--- |
|
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> |