
# Taiwan Words Translator 繁體中文台灣化翻譯器 by LLMs

<!-- Provide a quick summary of what the model is/does. -->

https://github.com/SuJiaKuan/llm_tw_word

The model supports translation that converts text with China words to text with only Taiwan words. Example:
- Input: `這個軟件的質量真高啊`
- Output: `這個軟體的品質真高啊`

#### This Model

This model is fine-tuned from [TinyLlama/TinyLlama-1.1B-Chat-v1.0](https://huggingface.co/TinyLlama/TinyLlama-1.1B-Chat-v1.0) (by applying Instruction Finetuning). The dataset is collected from [MBZUAI/Bactrian-X](https://huggingface.co/datasets/MBZUAI/Bactrian-X) and automatically labeled by [繁化姬](https://zhconvert.org).

#### How to use
You can follow the example usage below, or see [here](https://github.com/SuJiaKuan/llm_tw_word/blob/main/llm_tw_word/translate.py) to know how to integrate the model into a Python class.

```python
import torch
from transformers import pipeline

SYSTEM_PROMPT = """\
對於輸入內容的中文文字，請將中國用語轉成台灣的用語，其他非中文文字或非中國用語都維持不變。

範例：
Input: ```這個視頻的質量真高啊```
Output: ```這個影片的品質真高啊```\
"""

text_trad = "這個軟件的質量真高啊"

pipeline = pipeline(
    "text-generation",
    model="feabries/TaiwanWordTranslator-v0.1",
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

prompt = "Input: ```{}```".format(text_trad)
messages = [{
    "role": "system",
    "content": SYSTEM_PROMPT,
}, {
    "role": "user",
    "content": prompt,
}]
input_text = pipeline.tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True,
)
outputs = pipeline(
    input_text,
    do_sample=False,
    max_new_tokens=2048,
)
print(outputs[0]["generated_text"])
# <|system|>
# 對於輸入內容的中文文字，請將中國用語轉成台灣的用語，其他非中文文字或非中國用語都維持不變。
# 
# 範例：
# Input: ```這個視頻的質量真高啊```
# Output: ```這個影片的品質真高啊```</s>
# <|user|>
# Input: ```這個軟件的質量真高啊```</s>
# <|assistant|>
# Output: ```這個軟體的品質真高啊```
```
{"language": ["zh"], "license": "agpl-3.0", "tags": ["traditional chinese", "zh-tw", "zh-hant", "taiwan"], "datasets": ["MBZUAI/Bactrian-X"], "widget": [{"text": "<|system|>\n\u5c0d\u65bc\u8f38\u5165\u5167\u5bb9\u7684\u4e2d\u6587\u6587\u5b57\uff0c\u8acb\u5c07\u4e2d\u570b\u7528\u8a9e\u8f49\u6210\u53f0\u7063\u7684\u7528\u8a9e\uff0c\u5176\u4ed6\u975e\u4e2d\u6587\u6587\u5b57\u6216\u975e\u4e2d\u570b\u7528\u8a9e\u90fd\u7dad\u6301\u4e0d\u8b8a\u3002\n\n\u7bc4\u4f8b\uff1a\nInput: ```\u9019\u500b\u8996\u983b\u7684\u8cea\u91cf\u771f\u9ad8\u554a```\nOutput: ```\u9019\u500b\u5f71\u7247\u7684\u54c1\u8cea\u771f\u9ad8\u554a```</s>\n<|user|>\nInput: ```\u9019\u500b\u8edf\u4ef6\u7684\u8cea\u91cf\u771f\u9ad8\u554a```</s>\n<|assistant|>\nOutput: "}, {"text": "<|system|>\n\u5c0d\u65bc\u8f38\u5165\u5167\u5bb9\u7684\u4e2d\u6587\u6587\u5b57\uff0c\u8acb\u5c07\u4e2d\u570b\u7528\u8a9e\u8f49\u6210\u53f0\u7063\u7684\u7528\u8a9e\uff0c\u5176\u4ed6\u975e\u4e2d\u6587\u6587\u5b57\u6216\u975e\u4e2d\u570b\u7528\u8a9e\u90fd\u7dad\u6301\u4e0d\u8b8a\u3002\n\n\u7bc4\u4f8b\uff1a\nInput: ```\u9019\u500b\u8996\u983b\u7684\u8cea\u91cf\u771f\u9ad8\u554a```\nOutput: ```\u9019\u500b\u5f71\u7247\u7684\u54c1\u8cea\u771f\u9ad8\u554a```</s>\n<|user|>\nInput: ```\u6211\u5011\u5efa\u7acb\u4e86\u6578\u64da\u5eab\uff0c\u7528\u4f86\u5132\u5b58\u548c\u7ba1\u7406\u7dda\u4e0a\u670d\u52d9\u7684\u4fe1\u606f```</s>\n<|assistant|>\nOutput: "}]}
transformers safetensors llama text-generation traditional chinese zh-tw zh-hant taiwan conversational zh dataset:MBZUAI/Bactrian-X license:agpl-3.0 autotrain_compatible endpoints_compatible text-generation-inference region:us