license: gemma
library_name: transformers
pipeline_tag: text-generation
extra_gated_button_content: Acknowledge license
tags:
- conversational
language:
- ar
datasets:
- MBZUAI-Paris/Darija-SFT-Mixture
base_model:
- google/gemma-2-9b-it
QuantFactory/Atlas-Chat-9B-GGUF
This is quantized version of MBZUAI-Paris/Atlas-Chat-9B created using llama.cpp
Original Model Card
Atlas-Chat Model Card
Model Overview
Atlas-Chat is a family of open models instruction-tuned for Darija, the colloquial Arabic of Morocco, developed as part of the Jais project for standard Arabic and its extentions to dialectal Arabic. These models are designed for language generation and excel in various applications such as question answering, summarization, and translation. Thanks to their compact size, Atlas-Chat models can be deployed in resource-constrained environments like laptops, desktops, or personal cloud setups, making advanced AI accessible to Darija speakers and promoting widespread innovation. Two versions are available:
- Atlas-Chat-2B: A small-sized version with 2 billion parameters, capable of generating fluent Moroccan Darija text while maintaining efficiency.
- Atlas-Chat-9B: A larger version with 9 billion parameters, providing more nuanced, contextually rich language generation for complex tasks.
The models are designed to assist with:
- Conversational agents and chatbots that operate in Darija.
- Translation, summarization, and content generation in informal dialect.
- Cultural research related to Morocco and its language.
Paper: Atlas-Chat: Adapting Large Language Models for Low-Resource Moroccan Arabic Dialect
๐ฅ Our Team
The model is developed by MBZUAI France Lab, an AI research center in Paris affiliated with the Mohamed bin Zayed University of Artificial Intelligence (MBZUAI) headquartered in Abu Dhabi.
Usage
Below we share some code snippets on how to get quickly started with running the model. First, install the Transformers library with:
pip install -U transformers sentencepiece
Then, copy the snippet from the section that is relevant for your use case.
Running with the pipeline
API
import torch
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="MBZUAI-Paris/Atlas-Chat-9B",
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda" # replace with "mps" to run on a Mac device
)
messages = [
{"role": "user", "content": 'ุดููู ูู ุตูุนูุ'},
]
outputs = pipe(messages, max_new_tokens=256, temperature=0.0)
assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
print(assistant_response)
- Response:
ุตูุนุงุชูู ุฌุงู ุนุฉ ู ุญู ุฏ ุจู ุฒุงูุฏ ููุฐูุงุก ุงูุงุตุทูุงุนูุ ูู ูู ุฌุงู ุนุฉ ุจุญุซูุฉ ุฏูุงู ุงูุฏุฑุงุณุงุช ุงูุนููุง ุงููุฏู ุฏูุงููุง ุฃููุง ุชุฒูุฏ ุจุงูุฐูุงุก ุงูุงุตุทูุงุนู ููุฏูุงู ูุชููุน ุจูู ุงูุฅูุณุงููุฉ. ูู ูู ููู ุชุฒูุฑ https://mbzuai.ac.ae/ar/about/ ุจุงุด ุชุนุฑู ูุซุฑ ุนูู ุฌุงู ุนุฉ ู ุญู ุฏ ุจู ุฒุงูุฏ ููุฐูุงุก ุงูุงุตุทูุงุนู ูุงูู ูู ุฉ ุฏูุงููุง!
Running the model on a single / multi GPU
pip install accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "MBZUAI-Paris/Atlas-Chat-9B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype=torch.bfloat16,
)
messages = [
{"role": "user", "content": "ุดูู ููุชุณู
ู ุงูู
ูุชุฎุจ ุงูู
ุบุฑุจู ุ"},
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True, , add_generation_prompt=True)
outputs = model.generate(**input_ids, max_new_tokens=256)
print(tokenizer.decode(outputs[0]))
- Response:
ุงูู ูุชุฎุจ ุงูู ุบุฑุจู ููุชุณู ู ุฃูุถุง "ุฃุณูุฏ ุงูุฃุทูุณ"
Quantized Versions through bitsandbytes
Using 8-bit precision (int8)
pip install bitsandbytes accelerate
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
model_id = "MBZUAI-Paris/Atlas-Chat-9B"
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=quantization_config,
)
text = f"""
ุดุฑุญ ููุง ูุงุฏ ุงููุถุฑุฉ:
ูู ุงููุฑู 19 ููุงู ุงูุฐููุจ ูู ูุงููููุฑููุงุ ูุงุถู ููู ููุจูุนู ุงูุนุชูุฉ ูุงููุงุณ ููููุนู ุงููุงุณ ุจูู ุบูุฏูุฑู ูุงุจุงุณ ููุง ููุจู ุนูู ุงูุฐูุจ... ูุงูุฃุฎูุฑ ุงุบุชูู ุชุฌุงุฑ ุฃุฏูุงุช ุงูุชูููุจ ูุงูุญูุฑ. ูุญุงููุง ูุงูู ููู ููููุน ุงูุฃุฎุฑูู ุจูู ูู ู
ูููููุฑุ ูุนูุฏู ุงูููุช ููุฑูู ููุขุฎุฑูู ูููุงุด ูุฏูุฑู ูุงุจุงุณ.
"""
messages = [
{"role": "user", "content": text},
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=256)
print(tokenizer.decode(outputs[0]).split("<start_of_turn>model")[-1])
- Response:
ูุงุฏ ุงููุถุฑุฉ ูุชูุถุฑ ุนูู ูุตุฉ ูุฏูู ุฉ ู ู ุงููุฑู 19 ููู ุชูุชุดู ุงูุฐูุจ ููุงููููุฑููุง. ูุงุฏ ุงูุดู ุฎูู ุญุงูุฉ ุฏูุงู ุงูุฌููู ุนูู ุงูุฐูุจุ ููู ุจุฒุงู ุฏูุงู ุงููุงุณ ู ุดุงู ูุชู ุง ุจุงุด ูููุจู ุนููู. ูุงูู ุญุชู ูุงุณ ุงููู ูุงูู ููุจูุนู ุฃุฏูุงุช ุงูุชูููุจ ุจุญุงู ุงููุงุณ ูุงูุนุชูุฉุ ููุงูู ููููุนู ุงููุงุณ ุจูู ุบุงุฏู ูุฑุจุญู ุงููููุณ ุฅูุง ู ุดุงู ูููุจู ุนูู ุงูุฐูุจ. ูุงูููุงูุฉุ ูุงุฏูู ุงููู ูุงูู ููุจูุนู ูุงุฏ ุงูุฃุฏูุงุช ููู ุง ุงููู ุฑุจุญู ุจุฒุงูุ ุญูุช ูุงูู ููุฑุจุญู ู ู ูู ูุงุญุฏ ุงููู ูุงู ููุดุฑู ู ููู .
ูุงุฏ ุงููุตุฉ ูุชุดุจู ููู ูุงููุฉ ุฏุงุจุงุ ููู ูุงูููู ูุงุณ ุงููู ููุฏุนูู ุจูู ููู ุง ู ูููููุฑ ูููุจูุนู ูุตุงุฆุญ ุนูู ูููุงุด ุชุฑุจุญ ุงููููุณ. ุจุญุงู ูุงุฏูู ุงููู ูุงูู ููุจูุนู ุงูุฃุฏูุงุช ูุงูู ุงุถูุ ุญุชู ูุงุฏ ุงููุงุณ ููุฑุจุญู ู ู ูุงุฏ ุงูุดูุ ุญูุช ููุงุฎุฏู ุงููููุณ ู ู ุงููุงุณ ุงููู ููุดุฑูู ู ููู ุงููุตุงุฆุญ ุฏูุงููู .
Using 4-bit precision
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
model_id = "MBZUAI-Paris/Atlas-Chat-9B"
quantization_config = BitsAndBytesConfig(load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
quantization_config=quantization_config,
)
text = f"""ุชุฑุฌู
ููุฏุงุฑุฌุฉ:
Atlas Chat is the first open source large language model that talks in Darija.
"""
messages = [
{"role": "user", "content": text},
]
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True, add_generation_prompt=True)
outputs = model.generate(**input_ids, max_new_tokens=256, temperature=0.0)
print(tokenizer.decode(outputs[0]).split("<start_of_turn>model")[-1])
- Response:
ุฃุทููุงุณ ุดุงุช ูู ุฃูู ูู ูุฐุฌ ูุบูู ูุจูุฑ ู ูุชูุญ ุงูู ุตุฏุฑ ูุงููุถุฑ ุจุงูุฏุงุฑุฌุฉ.
Chat Template
The models use a chat template that must be adhered to conversational use. The easiest way to apply it is using the tokenizer's built-in chat template, as shown in the following snippet.
Let's load the model and apply the chat template to a conversation. In this example, we'll start with a single user interaction:
from transformers import AutoTokenizer, AutoModelForCausalLM
import transformers
import torch
model_id = "MBZUAI-Paris/Atlas-Chat-9B"
dtype = torch.bfloat16
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="cuda",
torch_dtype=dtype,)
chat = [
{ "role": "user", "content": "ุฃุดูู ูุงูู
ููุฒ ุงูู
ู
ููุฉ ุงูู
ุบุฑุจูุฉ." },
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
At this point, the prompt contains the following text:
<bos><start_of_turn>user
ุฃุดูู ูุงูู
ููุฒ ุงูู
ู
ููุฉ ุงูู
ุบุฑุจูุฉ.<end_of_turn>
<start_of_turn>model
As you can see, each turn is preceded by a <start_of_turn>
delimiter and then the role of the entity
(either user
, for content supplied by the user, or model
for LLM responses). Turns finish with
the <end_of_turn>
token.
You can follow this format to build the prompt manually, if you need to do it without the tokenizer's chat template.
After the prompt is ready, generation can be performed like this:
inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512)
print(tokenizer.decode(outputs[0]))
- Response:
ุงูู ุบุฑุจ ูุงูู ูุฒู ุจุฒุงู ุฏูุงู ุงูุญูุงูุฌุ ู ููู :
ุงูุชููุน ุงูุซูุงูู: ุงูู ุบุฑุจ ุจูุงุฏ ูููุง ุจุฒุงู ุฏูุงู ุงูุซูุงูุงุชุ ูู ูุญุฏุฉ ูููู ุนูุฏูุง ุงูุชูุงููุฏ ุฏูุงููุง ูุงููุบุฉ ุฏูุงููุง ูุงูู ุงููุฉ ุฏูุงููุง. ูุงุฏ ุงูุชููุน ูุงูุจุงู ูุงูู ูุณููู ูุงูุฑูุต ูุงููููู ุงูุชูููุฏูุฉ.
ุงูุชุฑุงุซ ุงูุชุงุฑูุฎู: ุงูู ุบุฑุจ ุนูุฏู ุชุงุฑูุฎ ุบูู ูุงูู ุชุฏ ูุขูุงู ุงูุณูููุ ููู ุญุถุงุฑุงุช ูุฏูู ุฉ ุจุญุงู ู ู ููุฉ ู ูุฑูุทุงููุงุ ูุงูุฑูู ุงูุ ูุงูุจูุฒูุทูููุ ูุงููุชูุญุงุช ุงูุฅุณูุงู ูุฉ. ูุงุฏ ุงูุชุฑุงุซ ูุงูุจุงู ูุงูู ุนุงูู ุงูุชุงุฑูุฎูุฉ ุจุญุงู ู ุฏููุฉ ูุงุณุ ูุงูู ุฏููุฉ ุงููุฏูู ุฉ ุฏูุงู ู ุฑุงูุดุ ูุงูู ุฏููุฉ ุงููุฏูู ุฉ ุฏูุงู ุดูุดุงูู.
ุงูู ูุงุธุฑ ุงูุทุจูุนูุฉ: ุงูู ุบุฑุจ ุจูุงุฏ ูููุง ู ูุงุธุฑ ุทุจูุนูุฉ ู ุชููุนุฉุ ู ู ุงูุณูุงุญู ุงูุฒุฑูุฉ ูุงูุตุญุงุฑู ุงููุจูุฑุฉุ ููุฌุจุงู ุงูุนุงููุฉ ูุงููุฏูุงู ุงูุฎุถุฑุงุก. ูุงุฏ ุงูุชููุน ูุงูู ููู ู ู ู ู ุงุฑุณุฉ ุฃูุดุทุฉ ุฎุงุฑุฌูุฉ ุจุญุงู ุงูู ุดู ูู ุณุงูุงุช ุทูููุฉุ ูุงูุชุฎููู ุ ูุงูุฑูุงุถุงุช ุงูู ุงุฆูุฉ.
ุงูู ุงููุฉ: ุงูู ุงููุฉ ุงูู ุบุฑุจูุฉ ู ุนุฑููุฉ ุจุงูุชููุน ุฏูุงููุง ูุงูุทุนู ุฏูุงููุง. ู ู ุจูู ุงูุฃุทุจุงู ุงูุฃูุซุฑ ุดุนุจูุฉ ูุงูู ุงูุทุงุฌููุ ูุงููุณูุณุ ูุงูุจุฑููุงุชุ ูุงููููุชูู ุฏูุงู ุงูููุงูู.
ุงููุงุณ: ุงูู ุบุงุฑุจุฉ ู ุนุฑูููู ุจุงูุถูุงูุฉ ุฏูุงููู ูุงูุชุฑุญุงุจ ุฏูุงููู . ูุงููููู ูุฑุญุงููู ุจุงุด ูุดุงุฑูู ุงูุซูุงูุฉ ูุงูุชูุงููุฏ ุฏูุงููู ู ุน ุงูุฒูุงุฑ.
Inputs and outputs
- Input: Text string, such as a question, a prompt, or a document to be summarized.
- Output: Generated Darija text in response to the input, such as an answer to a question, or a summary of a document.
Chatbot interface using Ollama
You can also use Ollama and chatbot-ollama to create a chatbot user-interface to better test the model. First you need to install Ollama on your machine from here and have node.js installed as well. Then, download and prepare the model as follows:
huggingface-cli download MBZUAI-Paris/Atlas-Chat-9B --local-dir Atlas-Chat-9B/
ollama create Atlas-Chat-9B -f Atlas-Chat-9B/modelfile
ollama serve
Finally, in a new terminal clone chatbot-ollama repository from Github and run it:
git clone https://github.com/ivanfioravanti/chatbot-ollama.git
cd chatbot-ollama
npm ci
npm run dev
You can start chatting with the model by visiting http://localhost:3000.
Citation
If you use Atlas-Chat in your research, please cite our paper:
@article{shang2024atlaschatadaptinglargelanguage,
title={Atlas-Chat: Adapting Large Language Models for Low-Resource Moroccan Arabic Dialect},
author={Guokan Shang and Hadi Abdine and Yousef Khoubrane and Amr Mohamed and Yassine Abbahaddou and Sofiane Ennadir and Imane Momayiz and Xuguang Ren and Eric Moulines and Preslav Nakov and Michalis Vazirgiannis and Eric Xing},
year={2024},
eprint={2409.17912},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2409.17912},
}
Training Data
The model was trained on diverse datasets focusing on Darija consisting for approximatley 450k instructions of a maximum length of 2048 tokens, including:
- Synthetic instructions created to guide the model in processing various types of language tasks tailord towards Moroccan culture.
- Instruction samples created from publicly available Moroccan Arabic datasets including translation, summarization and sentiment analysis.
- Translated English and multi-lingual instruction-tuning datasets.
Our training dataset Darija-SFT-Mixture is publicly available.
Implementation Information
Atlas-Chat models are based on Gemma 2 models. The Atlas-Chat models were trained using 8 Nvidia's A100 80 GB GPUs in parallel using FSDP on AWS Sagemaker. The model is trained using HuggingFace transformers and parameter-efficient fine-tuning with LoRA rank of 256.
Evaluation
The Atlas-Chat models were evaluated on a comprehensive suite of tasks using various datasets and benchmarks to assess their performance across multiple dimensions. These included tasks such as:
- DarijaMMLU: A Darija version of ArabicMMLU and MMLU benchmarks translated from MSA and English respectively.
- DarijaHellaSwag: A Darija version of HellaSwag.
- Belebele Ary_Arab: Belebele is a multiple-choice machine reading comprehension dataset published by Facebook spanning 122 language variants. The Evaluation is done on the Ary_Arab part of Belebele that refers to Darija.
- Sentiment Analysis.
- Translation: Including six directions and four languages: Darija, MSA, English and French.
- Summarization.
The models were compared against a collection of existing open-source Arabic models to gauge their effectiveness, with a particular focus on performance in Darija. All scores are based on zero-shot performance. The prompts are written mainly in Darija. The metric used for DarijaMMLU, DarijaHellaSwag, Belebele Ary and Sentiment Analysis is the normalized accuracy. We used Language Model Evaluation Harness to conduct these evaluations.
Model | DarijaMMLU | DarijaHellaSwag | Belebele Ary | Sentiment Analysis | DoDa-10k (Translation) | MArSum (Summarization) (LLM as a judge) |
|
BLEU | chrF | ||||||
jais-family-1p3b-chat | 35.39 | 32.51 | 38.33 | 45.29 | 00.13 | 06.18 | 00.50 |
jais-family-2p7b-chat | 37.44 | 34.49 | 44.11 | 51.56 | 00.25 | 07.46 | 00.90 |
gemma-2-2b-it | 28.58 | 32.42 | 25.22 | 53.36 | 00.10 | 04.96 | 06.80 |
Atlas-Chat-2B | 44.97 | 41.48 | 53.89 | 73.99 | 22.76 | 44.86 | 55.22 |
jais-family-6p7b-chat | 39.96 | 41.57 | 51.22 | 56.78 | 00.73 | 11.85 | 03.02 |
jais-adapted-7b-chat | 39.30 | 35.19 | 43.67 | 52.72 | 00.60 | 09.43 | 02.82 |
jais-family-13b-chat | 45.11 | 43.90 | 58.67 | 41.73 | 00.92 | 11.71 | 01.77 |
jais-adapted-13b-chat | 45.20 | 40.65 | 49.67 | 66.68 | 00.87 | 10.52 | 01.92 |
AceGPT-7b-chat | 35.98 | 36.57 | 30.11 | 40.23 | 00.44 | 11.33 | 02.28 |
AceGPT-13b-chat | 41.09 | 38.35 | 33.11 | 59.58 | 00.98 | 16.70 | 02.80 |
gemma-2-9b-it | 35.91 | 42.43 | 31.00 | 59.87 | 03.10 | 19.16 | 13.81 |
Llama-3.1-8B-Instruct | 44.13 | 38.24 | 47.00 | 44.08 | 00.92 | 14.19 | 01.28 |
Atlas-Chat-9B | 58.23 | 57.75 | 74.56 | 81.89 | 28.08 | 50.48 | 59.76 |
Usage and Limitations
These models have certain limitations that users should be aware of.
Intended Usage
Open Large Language Models (LLMs) have a wide range of applications across various industries and domains. The following list of potential uses is not comprehensive. The purpose of this list is to provide contextual information about the possible use-cases that the model creators considered as part of model training and development.
Content Creation and Communication
- Text Generation: These models can be used to generate creative text formats such as poems, scripts, code, marketing copy, and email drafts.
- Chatbots and Conversational AI: Power conversational interfaces for customer service, virtual assistants, or interactive applications.
- Text Summarization: Generate concise summaries of a text corpus, research papers, or reports.
Research and Education
- Natural Language Processing (NLP) Research: These models can serve as a foundation for researchers to experiment with NLP techniques, develop algorithms, and contribute to the advancement of the field.
- Language Learning Tools: Support interactive language learning experiences, aiding in grammar correction or providing writing practice.
- Knowledge Exploration: Assist researchers in exploring large bodies of text by generating summaries or answering questions about specific topics.
Limitations
Training Data
- The quality and diversity of the training data significantly influence the model's capabilities. Biases or gaps in the training data can lead to limitations in the model's responses.
- The scope of the training dataset determines the subject areas the model can handle effectively.
Context and Task Complexity
- LLMs are better at tasks that can be framed with clear prompts and instructions. Open-ended or highly complex tasks might be challenging.
- A model's performance can be influenced by the amount of context provided (longer context generally leads to better outputs, up to a certain point).
Language Ambiguity and Nuance
- Natural language is inherently complex. LLMs might struggle to grasp subtle nuances, sarcasm, or figurative language.
Factual Accuracy
- LLMs generate responses based on information they learned from their training datasets, but they are not knowledge bases. They may generate incorrect or outdated factual statements.
Common Sense
- LLMs rely on statistical patterns in language. They might lack the ability to apply common sense reasoning in certain situations.
Ethical Considerations and Risks
The development of large language models (LLMs) raises several ethical concerns. In creating an open model, we have carefully considered the following:
- Bias and Fairness
- LLMs trained on large-scale, real-world text data can reflect socio-cultural biases embedded in the training material.
- Misinformation and Misuse
- LLMs can be misused to generate text that is false, misleading, or harmful.
- Guidelines are provided for responsible use with the model, see the [Responsible Generative AI Toolkit][rai-toolkit].
- Transparency and Accountability:
- This model card summarizes details on the models' architecture, capabilities, limitations, and evaluation processes.
- A responsibly developed open model offers the opportunity to share innovation by making LLM technology accessible to developers and researchers across the AI ecosystem.
Risks identified and mitigations:
- Perpetuation of biases: It's encouraged to perform continuous monitoring (using evaluation metrics, human review) and the exploration of de-biasing techniques during model training, fine-tuning, and other use cases.
- Generation of harmful content: Mechanisms and guidelines for content safety are essential. Developers are encouraged to exercise caution and implement appropriate content safety safeguards based on their specific product policies and application use cases.
- Privacy violations: Models were trained on data filtered for removal of PII (Personally Identifiable Information). Developers are encouraged to adhere to privacy regulations with privacy-preserving techniques.
Acknowledgement
We would like to express our gratitude to the following institutions for their contributions to this work: รcole Polytechnique, LINAGORA and KTH Royal Institute of Technology. Additionally, we extend our thanks to the AtlasIA community.