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 是一个经过在大量台语和英语数据集上微调的 70B 参数模型,使用 Llama-3 架构构建。它在各种传统中文 NLP 基准测试中展现出最先进的性能。

该模型使用 NVIDIA NeMo™ 框架经过训练,该框架由 NVIDIA DGX H100 系统构建的 NVIDIA Taipei-1 构建。

训练Llama-3-Taiwan-70B所需的计算和数据得到了以下机构的慷慨赞助:长庚纪念医院(链接)、长春集团(链接)、Legalsign.ai(链接)、NVIDIA(链接)、鸿海精密(链接)、TechOrange(链接)和南亚电路制造(链接),赞助机构按字母顺序排列。

在此,我们感谢数据提供方、团队成员和顾问在模型开发过程中的贡献,包括shasha77(链接)提供的高质量的YouTube脚本和研究材料,台湾AI实验室(链接)提供的本地媒体内容,Ubitus K.K.(链接)提供的游戏内容,陈云绫教授的指导和咨询,陈维琳负责我们的预训练数据管道,林子涵负责合成数据的生成,高成胜提高我们的合成数据质量,以及陈炯杰出于清理指令遵循数据。

模型摘要

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

  • 70亿参数
  • 语言:繁体中文(zh-tw)、英语(en)
  • 在涵盖一般知识以及法律、制造、医疗和电子领域工业知识的优质繁体中文和英文语料库上进行超调
  • 8K上下文长度
  • 在Llama-3许可证下释放的开源模型

训练细节

  • 训练框架:NVIDIA NeMo(链接)、NVIDIA NeMo Megatron(链接
  • 推理框架:NVIDIA TensorRT-LLM(链接
  • 基准模型:Llama-3 70B(链接
  • 硬件:台北1的NVIDIA DGX H100(链接
  • 上下文长度:8K标记(128k版本
  • 每步2M标记批大小

评估

查看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。

评估实现

^从原始数据集中选取最接近的匹配数字。

海中寻针评估

“海中寻针”评估测试模型在大量文本中定位和回忆嵌套的重要信息的能力,使用诸葛亮所著的经典中文文本《出师表》。

运行评估,请使用脚本

台湾MT-Bench评分

image/png

用例

Llama-3-Taiwan-70B 可应用于多种繁体中文和英文的自然语言处理任务,包括

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`。请参考来自李宏毅的《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 的能力!我们期待看到您使用这个强大的开源模型能创造什么。如果您有任何问题或反馈,请告诉我们。

贡献者

  • 陈允甦(Vivian)教授,她在整个项目中的指导和咨询。
  • 陈维林,领导我们的预训练数据管道。
  • 林子涵,进行合成数据生成。
  • 高长胜,提高我们的合成数据质量。
  • 陈康杰,清理指令遵循数据。
  • 陈旻益徐韶鹏,收集化学工程数据和基准。
  • 马重耀,郭子建立和曾凯均,收集制造业和电气工程数据和基准,以及项目管理

引用

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