Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: cc-by-nc-sa-4.0
|
3 |
+
---
|
4 |
+
<p align="center">
|
5 |
+
<img src="https://github.com/lbh0830/TW-Hokkien-LLM/blob/main/pics/logo.jpg?raw=true" alt="Taigi-llama-logo" width="350">
|
6 |
+
</p>
|
7 |
+
|
8 |
+
# Model Card for Taigi-Llama-2-13B
|
9 |
+
Taigi-Llama-2 series are built based on the Traditional Chinese version of the LLaMA-2 model. We conducted continued pre-training on web-scraped data in Taiwanese Hokkien, including Hanzi, POJ, and Hanlo, totaling around 78MB.
|
10 |
+
|
11 |
+
For more details, please refer to our [GitHub repository](https://github.com/lbh0830/TW-Hokkien-LLM/tree/main) and the paper: [Enhancing Taiwanese Hokkien Dual Translation by Exploring and Standardizing of Four Writing Systems](https://arxiv.org/abs/2403.12024)
|
12 |
+
|
13 |
+
Explore other models and datasets in the [Taiwanese Hokkien LLM collection](https://huggingface.co/collections/Bohanlu/taiwanese-hokkien-llm-6614ba7456e6789bc2f10ca0).
|
14 |
+
|
15 |
+
## Model description
|
16 |
+
|
17 |
+
- **Usage:** This model can be used for causal language modeling tasks in Taiwanese Hokkien. It is also suitable for further fine-tuning on specific datasets for downstream tasks.
|
18 |
+
- **Language(s) (NLP):** The primary language is Taiwanese Hokkien (Hanzi and POJ). The model also retains capabilities in English and Mandarin Chinese due to prior pre-training.
|
19 |
+
- **Input:** Text
|
20 |
+
- **Output:** Text
|
21 |
+
- **Model Size:** 13B parameters
|
22 |
+
|
23 |
+
## Usage Example
|
24 |
+
```
|
25 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextGenerationPipeline
|
26 |
+
import torch
|
27 |
+
import accelerate
|
28 |
+
|
29 |
+
def get_pipeline(path:str, tokenizer:AutoTokenizer, accelerator:accelerate.Accelerator) -> TextGenerationPipeline:
|
30 |
+
model = AutoModelForCausalLM.from_pretrained(
|
31 |
+
path, torch_dtype=torch.float16, device_map='auto', trust_remote_code=True)
|
32 |
+
|
33 |
+
terminators = [tokenizer.eos_token_id, tokenizer.pad_token_id]
|
34 |
+
|
35 |
+
pipeline = TextGenerationPipeline(model = model, tokenizer = tokenizer, num_workers=accelerator.state.num_processes*4, pad_token_id=tokenizer.pad_token_id, eos_token_id=terminators)
|
36 |
+
|
37 |
+
return pipeline
|
38 |
+
|
39 |
+
model_dir = "Bohanlu/Taigi-Llama-2-7B" # or Bohanlu/Taigi-Llama-2-13B for the 13B model
|
40 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=False)
|
41 |
+
|
42 |
+
accelerator = accelerate.Accelerator()
|
43 |
+
pipe = get_pipeline(model_dir, tokenizer, accelerator)
|
44 |
+
|
45 |
+
# Few-shot示例:問答
|
46 |
+
qa_prompt = """Example 1:
|
47 |
+
問題:台北101有偌懸?
|
48 |
+
答案:台北101的高度是五百空八公尺。
|
49 |
+
|
50 |
+
Example 2:
|
51 |
+
問題:台灣上長的溪仔是佗一條?
|
52 |
+
答案:台灣上長的溪仔是濁水溪,規个長度有百八公里遐爾長。
|
53 |
+
|
54 |
+
Example 3:
|
55 |
+
問題:臺灣上懸的山是啥物?
|
56 |
+
答案:"""
|
57 |
+
|
58 |
+
print(pipe(qa_prompt, return_full_text=False))
|
59 |
+
>>> [{'generated_text': '臺灣上懸的山是玉山,海拔三千九百五十二公尺。'}]
|
60 |
+
```
|
61 |
+
|
62 |
+
## Citation
|
63 |
+
|
64 |
+
If you find the resources in the Taiwanese Hokkien LLM collection useful in your work, please cite it using the following reference:
|
65 |
+
|
66 |
+
```
|
67 |
+
@misc{lu2024enhancing,
|
68 |
+
title={Enhancing Taiwanese Hokkien Dual Translation by Exploring and Standardizing of Four Writing Systems},
|
69 |
+
author={Bo-Han Lu and Yi-Hsuan Lin and En-Shiun Annie Lee and Richard Tzong-Han Tsai},
|
70 |
+
year={2024},
|
71 |
+
eprint={2403.12024},
|
72 |
+
archivePrefix={arXiv},
|
73 |
+
primaryClass={cs.CL}
|
74 |
+
}
|
75 |
+
```
|