🚀 InkubaLM-0.4B:適用於低資源非洲語言的小型語言模型
InkubaLM-0.4B 是一款專門為低資源非洲語言打造的小型語言模型,它使用了多語言數據進行訓練,能夠理解和生成多種非洲語言及英法語言的文本內容,為非洲語言的研究和應用提供了有力支持。

📚 模型詳情
InkubaLM 是從零開始訓練的,使用了 19 億個標記的五種非洲語言數據,再加上英語和法語數據,總共使用了 24 億個標記的數據。與 MobileLLM 使用的模型架構類似,我們訓練的這個 InkubaLM 參數規模為 4 億,詞彙量為 61788。如需瞭解訓練、基準測試和性能的詳細信息,請參考我們完整的 博客文章。
模型描述
- 開發者:Lelapa AI - 基礎研究團隊。
- 模型類型:採用 LLaMA - 7B 架構設計構建的適用於五種非洲語言的小型語言模型(SLM)。
- 支持語言(NLP):祖魯語(isiZulu)、約魯巴語(Yoruba)、斯瓦希里語(Swahili)、科薩語(isiXhosa)、豪薩語(Hausa)、英語和法語。
- 許可證:CC BY - NC 4.0。
模型資源
🚀 快速開始
使用以下代碼開始使用該模型。
安裝依賴
pip install transformers
在 CPU/GPU/多 GPU 上運行模型
- 在 CPU 上運行模型
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("lelapa/InkubaLM-0.4B", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("lelapa/InkubaLM-0.4B", trust_remote_code=True)
text = "Today I planned to"
inputs = tokenizer(text, return_tensors="pt")
input_ids = inputs.input_ids
attention_mask = inputs.attention_mask
outputs = model.generate(input_ids, attention_mask=attention_mask, max_length=60, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
- 使用全精度
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("lelapa/InkubaLM-0.4B", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("lelapa/InkubaLM-0.4B", trust_remote_code=True)
model.to('cuda')
text = "Today i planned to "
input_ids = tokenizer(text, return_tensors="pt").to('cuda').input_ids
outputs = model.generate(input_ids, max_length=1000, repetition_penalty=1.2, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.batch_decode(outputs[:, input_ids.shape[1]:-1])[0].strip())
- 使用 torch.bfloat16
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
checkpoint = "lelapa/InkubaLM-0.4B"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=True)
inputs = tokenizer.encode("Today i planned to ", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
- 通過 bitsandbytes 使用量化版本
pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
checkpoint = "lelapa/InkubaLM-0.4B"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config, trust_remote_code=True)
inputs = tokenizer.encode("Today i planned to ", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
🔧 訓練細節
訓練數據
訓練超參數
屬性 |
詳情 |
總參數數量 |
4.22 億 |
隱藏層大小 |
2048 |
中間層大小(MLPs) |
5632 |
注意力頭數量 |
32 |
隱藏層數量 |
8 |
RMSNorm ɛ |
1e^ - 5 |
最大序列長度 |
2048 |
詞彙量大小 |
61788 |
⚠️ 侷限性
InkubaLM 模型在多語言數據集上進行了訓練,但仍存在一些侷限性。它能夠理解和生成五種非洲語言(斯瓦希里語、約魯巴語、豪薩語、祖魯語和科薩語)以及英語和法語的內容。雖然它可以生成各種主題的文本,但生成的內容可能並不總是完全準確、邏輯一致,或者可能包含訓練數據中的偏差。此外,該模型在生成文本時有時可能會混用不同的語言。不過,該模型旨在作為支持非洲語言研究的基礎工具。
🤔 倫理考量與風險
InkubaLM 是為五種非洲語言開發的小型語言模型。該模型僅在情感分析、機器翻譯、AfriMMLU 和 AfriXNLI 任務中進行了評估,尚未涵蓋所有可能的評估場景。與其他語言模型類似,無法提前預測 InkubaLM 的所有潛在輸出,在某些情況下,該模型可能會產生不準確、有偏差或令人反感的響應。因此,在將該模型用於任何應用之前,用戶應根據其預期用途進行安全測試和調整。
📖 引用
@article{tonja2024inkubalm,
title={InkubaLM: A small language model for low-resource African languages},
author={Tonja, Atnafu Lambebo and Dossou, Bonaventure FP and Ojo, Jessica and Rajab, Jenalea and Thior, Fadel and Wairagala, Eric Peter and Anuoluwapo, Aremu and Moiloa, Pelonomi and Abbott, Jade and Marivate, Vukosi and others},
journal={arXiv preprint arXiv:2408.17024},
year={2024}
}
📝 模型卡片作者
Lelapa AI - 基礎研究團隊
📞 模型卡片聯繫方式
Lelapa AI