Llama-3-Taiwan-8B 是基于 Llama-3 架构在大量繁体中文和英文数据语料库上进行微调的 8B 参数模型。它在各种繁体中文 NLP 基准测试中展现出最先进的性能。

8B

262 拉取 更新于6周前

README

来源:https://hugging-face.cn/yentinglin/Llama-3-Taiwan-8B-Instruct

Taiwan LLM Logo

🚀 演示网站

twllm.com 上交互式体验 Llama-3-Taiwan

⚔️ 聊天机器人竞技场

参与精彩绝伦的 聊天机器人竞技场,与其他聊天机器人一较高下!

🚀 我们激动地推出 Llama-3-Taiwan-70B!Llama-3-Taiwan-70B 是一个在大量繁体中文和英文数据集上使用 Llama-3 架构微调的 70B 参数模型。它在多个繁体中文 NLP 基准测试中展现了最先进的性能。

该模型采用以 NVIDIA DGX H100 系统构建的 NVIDIA NeMo™ 框架进行训练。

Llama-3-Taiwan-70B的训练与数据由 Chang Gung Memorial Hospital(https://www.cgmh.org.tw/eng)、Chang Chun Group(https://www.ccp.com.tw/ccpweb.nsf/homepage?openagent)、Legalsign.ai(https://legalsign.ai/)、NVIDIA(https://www.nvidia.com/zh-tw/)、Pegatron(https://www.pegatroncorp.com/)、TechOrange(https://buzzorange.com/techorange/)和 Unimicron(https://www.unimicron.com/)(按字母顺序排列)慷慨赞助。

我们感谢数据提供者、团队成员和顾问在模型开发中的贡献,包括 shasha77(https://www.youtube.com/@shasha77)为高质量YouTube脚本和学习材料作出了贡献,Taiwan AI Labs(https://ailabs.tw/)提供了本地媒体内容,Ubitus K.K.(https://ubitus.net/zh/)提供了游戏内容,陈允瓴(Vivian)教授的指导和咨询,陈维麟领导我们的预训练数据管道工程,林子韓负责合成数据处理,高長聖增强我们的合成数据质量,以及陳楷傑负责清洗指令遵循数据。

模型摘要

Llama-3-Taiwan-70B是一个针对繁体中文和英语用户进行微调的大规模语言模型。它在语言理解、生成、推理和多轮对话方面具有很强的能力。主要特性包括

  • 70B个参数
  • 语言:繁体中文(zh-tw),英语(en)
  • 在包括法律、制造、医疗和电子领域的知识在内的优质繁体中文和英语语料库上进行微调
  • 8K上下文长度
  • 在Llama-3许可证下开放模型

训练细节

  • 训练框架:NVIDIA NeMo(https://www.nvidia.com/zh-tw/ai-data-science/products/nemo/)、NVIDIA NeMo Megatron(https://docs.nvda.net.cn/nemo-framework/user-guide/latest/nemotoolkit/nlp/megatron.html)
  • 推理框架:NVIDIA TensorRT-LLM(https://github.com/NVIDIA/TensorRT-LLM)
  • 基础模型:Llama-3 70B(https://llama.meta.com/llama3/)
  • 硬件:台北1号的NVIDIA DGX H100(https://www.nvidia.com/zh-tw/data-center/dgx-h100/)
  • 上下文长度:8K个token(128k版本(https://hugging-face.cn/yentinglin/Llama-3-Taiwan-70B-Instruct-128k))
  • 批量大小:每步2M个token

评估

查看Open TW LLM排行榜以获取完整和最新的列表。

模型 TMLU 台湾真实问答 法律评估 TW MT-Bench 长上下文 函数调用 TMMLU+
学科知识 台湾本地化测试 台湾法律考题 中文多轮对话 长文本支持 函数调用
yentinglin/Llama-3-Taiwan-70B-Instruct 74.76% 80.95% 68.42% 7.54 128k版本 67.53%
yentinglin/Llama-3-Taiwan-70B-Instruct-DPO 74.60% 81.75% 70.33% - - -
yentinglin/Llama-3-Taiwan-70B-Instruct-128k 73.01% 80.16% 63.64% - - -
yentinglin/Llama-3-Taiwan-8B-Instruct 59.50% 61.11% 53.11% 7.21 128k版本 52.28%
yentinglin/Llama-3-Taiwan-8B-Instruct-DPO 59.88% 59.52% 52.63% - - -
yentinglin/Llama-3-Taiwan-8B-Instruct-128k - - - - - -
Claude-3-Opus 73.59% (5-shot) 69.84% 60.29% - 200k -
GPT4-o 65.56% (0-shot), 69.88% (5-shot) 76.98% 53.59% - 128k -
GPT4-turbo 70.42% (5-shot) - - - 128k 60.34%^
Gemini-Pro 61.40% (5-shot) - - - 1000k 49.92%^
GPT-3.5-turbo-1106 49.37% (5-shot) - - 7.1 128k 41.76%^
Qwen1.5-110B-Chat 75.69% 66.67% 49.28% - 32k 65.81%
Yi-34B-Chat 73.59% 71.43% 55.02% 6.9 200k 64.10%
Meta-Llama-3-70B-Instruct 70.95% 65.08% 52.63% - 8k 62.75%
Mixtral-8x22B-Instruct-v0.1 55.57% 52.38% 44.98% - 64k 52.16%
Breexe-8x7B-Instruct-v0_1 - - - 7.2 8k 48.92%
c4ai-command-r-plus 62.87% 64.29% 34.45% - 128k 49.75%
Meta-Llama-3-8B-Instruct 55.81% 46.83% 35.89% - 8k 43.38%
Breeze-7B-Instruct-v1_0 55.57% 52.38% 39.23% 6.0 32k 41.77%
Llama3-TAIDE-LX-8B-Chat-Alpha1 47.30% 50.79% 37.80% - 8k 39.03%
Phi-3-mini-4k-instruct 40.97% 37.30% 27.27% - 4k 33.02%

数值默认为0-shot。

评估实现

^ 取自原始数据集中最接近的匹配值。

针线寻线评估

“针线寻线”评估测试模型在大量文本中定位和回忆嵌入的重要信息的能力,使用了著名的中文文本《出师表》。

要运行评估,请使用 脚本

TW MT-Bench分数

image/png

应用场景

Llama-3-Taiwan-70B 可应用于多种繁体中文和英文 NLP 任务,包括:

1. 多轮对话
System: You are an AI assistant called Twllm, created by TAME (TAiwan Mixture of Expert) project.

User: 嗨,你好!

Assistant: 你好!我今天可以如何協助你?

User: 就想聊天而已....

Assistant: 當然,我很樂意和你聊天!有什麼特別想談論的嗎?
2. RAG(检索增强生成)演示:可以在 [twllm.com](https://twllm.com/) 打开 `Search Web` ![image/png](https://cdn-uploads.huggingface.co/production/uploads/5df9c78eda6d0311fd3d541f/Zcl20NsPmY2vObIaMtT8G.png) ![image/png](https://cdn-uploads.huggingface.co/production/uploads/5df9c78eda6d0311fd3d541f/xuXEHIkMgDEB7xxDd3JoL.png)
System: You are an AI assistant called Twllm, created by TAME (TAiwan Mixture of Expert) project.

User: 明天台大天氣如何?

Assistant: 根據天氣預報,明天台大天氣為陣雨。低溫 24°C。10 到 15 公里/小時 的 東 風 。降雨機率為 40%。
3. 格式化输出,语言理解,实体识别,函数调用如果您对函数调用感兴趣,我强烈推荐使用 [约束解码](https://hugging-face.cn/docs/text-generation-inference/basic_tutorials/using_guidance) 打开 `json mode`。来自李宏毅的《生成式 AI 2024 春季》HW7 中的示例 ![image/png](https://cdn-uploads.huggingface.co/production/uploads/5df9c78eda6d0311fd3d541f/dCGo92llL3_ammH_Nu2-c.png)
System: You are an AI assistant called Twllm, created by TAME (TAiwan Mixture of Expert) project.

User: 您是電影評論分析師,負責情緒分析。
分析每個被評論的句子,評估句子中每個字和標點符號的重要性,
並且將結果使用 tuple 的結構列出。
tuple 值的範圍介於 -1 (負向) 到 1 (正向) 之間,
然後,將評論分類為正向 (1) 或負向 (-1)。
這些需要被評論的句子,包含在  標籤中間。

輸出範例:
[(<單字或標點符號>, ), ...]

 根據外媒報導,宏都拉斯在去年3月與台灣斷交,並轉往與中國建交之後,卻遲遲等不到中國的金援,談好要進口宏都拉斯的白蝦也拖延許久,甚至還將白蝦價格殺價至過往與台灣交易的半價,再加上墨西哥同時也中斷了與宏國的白蝦貿易,對當地蝦農可說是雪上加霜。 
  

Assistant: [('根據', 0.2), ('外媒', 0.1), ('報導', -0.1), (',', 0.05), ('宏都拉斯', -0.3), ('在去年3月與台灣斷交, ', -0.5), ('並轉往與中國建交之後, ', -0.4), ('卻遲遲等不到中國的金援, ', -1),
('談好要進口宏都拉斯的白蝦也拖延許久, ', -1),
(',甚至還將白蝦價格殺價至過往與台灣交易的半價,再加上墨西哥同時也中斷了與宏國的白蝦貿易,對當地蝦農可說是雪上加霜。 ',-1)]
-1

开始使用

注意:系统消息应始终设置。

Hugging Face Transformers 库

您可以使用 Hugging Face Transformers 库配合 Llama-3-Taiwan-70B。

import torch
from transformers import pipeline, StoppingCriteria

# Define a custom stopping criteria class
class EosListStoppingCriteria(StoppingCriteria):
    def __init__(self, eos_sequence=[128256]):
        self.eos_sequence = eos_sequence

    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
        last_ids = input_ids[:, -len(self.eos_sequence):].tolist()
        return self.eos_sequence in last_ids

# Initialize the model with automatic device mapping
llm = pipeline("text-generation", model="yentinglin/Llama-3-Taiwan-70B-Instruct-rc1", device_map="auto")
tokenizer = llm.tokenizer

# Define a conversation example
chat = [
    {"role": "system", "content": "You are an AI assistant called Twllm, created by TAME (TAiwan Mixture of Expert) project."},
    {"role": "user", "content": "你好,請問你可以完成什麼任務?"},
    {"role": "assistant", "content": "你好,我可以幫助您解決各種問題、提供資訊並協助完成多種任務。例如:回答技術問題、提供建議、翻譯文字、尋找資料或協助您安排行程等。請告訴我如何能幫助您。"},
    {"role": "user", "content": "太棒了!"}
]
flatten_chat_for_generation = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
"""
<|im_start|>user
You are an AI assistant called Twllm, created by TAME (TAiwan Mixture of Expert) project.<|im_end|>
<|im_start|>user
你好,請問你可以完成什麼任務?<|im_end|>
<|im_start|>assistant
你好,我可以幫助您解決各種問題、提供資訊和協助您完成許多不同的任務。例如:回答技術問題、提供建議、翻譯文字、尋找資料或協助您安排行程等。請告訴我如何能幫助您。<|im_end|>
<|im_start|>user
太棒了!<|im_end|>
<|im_start|>assistant

"""

# Generate a response using the custom stopping criteria
output = llm(flatten_chat_for_generation, return_full_text=False, max_new_tokens=128, top_p=0.9, temperature=0.7, stopping_criteria=[EosListStoppingCriteria([tokenizer.eos_token_id])])
print(output[0]['generated_text'])
"謝謝!很高興能夠為您服務。如果有任何其他需要協助的地方,請隨時與我聯繫。我會盡最大努力為您提供所需的支援。"

vLLM

启动服务器

export NUM_GPUS=4
export PORT=8000

docker run \
  -e HF_TOKEN=$HF_TOKEN \
  --gpus '"device=0,1,2,3"' \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  -p "${PORT}:8000" \
  --ipc=host \
  vllm/vllm-openai:v0.4.0.post1 \
  --model "yentinglin/Llama-3-Taiwan-70B-Instruct-rc1" \
  -tp "${NUM_GPUS}"

示例客户端代码,或您可以使用任何兼容 OpenAI-API 的客户端

# pip install "openai>=1.0.0"
from openai import OpenAI
# Set OpenAI's API key and API base to use vLLM's API server.
openai_api_key = "EMPTY"
openai_api_base = "https://:8000/v1"

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

chat_response = client.chat.completions.create(
    model="yentinglin/Llama-3-Taiwan-70B-Instruct-rc1",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Tell me a joke."},
    ]
)
print("Chat response:", chat_response)

享受探索 Llama-3-Taiwan-70B 功能的乐趣!我们期待着看到您使用这个强大的开源模型所创造的一切。如果您有任何问题或反馈,请告诉我们。

贡献者

  • 陈荣民教授,在整个项目中的指导和建议。
  • 陈维林,领导我们的预训练数据管道。
  • 林子涵,生成合成数据。
  • 高长生,提升合成数据质量。
  • 陈康杰,清理指令遵循数据。
  • 陈敏怡徐韶衡,收集化学工程数据和基准。
  • 马中耀,郭子宁和张家骏,搜集制造业和电气工程数据和基准,以及项目进度管理

引用

@article{DBLP:journals/corr/abs-2311-17487,
  author       = {Yen{-}Ting Lin and
                  Yun{-}Nung Chen},
  title        = {Taiwan {LLM:} Bridging the Linguistic Divide with a Culturally Aligned
                  Language Model},
  journal      = {CoRR},
  volume       = {abs/2311.17487},
  year         = {2023},
  url          = {https://doi.org/10.48550/arXiv.2311.17487},
  doi          = {10.48550/ARXIV.2311.17487},
  eprinttype    = {arXiv},
  eprint       = {2311.17487},
  timestamp    = {Tue, 05 Dec 2023 14:40:42 +0100},
  biburl       = {https://dblp.org/rec/journals/corr/abs-2311-17487.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}
@article{DBLP:journals/corr/abs-2403-20180,
  author       = {Po{-}Heng Chen and
                  Sijia Cheng and
                  Wei{-}Lin Chen and
                  Yen{-}Ting Lin and
                  Yun{-}Nung Chen},
  title        = {Measuring Taiwanese Mandarin Language Understanding},
  journal      = {CoRR},
  volume       = {abs/2403.20180},
  year         = {2024},
  url          = {https://doi.org/10.48550/arXiv.2403.20180},
  doi          = {10.48550/ARXIV.2403.20180},
  eprinttype    = {arXiv},
  eprint       = {2403.20180},
  timestamp    = {Wed, 10 Apr 2024 17:37:45 +0200},
  biburl       = {https://dblp.org/rec/journals/corr/abs-2403-20180.bib},
  bibsource    = {dblp computer science bibliography, https://dblp.org}
}