Llama-3-Taiwan-8B是一个采用Llama-3架构在大量繁体中文和英文数据集上微调的8B参数模型。它在各种繁体中文NLP基准测试中表现出最先进的性能。

8B

262 Pulls 更新于6周前

6周前

1455021ead7d · 16GB

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™ Framework,基于 NVIDIA DGX H100 系统构建的 NVIDIA Taipei-1 进行训练。

Llama-3-Taiwan-70B 的计算和数据训练得到了 Chang Gung Memorial HospitalChang Chun GroupLegalsign.aiNVIDIAPegatronTechOrangeUnimicron (按字母顺序排列)慷慨赞助。

我们感谢我们的数据提供商、团队成员和顾问在开发此模型中的贡献,包括贡献者shasha77提供了高质量的YouTube剧本和研究材料,台湾人工智能实验室提供了当地媒体内容,Ubitus K.K.提供了游戏内容,陈芸葓教授在她的指导和咨询方面,陈维琳在推动我们的预训练数据管道方面的领导,林子涵在合成数据生成方面的贡献,高长胜对我们合成数据质量提升的贡献,以及陈永捷在清理指令遵循数据方面的工作。

模型概述

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

  • 70B参数
  • 语言:传统普通话(zh-tw),英语(en)
  • 在涵盖一般知识和法律、制造业、医疗和电子产品领域行业知识的优质传统普通话和英语语料库上微调
  • 8K上下文长度
  • 在Llama-3许可下发布的开放模型

训练细节

评估

查看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次拍摄) 69.84% 60.29% - 200k -
GPT4-o 65.56% (无提示), 69.88% (5次拍摄) 76.98% 53.59% - 128k -
GPT4-turbo 70.42% (5次拍摄) - - - 128k 60.34%^
Gemini-Pro 61.40% (5次拍摄) - - - 1000k 49.92%^
GPT-3.5-turbo-1106 49.37% (5次拍摄) - - 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%

默认情况下为无提示。

评估实现

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

万针在你的手表里寻找评估

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

运行评估,使用脚本

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`。示例来自“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}
}