🚀 臺語- Llama - 2 翻譯器 7B 模型
臺語- Llama - 2 翻譯器系列基於臺語- Llama - 2 系列模型構建。我們在 263k 平行數據上進行了微調,創建了一個用於臺灣閩南語及相關語言的翻譯模型。
🚀 快速開始
臺語- Llama - 2 翻譯器系列模型基於臺語- Llama - 2 系列模型構建,通過在 263k 平行數據上微調,打造出可用於臺灣閩南語及相關語言的翻譯模型。
如需更多詳細信息,請參考我們的 GitHub 倉庫 和論文:Enhancing Taiwanese Hokkien Dual Translation by Exploring and Standardizing of Four Writing Systems。
您還可以在 臺灣閩南語大語言模型集合 中探索其他模型和數據集。
✨ 主要特性
- 多語言翻譯:該模型可用於繁體中文或英語與臺灣閩南語(漢字、白話字、漢羅)之間的翻譯,也支持臺灣閩南語不同書寫系統(漢字、白話字、漢羅)之間的翻譯。
- 語言支持:支持臺灣閩南語(漢字、白話字和漢羅)、繁體中文和英語。
- 輸入輸出:輸入源語言文本,輸出目標語言文本。
- 模型規模:具有 70 億參數。
📚 詳細文檔
模型描述
屬性 |
詳情 |
基礎模型 |
Bohanlu/Taigi-Llama-2-7B |
使用方式 |
可用於繁體中文或英語與臺灣閩南語(漢字、白話字、漢羅)之間的翻譯,也支持臺灣閩南語不同書寫系統(漢字、白話字、漢羅)之間的翻譯 |
語言 |
臺灣閩南語(漢字、白話字和漢羅)、繁體中文和英語 |
輸入 |
源語言文本 |
輸出 |
目標語言文本 |
模型規模 |
70 億參數 |
提示模板
{BOS}[TRANS]\n{source_sentence}\n[/TRANS]\n[{target_language}]\n
source_sentence
:您要翻譯的句子。
target_language
:您要翻譯到的目標語言。使用 "ZH" 表示繁體中文,"EN" 表示英語,"POJ" 表示臺灣閩南語白話字,"HL" 表示臺灣閩南語漢羅,"HAN" 表示臺灣閩南語漢字。
- 請確保末尾有換行符。
💻 使用示例
基礎用法
from transformers import AutoModelForCausalLM, AutoTokenizer, TextGenerationPipeline
import torch
import accelerate
def get_pipeline(path:str, tokenizer:AutoTokenizer, accelerator:accelerate.Accelerator) -> TextGenerationPipeline:
model = AutoModelForCausalLM.from_pretrained(
path, torch_dtype=torch.float16, device_map='auto', trust_remote_code=True)
terminators = [tokenizer.eos_token_id, tokenizer.pad_token_id]
pipeline = TextGenerationPipeline(model = model, tokenizer = tokenizer, num_workers=accelerator.state.num_processes*4, pad_token_id=tokenizer.pad_token_id, eos_token_id=terminators)
return pipeline
model_dir = "Bohanlu/Taigi-Llama-2-Translator-7B"
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=False)
accelerator = accelerate.Accelerator()
pipe = get_pipeline(model_dir, tokenizer, accelerator)
PROMPT_TEMPLATE = "[TRANS]\n{source_sentence}\n[/TRANS]\n[{target_language}]\n"
def translate(source_sentence:str, target_language:str) -> str:
prompt = PROMPT_TEMPLATE.format(source_sentence=source_sentence, target_language=target_language)
out = pipe(prompt, return_full_text=False, repetition_penalty=1.1, do_sample=False)[0]['generated_text']
return out[:out.find("[/")].strip()
source_sentence = "How are you today?"
print("To Hanzi: " + translate(source_sentence, "HAN"))
print("To POJ: " + translate(source_sentence, "POJ"))
print("To Traditional Chinese: " + translate(source_sentence, "ZH"))
print("To Hanlo: " + translate(source_sentence, "HL"))
📄 許可證
本項目遵循 CC - BY - NC - SA 4.0 許可證。
引用
如果您在工作中發現臺灣閩南語大語言模型集合中的資源有用,請使用以下引用:
@misc{lu2024enhancing,
title={Enhancing Taiwanese Hokkien Dual Translation by Exploring and Standardizing of Four Writing Systems},
author={Bo-Han Lu and Yi-Hsuan Lin and En-Shiun Annie Lee and Richard Tzong-Han Tsai},
year={2024},
eprint={2403.12024},
archivePrefix={arXiv},
primaryClass={cs.CL}
}