🚀 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