模型概述
模型特點
模型能力
使用案例
🚀 SeaLLM-7B-v2 - 面向東南亞的大語言模型
SeaLLM-7B-v2是一款面向東南亞語言的先進多語言大語言模型,支持英語、中文、越南語等多種語言。相比前代模型,它規模更小但性能更優,在多語言任務中表現出色,如世界知識、數學推理和指令跟隨等方面。
🚀 快速開始
我們推出了 SeaLLM-7B-v2,這是一款面向東南亞(SEA)語言的最先進多語言大語言模型,支持英語、中文、越南語、印尼語、泰語、馬來語、高棉語、老撾語、緬甸語和菲律賓語。這是自 SeaLLM-13B 以來最重要的一次升級,模型規模減半,但在各種多語言任務中表現更優,涵蓋世界知識、數學推理、指令跟隨等領域。
重要消息
🎉 SeaLLM3 已發佈,在各種任務中展現出了最先進的性能,並且特別增強了模型的可信度。建議使用這個最新的模型版本。
相關鏈接
✨ 主要特性
亮點
- SeaLLM-7B-v2 在 零樣本思維鏈(Zero-shot CoT)GSM8K 任務中取得了 78.2 分的成績,達到了 7B 模型的最優水平(7B-SOTA)。在許多東南亞語言(中文、越南語、印尼語、泰語)翻譯後的 GSM8K 任務以及 MGSM(中文、泰語)任務中,表現優於 GPT-3.5。在泰語的 MATH 思維鏈任務中也超越了 GPT-3.5。
- 在許多零樣本思維鏈常識基準測試中,與 GPT-3.5 競爭激烈,在 Arc-C、Winogrande 和 Hellaswag 測試中分別取得了 82.5、68.3 和 80.9 的分數。
- 在英語 MT-bench 測試中獲得了 7.54 分,在 7B 類別排行榜中排名第 3,是表現最出色的多語言模型。
- 在越南語 VMLU 基準測試中獲得了 45.74 分,是唯一能與同規模單語言模型(如 Vistral-7B)競爭的開源多語言模型。
發佈與演示
- 演示:SeaLLMs/SeaLLM-7B。
- 技術報告:Arxiv: SeaLLMs - Large Language Models for Southeast Asia。
- 模型權重:
- SeaLLM-7B-v2。
- SeaLLM-7B-v2-gguf。
- SeaLLM-7B-v2-GGUF(感謝 Lonestriker)。注意:需使用 seallm.preset.json 才能正常工作。
- 本地運行:
- LM-studio:
- SeaLLM-7B-v2-q4_0 和 SeaLLM-7B-v2-q8_0。
- LM-studio 需要使用 seallm.preset.json 來正確設置聊天模板。
- ollama:
ollama run nxphi47/seallm-7b-v2:q4_0
- 適用於蘋果硅芯片的 MLX:mlx-community/SeaLLM-7B-v2-4bit-mlx
- LM-studio:
使用條款和許可
⚠️ 重要提示
使用我們發佈的權重、代碼和演示,即表示您同意並遵守 SeaLLMs 使用條款 中規定的條款和條件。
免責聲明: 我們必須指出,儘管我們以開放的方式發佈了權重、代碼和演示,但與其他預訓練語言模型一樣,即使我們在紅隊測試、安全微調及強化方面已盡最大努力,我們的模型仍存在潛在風險,包括但不限於不準確、誤導性或潛在有害的生成內容。 開發者和相關利益方在部署前應進行自己的紅隊測試並提供相關安全措施,且必須遵守當地的治理和法規。 在任何情況下,作者均不對因使用發佈的權重、代碼或演示而產生的任何索賠、損害或其他責任負責。
SeaLLM-13B-v1 和 SeaLLM-7B-v1 的更新內容
SeaLLM-7B-v2 基於 Mistral-7B 繼續預訓練,並經過精心設計的調優,專注於推理能力的提升。
🔧 技術細節
零樣本思維鏈多語言數學推理
SeaLLM-7B-v2 在 GSM8K 零樣本思維鏈推理測試中取得了 78.2 分的成績,成為 7B 模型領域的 最優模型。在翻譯成東南亞語言(中文、越南語、印尼語、泰語)的相同 GSM8K 基準測試中,它也優於 GPT-3.5。在泰語翻譯的 MATH 基準測試中,SeaLLM-7B-v2 以 22.4 分的成績超過了 GPT-3.5 的 18.1 分。
查看英語及翻譯後的 GSM8K 和 MATH 零樣本推理詳情
模型 | GSM8K 英語 |
MATH 英語 |
GSM8K 中文 |
MATH 中文 |
GSM8K 越南語 |
MATH 越南語 |
GSM8K 印尼語 |
MATH 印尼語 |
GSM8K 泰語 |
MATH 泰語 |
---|---|---|---|---|---|---|---|---|---|---|
GPT-3.5 | 80.8 | 34.1 | 48.2 | 21.5 | 55 | 26.5 | 64.3 | 26.4 | 35.8 | 18.1 |
Qwen-14B-chat | 61.4 | 18.4 | 41.6 | 11.8 | 33.6 | 3.6 | 44.7 | 8.6 | 22 | 6 |
Vistral-7b-chat | 48.2 | 12.5 | 48.7 | 3.1 | ||||||
Qwen1.5-7B-chat | 56.8 | 15.3 | 40 | 2.7 | 37.7 | 9 | 36.9 | 7.7 | 21.9 | |
SeaLLM-7B-v2 | 78.2 | 27.5 | 53.7 | 17.6 | 69.9 | 23.8 | 71.5 | 24.4 | 59.6 | 22.4 |
基線模型使用各自的聊天模板和系統提示進行評估(Qwen1.5-7B-chat,Vistral)。
零樣本 MGSM
SeaLLM-7B-v2 在中文和泰語的多語言 MGSM 測試中也優於 GPT-3.5 和 Qwen-14B。
模型 | MGSM-中文 | MGSM-泰語 |
---|---|---|
ChatGPT(報告值) | 61.2 | 47.2 |
Qwen-14B-chat | 59.6 | 28 |
SeaLLM-7B-v2 | 64.8 | 62.4 |
零樣本常識推理
我們將 SeaLLM-7B-v2 與 ChatGPT 和 Mistral-7B-instruct 在各種零樣本常識基準測試(Arc-Challenge、Winogrande 和 Hellaswag)中進行了比較。我們使用 (Kojima et al., 2023) 中的兩階段技術來獲取答案。請注意,我們 未 使用 “Let's think step-by-step” 來觸發顯式思維鏈。
零樣本推理 | Arc-Challenge | Winogrande | Hellaswag |
---|---|---|---|
ChatGPT(報告值) | 84.6* | 66.8* | 72.0* |
ChatGPT(復現) | 84.1 | 63.1 | 79.5 |
Mistral-7B-Instruct | 68.1 | 56.4 | 45.6 |
Qwen1.5-7B-chat | 79.3 | 59.4 | 69.3 |
SeaLLM-7B-v2 | 82.5 | 68.3 | 80.9 |
基線模型使用各自的聊天模板和系統提示進行評估(Qwen1.5-7B-chat,Mistral)。
多語言世界知識
我們按照推薦的默認設置在 3 個基準測試中評估模型:英語的 5 樣本 MMLU、英語、中文、越南語、印尼語、泰語的 3 樣本 M3Exam(M3e)以及越南語的零樣本 VMLU。
模型 | 語言 | 英語 MMLU |
英語 M3e |
中文 M3e |
越南語 M3e |
越南語 VMLU |
印尼語 M3e |
泰語 M3e |
---|---|---|---|---|---|---|---|---|
GPT-3.5 | 多語言 | 68.90 | 75.46 | 60.20 | 58.64 | 46.32 | 49.27 | 37.41 |
Vistral-7B-chat | 單語言 | 56.86 | 67.00 | 44.56 | 54.33 | 50.03 | 36.49 | 25.27 |
Qwen1.5-7B-chat | 多語言 | 61.00 | 52.07 | 81.96 | 43.38 | 45.02 | 24.29 | 20.25 |
SeaLLM-7B-v2 | 多語言 | 61.89 | 70.91 | 55.43 | 51.15 | 45.74 | 42.25 | 35.52 |
VMLU 復現腳本 在此。我們使用 Lm-eval 來評估 MMLU。基線模型的零樣本 VMLU 分數使用各自的聊天模板和系統提示進行評估(Qwen1.5-7B-chat)。
MT-Bench
在英語 MT-bench 指標上,SeaLLM-7B-v2 取得了 7.54 分的成績(在 7B 類別排行榜中排名第 3),優於許多 70B 模型,並且可以說是唯一能處理 10 種東南亞語言的模型。
有關 SeaLLM-7B-v2 的 MT-bench 預測結果,請參考 mt_bench/seallm_7b_v2.jsonl,復現方法 在此。
模型 | 訪問方式 | 語言 | MT-Bench |
---|---|---|---|
GPT-4-turbo | 閉源 | 多語言 | 9.32 |
GPT-4-0613 | 閉源 | 多語言 | 9.18 |
Mixtral-8x7b (46B) | 開源 | 多語言 | 8.3 |
Starling-LM-7B-alpha | 開源 | 單語言(英語) | 8.0 |
OpenChat-3.5-7B | 開源 | 單語言(英語) | 7.81 |
SeaLLM-7B-v2 | 開源 | 多語言(10 種以上) | 7.54 |
Qwen-14B | 開源 | 多語言 | 6.96 |
Llama-2-70B | 開源 | 單語言(英語) | 6.86 |
Mistral-7B-instuct | 開源 | 單語言(英語) | 6.84 |
Sea-Bench
與 MT-Bench 類似,Sea-bench 是一組分類指令測試集,用於衡量模型作為助手的能力,特別關注 9 種東南亞語言,包括非拉丁低資源語言。
如圖所示,模型在數學推理方面有了巨大的改進,達到了 GPT-3.5 的性能水平。
有關 SeaLLM-7B-v2 的 Sea-bench 預測結果,請參考 sea_bench/seallm_7b_v2.jsonl。
💻 使用示例
指令格式
prompt = """<|im_start|>system
You are a helpful assistant.</s><|im_start|>user
Hello world</s><|im_start|>assistant
Hi there, how can I help?</s>"""
# 注意:之前的提交在 </s> 和 <|im_start|> 之間有 \n,這是不正確的!
# <|im_start|> 不是特殊標記。
# Transformers 的聊天模板應與下面的 vLLM 格式一致。
# 確保序列開頭只有 1 個 bos `<s>`
print(tokenizer.convert_ids_to_tokens(tokenizer.encode(prompt)))
'<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁a', '▁helpful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '?', '</s>']
"""
使用 transformers 的聊天模板
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # 加載模型的設備
# 使用 bfloat16 以確保最佳性能。
model = AutoModelForCausalLM.from_pretrained("SeaLLMs/SeaLLM-7B-v2", torch_dtype=torch.bfloat16, device_map=device)
tokenizer = AutoTokenizer.from_pretrained("SeaLLMs/SeaLLM-7B-v2")
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello world"},
{"role": "assistant", "content": "Hi there, how can I help you today?"},
{"role": "user", "content": "Explain general relativity in details."}
]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
print(tokenizer.convert_ids_to_tokens(encodeds[0]))
# ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁a', '▁helpful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '▁you', '▁today', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Ex', 'plain', '▁general', '▁rel', 'ativity', '▁in', '▁details', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>']
model_inputs = encodeds.to(device)
model.to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True, pad_token_id=tokenizer.pad_token_id)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
使用 vLLM
from vllm import LLM, SamplingParams
TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
TURN_PREFIX = "<|im_start|>{role}\n"
# </s> 和 <|im_start|> 之間沒有 \n。
def seallm_chat_convo_format(conversations, add_assistant_prefix: bool, system_prompt=None):
# conversations: 包含 `role` 和 `content` 鍵的字典列表(OpenAI 格式)
if conversations[0]['role'] != 'system' and system_prompt is not None:
conversations = [{"role": "system", "content": system_prompt}] + conversations
text = ''
for turn_id, turn in enumerate(conversations):
prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
text += prompt
if add_assistant_prefix:
prompt = TURN_PREFIX.format(role='assistant')
text += prompt
return text
sparams = SamplingParams(temperature=0.1, max_tokens=1024, stop=['</s>', '<|im_start|>'])
llm = LLM("SeaLLMs/SeaLLM-7B-v2", dtype="bfloat16")
message = "Explain general relativity in details."
prompt = seallm_chat_convo_format(message, True)
gen = llm.generate(prompt, sampling_params)
print(gen[0].outputs[0].text)
微調 SeaLLM-7B-v2
應遵循聊天格式並準確屏蔽源標記。以下是一個示例。
conversations = [
{"role": "system", "content": "You are helful assistant."},
{"role": "user", "content": "Hello world."},
{"role": "assistant", "content": "Hi there, how can I help?"},
{"role": "user", "content": "Tell me a joke."},
{"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
]
def seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations, add_assistant_prefix=False):
"""
輸入:
conversations: 遵循 OpenAI 格式的字典列表,例如
conversations = [
{"role": "system", "content": "You are helful assistant."},
{"role": "user", "content": "Hello world."},
{"role": "assistant", "content": "Hi there, how can I help?"},
{"role": "user", "content": "Tell me a joke."},
{"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
]
add_assistant_prefix: 是否添加助手前綴,僅用於推理解碼
輸出:
tokenize_output_sample, {
"input_ids": ...
"token_type_ids": 1 表示訓練,0 表示屏蔽(不訓練)
}
在訓練期間,需要創建一個標籤,將屏蔽的標記設置為 -100 以避免損失計算。
labels = sample['input_ids'].clone()
labels[sample['token_type_ids'] == 0] = -100
"""
TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
TURN_PREFIX = "<|im_start|>{role}\n"
sample = None
assistant_prefix_len = None
for turn_id, turn in enumerate(conversations):
prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
turn_sample = tokenizer(
prompt, padding=False, truncation=False, verbose=False, add_special_tokens=False,
return_token_type_ids=True,
)
if turn['role'] == 'assistant':
if assistant_prefix_len is None:
assistant_prefix_len = len(tokenizer.encode(TURN_PREFIX.format(role=turn['role']), add_special_tokens=False))
turn_sample['token_type_ids'][assistant_prefix_len:] = [1] * (len(turn_sample['input_ids']) - assistant_prefix_len)
if sample is None:
sample = turn_sample
else:
for k in turn_sample.keys():
sample[k].extend(turn_sample[k])
if add_assistant_prefix:
assistant_prefix_sample = tokenizer(
TURN_PREFIX.format(role="assistant"), padding=False, truncation=False, verbose=False, add_special_tokens=False,
return_token_type_ids=True,
)
for k in sample.keys():
sample[k].extend(assistant_prefix_sample[k])
if tokenizer.add_bos_token:
sample['input_ids'] = [tokenizer.bos_token_id] + sample['input_ids']
sample['attention_mask'] = [1] + sample['attention_mask']
sample['token_type_ids'] = [sample['token_type_ids'][0]] + sample['token_type_ids']
return sample
# 測試
sample = seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations)
print(tokenizer.convert_ids_to_tokens(sample['input_ids']))
print(sample['token_type_ids'])
# ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁hel', 'ful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Tell', '▁me', '▁a', '▁joke', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Why', '▁don', "'", 't', '▁scientists', '▁trust', '▁atoms', '?', '▁Because', '▁they', '▁make', '▁up', '▁everything', '.', '</s>']
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
致謝語言學家
我們要特別感謝我們專業的母語語言學家 Tantong Champaiboon、Nguyen Ngoc Yen Nhi 和 Tara Devina Putri,他們幫助構建、評估和事實核查我們採樣的預訓練和 SFT 數據集,並從不同方面評估我們的模型,特別是在安全方面。
引用
如果您覺得我們的項目有用,希望您能給我們的倉庫點個星,並按以下方式引用我們的工作:通訊作者:l.bing@alibaba-inc.com
作者列表和順序可能會改變!
*
和^
表示同等貢獻。
@article{damonlpsg2023seallm,
author = {Xuan-Phi Nguyen*, Wenxuan Zhang*, Xin Li*, Mahani Aljunied*,
Zhiqiang Hu, Chenhui Shen^, Yew Ken Chia^, Xingxuan Li, Jianyu Wang,
Qingyu Tan, Liying Cheng, Guanzheng Chen, Yue Deng, Sen Yang,
Chaoqun Liu, Hang Zhang, Lidong Bing},
title = {SeaLLMs - Large Language Models for Southeast Asia},
year = 2023,
Eprint = {arXiv:2312.00738},
}
📄 許可證
本項目採用 seallms 許可證。



