Hugging Face 欢迎 Aya Expanse 多语言模型家族

社区文章 发布于 2024 年 10 月 24 日

image/png

Cohere 发布了两款强大的多语言模型,即

  1. aya-expanse-8B
  2. aya-expanse-32B

这些模型支持以下 23 种语言,确保了对广泛用户的包容性

语言 脚本
印地语 हिंदी
土耳其语 Türkçe
波斯语 فارسی
印尼语 Bahasa Indonesia
阿拉伯语 العربية
中文 中文
捷克语 Čeština
荷兰语 荷兰语
英语 英语
法语 法语
德语 德语
意大利语 意大利语
希腊语 Ελληνικά
日语 日本語
韩语 한국어
波兰语 波兰语
葡萄牙语 葡萄牙语
罗马尼亚语 Română
俄语 Русский
西班牙语 西班牙语
乌克兰语 Українська
越南语 越南语
希伯来语 עברית

两种模型权重均已根据 CC-BY-NC 许可证上传到 Hugging Face Hub,并额外要求遵守 C4AI 的可接受使用政策

您可以在 Cohere 团队的官方博客文章中找到对模型及其训练方式的深入分析,而在这篇博客文章中,我们将帮助您开始使用 Hugging Face 生态系统中的模型。

试用模型

在下载权重之前,您可以使用 Hugging Face 上托管的官方空间来验证模型。

开始使用

以下是如何使用 pipeline 快速从模型生成文本的方法。

import torch
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "CohereForAI/aya-expanse-8b" # aya-expanse-32b
dtype = torch.float16
device = "auto"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=dtype,
    device_map=device
)

generator = pipeline(
    model=model,
    tokenizer=tokenizer,
    task="text-generation"
)

messages = [
    {"role": "user", "content": "Anneme onu ne kadar sevdiğimi anlatan bir mektup yaz"},
]
generator(
    messages,
    max_new_tokens=128
)[0]["generated_text"][-1]["content"]

模型量化

我们 Hugging Face 不希望 GPU 资源有限的人因无法使用模型而却步。您可以对模型进行量化,并在免费的 Colab 实例上进行推理!

!pip install -Uq bitsandbytes

import torch
from transformers import (
    AutoTokenizer,
    AutoModelForCausalLM,
    BitsAndBytesConfig,
    pipeline
)

model_id = "CohereForAI/aya-expanse-32b"
dtype = torch.float16
device = "auto"

tokenizer = AutoTokenizer.from_pretrained(model_id)
quantization_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=dtype,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type= "nf4"
)
quantized_model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map=device,
    torch_dtype=dtype,
    quantization_config=quantization_config
)

generator = pipeline(
    model=quantized_model,
    tokenizer=tokenizer,
    task="text-generation"
)

messages = [
    {"role": "user", "content": "Anneme onu ne kadar sevdiğimi anlatan bir mektup yaz"},
]
generator(messages, max_new_tokens=128)[0]["generated_text"][-1]["content"]

来自 Cohere 社区

微调模型

这是一个 Notebook,展示了如何端到端地微调 Aya Expanse 模型以支持新语言。

其他 notebooks

以下由 Cohere For AI 社区成员贡献的 Notebooks 展示了 Aya Expanse 如何用于不同的用例

  1. 多语言写作助手
  2. AyaMCooking
  3. 多语言问答系统

致谢

感谢 Pedro Cuenca 审阅这篇博客文章。

社区

注册登录 以评论