Text Generation
Transformers
GGUF
Arabic
conversational
Inference Endpoints
File size: 27,258 Bytes
549fe2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621

---

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 Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)


# QuantFactory/Atlas-Chat-9B-GGUF
This is quantized version of [MBZUAI-Paris/Atlas-Chat-9B](https://huggingface.co/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](https://arxiv.org/abs/2308.16149) 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](https://huggingface.co/MBZUAI-Paris/Atlas-Chat-2B): A small-sized version with 2 billion parameters, capable of generating fluent Moroccan Darija text while maintaining efficiency.
* [Atlas-Chat-9B](https://huggingface.co/MBZUAI-Paris/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](https://arxiv.org/abs/2409.17912)

## ๐Ÿ‘ฅ 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)](https://mbzuai.ac.ae/) 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:

```sh
pip install -U transformers sentencepiece
```

Then, copy the snippet from the section that is relevant for your use case.

#### Running with the `pipeline` API

```python
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

```sh
pip install accelerate
```

```python
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:
>ุงู„ู…ู†ุชุฎุจ ุงู„ู…ุบุฑุจูŠ ูƒูŠุชุณู…ู‰ ุฃูŠุถุง "ุฃุณูˆุฏ ุงู„ุฃุทู„ุณ"


<!-- You can ensure the correct chat template is applied by using `tokenizer.apply_chat_template` as follows:
```python

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, temperature=0.0)

print(tokenizer.decode(outputs[0]))
```

- Response:
```text
<bos><start_of_turn>user
ุดู†ูˆ ู‡ูŠุง ุงู„ุฅูŠุฌุงุจูŠุงุช ุฏูŠุงู„ ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉุŸ<end_of_turn>
<start_of_turn>model
ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉ ุนู†ุฏู‡ุง ุจุฒุงู ุฏูŠุงู„ ุงู„ุฅูŠุฌุงุจูŠุงุชุŒ ู…ู†ู‡ุง:

1. ุงู„ุงุณุชุฏุงู…ุฉ: ู…ุตุงุฏุฑ ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉ ุจุญุงู„ ุงู„ุฑูŠุญุŒ ุงู„ุดู…ุณุŒ ูˆุงู„ุทุงู‚ุฉ ุงู„ูƒู‡ุฑูˆู…ุงุฆูŠุฉ ูƒูŠุชุฌุฏุฏูˆ ุจุดูƒู„ ุทุจูŠุนูŠุŒ ูŠุนู†ูŠ ู…ุง ุบุงุฏูŠุด ูŠู†ูุฏูˆ ู…ุน ุงู„ูˆู‚ุช. ู‡ุงุฏ ุงู„ุดูŠ ูƒูŠุฎู„ูŠู‡ู… ู…ุตุฏุฑ ุทุงู‚ุฉ ู…ุณุชุฏุงู… ุงู„ู„ูŠ ู…ู…ูƒู† ู†ุนุชู…ุฏูˆ ุนู„ูŠู‡ ุนู„ู‰ ุงู„ู…ุฏู‰ ุงู„ุทูˆูŠู„.

2. ุชู‚ู„ูŠู„ ุงู†ุจุนุงุซุงุช ุงู„ูƒุฑุจูˆู†: ู…ุตุงุฏุฑ ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉ ุนู…ูˆู…ุงู‹ ุนู†ุฏู‡ุง ุงู†ุจุนุงุซุงุช ูƒุฑุจูˆู†ูŠุฉ ุฃู‚ู„ ู…ู† ุงู„ูˆู‚ูˆุฏ ุงู„ุฃุญููˆุฑูŠุŒ ูˆู‡ุงุฏ ุงู„ุดูŠ ูƒูŠุณุงุนุฏ ูุงู„ุชุฎููŠู ู…ู† ุงู„ุชุบูŠุฑ ุงู„ู…ู†ุงุฎูŠ ูˆุชู‚ู„ูŠู„ ุชู„ูˆุซ ุงู„ู‡ูˆุงุก.

3. ุงู„ุงุณุชู‚ู„ุงู„ ุงู„ุทุงู‚ูŠ: ู…ุตุงุฏุฑ ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉ ู…ู…ูƒู† ู†ุณุชุนู…ู„ูˆู‡ุง ุจุงุด ู†ู‚ู„ู„ูˆ ู…ู† ุงู„ุงุนุชู…ุงุฏ ุนู„ู‰ ุงู„ูˆู‚ูˆุฏ ุงู„ุฃุญููˆุฑูŠ ุงู„ู…ุณุชูˆุฑุฏุŒ ูˆู‡ุงุฏ ุงู„ุดูŠ ูƒูŠุฒูŠุฏ ู…ู† ุงู„ุงุณุชู‚ู„ุงู„ ุงู„ุทุงู‚ูŠ ูˆูƒูŠู‚ู„ู„ ู…ู† ุฎุทุฑ ุงู„ุชู‚ุทูŠุน.

4. ุฎู„ู‚ ูุฑุต ุงู„ุดุบู„: ุตู†ุงุนุฉ ุงู„ุทุงู‚ุฉ ุงู„ู…ุชุฌุฏุฏุฉ ูƒุชุฎู„ู‚ ูุฑุต ุดุบู„ ูู…ุฌุงู„ุงุช ุจุญุงู„ ุชุฑูƒูŠุจ ุงู„ุฃู„ูˆุงุญ ุงู„ุดู…ุณูŠุฉุŒ ุตูŠุงู†ุฉ ุชูˆุฑุจูŠู†ุงุช ุงู„ุฑูŠุงุญุŒ ูˆุจู†ุงุก ู…ุญุทุงุช
``` -->

#### Quantized Versions through `bitsandbytes`

<details>
  <summary>
    Using 8-bit precision (int8)  
  </summary>

```sh
pip install bitsandbytes accelerate
```

```python
# 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 ููŠู† ุชูƒุชุดู ุงู„ุฐู‡ุจ ููƒุงู„ูŠููˆุฑู†ูŠุง. ู‡ุงุฏ ุงู„ุดูŠ ุฎู„ู‚ ุญุงู„ุฉ ุฏูŠุงู„ ุงู„ุฌู†ูˆู† ุนู„ู‰ ุงู„ุฐู‡ุจุŒ ููŠู† ุจุฒุงู ุฏูŠุงู„ ุงู„ู†ุงุณ ู…ุดุงูˆ ู„ุชู…ุง ุจุงุด ูŠู‚ู„ุจูˆ ุนู„ูŠู‡. ูƒุงู†ูˆ ุญุชู‰ ู†ุงุณ ุงู„ู„ูŠ ูƒุงู†ูˆ ูƒูŠุจูŠุนูˆ ุฃุฏูˆุงุช ุงู„ุชู†ู‚ูŠุจ ุจุญุงู„ ุงู„ูุงุณ ูˆุงู„ุนุชู„ุฉุŒ ูˆูƒุงู†ูˆ ูƒูŠู‚ู†ุนูˆ ุงู„ู†ุงุณ ุจู„ูŠ ุบุงุฏูŠ ูŠุฑุจุญูˆ ุงู„ูู„ูˆุณ ุฅู„ุง ู…ุดุงูˆ ูŠู‚ู„ุจูˆ ุนู„ู‰ ุงู„ุฐู‡ุจ. ูุงู„ู†ู‡ุงูŠุฉุŒ ู‡ุงุฏูˆูƒ ุงู„ู„ูŠ ูƒุงู†ูˆ ูƒูŠุจูŠุนูˆ ู‡ุงุฏ ุงู„ุฃุฏูˆุงุช ู‡ูˆู…ุง ุงู„ู„ูŠ ุฑุจุญูˆ ุจุฒุงูุŒ ุญูŠุช ูƒุงู†ูˆ ูƒูŠุฑุจุญูˆ ู…ู† ูƒู„ ูˆุงุญุฏ ุงู„ู„ูŠ ูƒุงู† ูƒูŠุดุฑูŠ ู…ู†ู‡ู….
>
>ู‡ุงุฏ ุงู„ู‚ุตุฉ ูƒุชุดุจู‡ ู„ู„ูŠ ูƒุงูŠู†ุฉ ุฏุงุจุงุŒ ููŠู† ูƒุงูŠู†ูŠู† ู†ุงุณ ุงู„ู„ูŠ ูƒูŠุฏุนูŠูˆ ุจู„ูŠ ู‡ูˆู…ุง ู…ู„ูŠูˆู†ูŠุฑ ูˆูƒูŠุจูŠุนูˆ ู†ุตุงุฆุญ ุนู„ู‰ ูƒูŠูุงุด ุชุฑุจุญ ุงู„ูู„ูˆุณ. ุจุญุงู„ ู‡ุงุฏูˆูƒ ุงู„ู„ูŠ ูƒุงู†ูˆ ูƒูŠุจูŠุนูˆ ุงู„ุฃุฏูˆุงุช ูุงู„ู…ุงุถูŠุŒ ุญุชู‰ ู‡ุงุฏ ุงู„ู†ุงุณ ูƒูŠุฑุจุญูˆ ู…ู† ู‡ุงุฏ ุงู„ุดูŠุŒ ุญูŠุช ูƒูŠุงุฎุฏูˆ ุงู„ูู„ูˆุณ ู…ู† ุงู„ู†ุงุณ ุงู„ู„ูŠ ูƒูŠุดุฑูŠูˆ ู…ู†ู‡ู… ุงู„ู†ุตุงุฆุญ ุฏูŠุงู„ู‡ู….


</details>

<details>
  <summary>
    Using 4-bit precision  
  </summary>

```python
# 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:

>ุฃุทู„ู‘ุงุณ ุดุงุช ู‡ูˆ ุฃูˆู„ ู†ู…ูˆุฐุฌ ู„ุบูˆูŠ ูƒุจูŠุฑ ู…ูุชูˆุญ ุงู„ู…ุตุฏุฑ ูƒุงูŠู‡ุถุฑ ุจุงู„ุฏุงุฑุฌุฉ.


</details>


### 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:

```python
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:

```python
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:

>ุงู„ู…ุบุฑุจ ูƒุงูŠู…ูŠุฒูˆ ุจุฒุงู ุฏูŠุงู„ ุงู„ุญูˆุงูŠุฌุŒ ู…ู†ู‡ู…:
>
>1. ุงู„ุชู†ูˆุน ุงู„ุซู‚ุงููŠ: ุงู„ู…ุบุฑุจ ุจู„ุงุฏ ููŠู‡ุง ุจุฒุงู ุฏูŠุงู„ ุงู„ุซู‚ุงูุงุชุŒ ูƒู„ ูˆุญุฏุฉ ููŠู‡ู… ุนู†ุฏู‡ุง ุงู„ุชู‚ุงู„ูŠุฏ ุฏูŠุงู„ู‡ุง ูˆุงู„ู„ุบุฉ ุฏูŠุงู„ู‡ุง ูˆุงู„ู…ุงูƒู„ุฉ ุฏูŠุงู„ู‡ุง. ู‡ุงุฏ ุงู„ุชู†ูˆุน ูƒุงูŠุจุงู† ูุงู„ู…ูˆุณูŠู‚ู‰ ูˆุงู„ุฑู‚ุต ูˆุงู„ูู†ูˆู† ุงู„ุชู‚ู„ูŠุฏูŠุฉ.
>
>2. ุงู„ุชุฑุงุซ ุงู„ุชุงุฑูŠุฎูŠ: ุงู„ู…ุบุฑุจ ุนู†ุฏูˆ ุชุงุฑูŠุฎ ุบู†ูŠ ูƒุงูŠู…ุชุฏ ู„ุขู„ุงู ุงู„ุณู†ูŠู†ุŒ ููŠู‡ ุญุถุงุฑุงุช ู‚ุฏูŠู…ุฉ ุจุญุงู„ ู…ู…ู„ูƒุฉ ู…ูˆุฑูŠุทุงู†ูŠุงุŒ ูˆุงู„ุฑูˆู…ุงู†ุŒ ูˆุงู„ุจูŠุฒู†ุทูŠูŠู†ุŒ ูˆุงู„ูุชูˆุญุงุช ุงู„ุฅุณู„ุงู…ูŠุฉ. ู‡ุงุฏ ุงู„ุชุฑุงุซ ูƒุงูŠุจุงู† ูุงู„ู…ุนุงู„ู… ุงู„ุชุงุฑูŠุฎูŠุฉ ุจุญุงู„ ู…ุฏูŠู†ุฉ ูุงุณุŒ ูˆุงู„ู…ุฏูŠู†ุฉ ุงู„ู‚ุฏูŠู…ุฉ ุฏูŠุงู„ ู…ุฑุงูƒุดุŒ ูˆุงู„ู…ุฏูŠู†ุฉ ุงู„ู‚ุฏูŠู…ุฉ ุฏูŠุงู„ ุดูุดุงูˆู†.
>
>3. ุงู„ู…ู†ุงุธุฑ ุงู„ุทุจูŠุนูŠุฉ: ุงู„ู…ุบุฑุจ ุจู„ุงุฏ ููŠู‡ุง ู…ู†ุงุธุฑ ุทุจูŠุนูŠุฉ ู…ุชู†ูˆุนุฉุŒ ู…ู† ุงู„ุณูˆุงุญู„ ุงู„ุฒุฑู‚ุฉ ูˆุงู„ุตุญุงุฑูŠ ุงู„ูƒุจูŠุฑุฉุŒ ู„ู„ุฌุจุงู„ ุงู„ุนุงู„ูŠุฉ ูˆุงู„ูˆุฏูŠุงู† ุงู„ุฎุถุฑุงุก. ู‡ุงุฏ ุงู„ุชู†ูˆุน ูƒุงูŠู…ูƒู†ูƒ ู…ู† ู…ู…ุงุฑุณุฉ ุฃู†ุดุทุฉ ุฎุงุฑุฌูŠุฉ ุจุญุงู„ ุงู„ู…ุดูŠ ู„ู…ุณุงูุงุช ุทูˆูŠู„ุฉุŒ ูˆุงู„ุชุฎูŠูŠู…ุŒ ูˆุงู„ุฑูŠุงุถุงุช ุงู„ู…ุงุฆูŠุฉ.
>
>4. ุงู„ู…ุงูƒู„ุฉ: ุงู„ู…ุงูƒู„ุฉ ุงู„ู…ุบุฑุจูŠุฉ ู…ุนุฑูˆูุฉ ุจุงู„ุชู†ูˆุน ุฏูŠุงู„ู‡ุง ูˆุงู„ุทุนู… ุฏูŠุงู„ู‡ุง. ู…ู† ุจูŠู† ุงู„ุฃุทุจุงู‚ ุงู„ุฃูƒุซุฑ ุดุนุจูŠุฉ ูƒุงูŠู† ุงู„ุทุงุฌูŠู†ุŒ ูˆุงู„ูƒุณูƒุณุŒ ูˆุงู„ุจุฑูŠูˆุงุชุŒ ูˆุงู„ูƒูˆูƒุชูŠู„ ุฏูŠุงู„ ุงู„ููˆุงูƒู‡.
>
>5. ุงู„ู†ุงุณ: ุงู„ู…ุบุงุฑุจุฉ ู…ุนุฑูˆููŠู† ุจุงู„ุถูŠุงูุฉ ุฏูŠุงู„ู‡ู… ูˆุงู„ุชุฑุญุงุจ ุฏูŠุงู„ู‡ู…. ูƒุงูŠูƒูˆู†ูˆ ูุฑุญุงู†ูŠู† ุจุงุด ูŠุดุงุฑูƒูˆ ุงู„ุซู‚ุงูุฉ ูˆุงู„ุชู‚ุงู„ูŠุฏ ุฏูŠุงู„ู‡ู… ู…ุน ุงู„ุฒูˆุงุฑ.




### 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](https://github.com/ollama/ollama) and have node.js installed as well. Then, download and prepare the model as follows:
```bash

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:
```bash
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:
```none
@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](https://huggingface.co/datasets/MBZUAI-Paris/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](https://github.com/MBZUAI-Paris/lm-evaluation-harness-atlas-chat) to conduct these evaluations.

<table>
    <tr>
        <td rowspan="2">Model</td>
        <td rowspan="2"><a href="https://huggingface.co/datasets/MBZUAI-Paris/DarijaMMLU" target="_blank">DarijaMMLU</a></td>
        <td rowspan="2"><a href="MBZUAI-Paris/DarijaHellaSwag" target="_blank">DarijaHellaSwag</a></td>
        <td rowspan="2"><a href="https://huggingface.co/datasets/facebook/belebele/viewer/ary_Arab" target="_blank">Belebele Ary</a></td>
        <td rowspan="2"><a href="https://huggingface.co/datasets/MBZUAI-Paris/DarijaBench" target="_blank">Sentiment Analysis</a></td>
        <td colspan="2"><a href="https://huggingface.co/datasets/MBZUAI-Paris/DarijaBench" target="_blank">DoDa-10k (Translation)</a></td>
        <td rowspan="2"><a href="https://huggingface.co/datasets/MBZUAI-Paris/DarijaBench" target="_blank">MArSum (Summarization)</a><br/>(LLM as a judge)</td>
    </tr>
    <tr>
        <td>BLEU</td>
        <td>chrF</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-family-1p3b-chat" target="_blank">jais-family-1p3b-chat</a></td>
        <td>35.39</td>
        <td>32.51</td>
        <td>38.33</td>
        <td>45.29</td>
        <td>00.13</td>
        <td>06.18</td>
        <td>00.50</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-family-2p7b-chat" target="_blank">jais-family-2p7b-chat</a></td>
        <td>37.44</td>
        <td>34.49</td>
        <td>44.11</td>
        <td>51.56</td>
        <td>00.25</td>
        <td>07.46</td>
        <td>00.90</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/google/gemma-2-2b-it" target="_blank">gemma-2-2b-it</a></td>
        <td>28.58</td>
        <td>32.42</td>
        <td>25.22</td>
        <td>53.36</td>
        <td>00.10</td>
        <td>04.96</td>
        <td>06.80</td>
    </tr>
    <tr>
        <td><strong><a href="https://huggingface.co/MBZUAI-Paris/Atlas-Chat-2B" target="_blank">Atlas-Chat-2B</a></strong></td>
        <td><b>44.97</td>
        <td><b>41.48</td>
        <td><b>53.89</td>
        <td><b>73.99</td>
        <td><b>22.76</td>
        <td><b>44.86</td>
        <td><b>55.22</td>
    </tr>
    <tr style="border-top: 4px solid;"></tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-family-6p7b-chat" target="_blank">jais-family-6p7b-chat</a></td>
        <td>39.96</td>
        <td>41.57</td>
        <td>51.22</td>
        <td>56.78</td>
        <td>00.73</td>
        <td>11.85</td>
        <td>03.02</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-adapted-7b-chat" target="_blank">jais-adapted-7b-chat</a></td>
        <td>39.30</td>
        <td>35.19</td>
        <td>43.67</td>
        <td>52.72</td>
        <td>00.60</td>
        <td>09.43</td>
        <td>02.82</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-family-13b-chat" target="_blank">jais-family-13b-chat</a></td>
        <td>45.11</td>
        <td>43.90</td>
        <td>58.67</td>
        <td>41.73</td>
        <td>00.92</td>
        <td>11.71</td>
        <td>01.77</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/inceptionai/jais-adapted-13b-chat" target="_blank">jais-adapted-13b-chat</a></td>
        <td>45.20</td>
        <td>40.65</td>
        <td>49.67</td>
        <td>66.68</td>
        <td>00.87</td>
        <td>10.52</td>
        <td>01.92</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/FreedomIntelligence/AceGPT-7B-chat" target="_blank">AceGPT-7b-chat</a></td>
        <td>35.98</td>
        <td>36.57</td>
        <td>30.11</td>
        <td>40.23</td>
        <td>00.44</td>
        <td>11.33</td>
        <td>02.28</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/FreedomIntelligence/AceGPT-13B-chat" target="_blank">AceGPT-13b-chat</a></td>
        <td>41.09</td>
        <td>38.35</td>
        <td>33.11</td>
        <td>59.58</td>
        <td>00.98</td>
        <td>16.70</td>
        <td>02.80</td>
    </tr>
    <tr>
        <td><a href="https://huggingface.co/google/gemma-2-9b-it" target="_blank">gemma-2-9b-it</a></td>
        <td>35.91</td>
        <td>42.43</td>
        <td>31.00</td>
        <td>59.87</td>
        <td>03.10</td>
        <td>19.16</td>
        <td>13.81</td>
    </tr>
    <tr>
        <td><a href="meta-llama/Meta-Llama-3.1-8B-Instruct" target="_blank">Llama-3.1-8B-Instruct</a></td>
        <td>44.13</td>
        <td>38.24</td>
        <td>47.00</td>
        <td>44.08</td>
        <td>00.92</td>
        <td>14.19</td>
        <td>01.28</td>
    </tr>
    <tr>
        <td><strong><a href="https://huggingface.co/MBZUAI-Paris/Atlas-Chat-9B" target="_blank">Atlas-Chat-9B</a></strong></td>
        <td><b>58.23</td>
        <td><b>57.75</td>
        <td><b>74.56</td>
        <td><b>81.89</td>
        <td><b>28.08</td>
        <td><b>50.48</td>
        <td><b>59.76</td>
    </tr>


    
</table>


## Usage and Limitations

These models have certain limitations that users should be aware of.
<details>
<summary>Intended Usage</summary>

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.
</details>
<details>
<summary>Limitations</summary>

* 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.
</details>
<details>
<summary> Ethical Considerations and Risks</summary>

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.

</details>


## 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.