Views
No views yet
pip install -U transformers sentencepiecepipeline API1import torch
2from transformers import pipeline
3
4pipe = pipeline(
5 "text-generation",
6 model="MBZUAI-Paris/Atlas-Chat-2B",
7 model_kwargs={"torch_dtype": torch.bfloat16},
8 device="cuda" # replace with "mps" to run on a Mac device
9)
10
11messages = [
12 {"role": "user", "content": 'شكون لي صنعك؟'},
13]
14
15outputs = pipe(messages, max_new_tokens=256, temperature=0.0)
16assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
17print(assistant_response)قادّوني الباحثين والمهندسين ديال جامعة محمد بن زايد للذكاء الاصطناعي. جامعة محمد بن زايد للذكاء الاصطناعي هي جامعة ديال البحت والدراسات العليا، كتّخصّص فتعزيز الذكاء الاصطناعي والاستعمال ديالو لمصلحة الإنسانية. يمكن ليك تزور https://mbzuai.ac.ae/ar/about/ باش تعرف كثر على جامعة محمد بن زايد للذكاء الاصطناعي والمهمة ديالها!
pip install accelerate1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4model_id = "MBZUAI-Paris/Atlas-Chat-2B"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id,
8 device_map="auto",
9 torch_dtype=torch.bfloat16,
10)
11
12messages = [
13 {"role": "user", "content": "شنو كيتسمى المنتخب المغربي ؟"},
14]
15
16input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True, , add_generation_prompt=True)
17
18outputs = model.generate(**input_ids, max_new_tokens=256)
19
20print(tokenizer.decode(outputs[0]))المنتخب المغربي كيتسمى "أسود الاطلس".
bitsandbytespip install bitsandbytes accelerate1# pip install bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4model_id = "MBZUAI-Paris/Atlas-Chat-2B"
5quantization_config = BitsAndBytesConfig(load_in_8bit=True)
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 quantization_config=quantization_config,
11)
12text = f"""
13 شرح ليا هاد الهضرة:
14 في القرن 19 لقاو الذّهب في كاليفورنيا، ناضو لّي كيبيعو العتلة والفاس كيقنعو الناس بلي غيديرو لاباس يلا قلبو على الذهب... فالأخير اغتنى تجار أدوات التنقيب والحفر. وحاليا كاين لّي كيقنع الأخرين بلي هو مليونير، وعندو الوقت يورّي للآخرين كيفاش يديرو لاباس.
15 """
16messages = [
17 {"role": "user", "content": text},
18]
19input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True).to("cuda")
20
21outputs = model.generate(**input_ids, max_new_tokens=256)
22print(tokenizer.decode(outputs[0]).split("<start_of_turn>model")[-1])ف القرن 19، لقاو الذهب ف كاليفورنيا، وهاد الشي جاب بزاف ديال الناس باش يمشيو ليه. هاد الناس كانو كيبيعو العتلة والفاس وكيتظاهرو بلي إلا قلبو على الذهب غادي يلقاو ليه. ف الآخر، هاد التجار ديال التنقيب والحفر كانو كيتغلبو على الناس اللي بغاو يقلبو على الذهب.دابا، كاينين ناس اللي كيتظاهرو بلي هوما مليونيرين وكيتظاهرو بلي عندهم الوقت يورّيو للناس كيفاش يلقاو الذهب. هاد الناس كيتظاهرو بلي عندهم الخبرة والخبرة باش يلقاو الذهب، ولكن ف الحقيقة، هاد الشي ماشي صحيح.
1# pip install bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3
4model_id = "MBZUAI-Paris/Atlas-Chat-2B"
5quantization_config = BitsAndBytesConfig(load_in_4bit=True)
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 quantization_config=quantization_config,
11)
12text = f"""ترجم للدارجة:
13Atlas Chat is the first open source large language model that talks in Darija.
14 """
15messages = [
16 {"role": "user", "content": text},
17]
18input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", return_dict=True, add_generation_prompt=True)
19
20outputs = model.generate(**input_ids, max_new_tokens=256, temperature=0.0)
21print(tokenizer.decode(outputs[0]).split("<start_of_turn>model")[-1])إن أطلاس شات هو أول نموذج لغة كبير مفتوح المصدر كيهضر بالدارجة.
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import transformers
3import torch
4
5model_id = "MBZUAI-Paris/Atlas-Chat-2B"
6dtype = torch.bfloat16
7
8tokenizer = AutoTokenizer.from_pretrained(model_id)
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 device_map="cuda",
12 torch_dtype=dtype,)
13
14chat = [
15 { "role": "user", "content": "اشنو هو الطاجين ؟"},
16]
17prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)<bos><start_of_turn>user
اشنو هو الطاجين ؟<end_of_turn>
<start_of_turn>model<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.1inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
2outputs = model.generate(input_ids=inputs.to(model.device), max_new_tokens=512)
3print(tokenizer.decode(outputs[0]))الطاجين هو طبق تقليدي مغربي كيتصاوب من اللحم ولا الدجاج ولا الخضرة، مع الخضرة، والبهارات، والصلصة. كيتطيب فالمقلاة ولا فالمقلى على نار هادية لمدة طويلة، وهاد الشي كيخلي اللحم يطيب بشوية ويبدا يذوب. الطاجين معروف بعمق النكهة ديالو والريحة ديالو، وغالبا كيتقدم مع الرز ولا الخبز.
1
2huggingface-cli download MBZUAI-Paris/Atlas-Chat-2B --local-dir Atlas-Chat-2B/
3ollama create Atlas-Chat-2B -f Atlas-Chat-2B/modelfile
4ollama serve1git clone https://github.com/ivanfioravanti/chatbot-ollama.git
2cd chatbot-ollama
3npm ci
4npm run dev1@article{shang2024atlaschatadaptinglargelanguage,
2 title={Atlas-Chat: Adapting Large Language Models for Low-Resource Moroccan Arabic Dialect},
3 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},
4 year={2024},
5 eprint={2409.17912},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2409.17912},
9}| Model | DarijaMMLU | DarijaHellaSwag | Belebele Ary | DarijaAlpacaEval |
| jais-family-1p3b-chat | 35.39 | 27.71 | 38.33 | 35.56 |
| jais-family-2p7b-chat | 37.44 | 29.10 | 44.11 | 52.97 |
| gemma-2-2b-it | 28.58 | 32.42 | 25.22 | 58.67 |
| Llama-3.2-1B-Instruct | 27.66 | 26.88 | 28.89 | 23.57 |
| Llama-3.2-3B-Instruct | 32.60 | 28.33 | 38.00 | 47.62 |
| Atlas-Chat-2B | 44.97 | 35.08 | 53.89 | 92.31 |
| jais-family-6p7b-chat | 39.96 | 32.64 | 51.22 | 65.18 |
| jais-adapted-7b-chat | 39.30 | 29.55 | 43.67 | 61.84 |
| jais-family-13b-chat | 45.11 | 33.98 | 58.67 | 69.93 |
| jais-adapted-13b-chat | 45.20 | 32.84 | 49.67 | 77.52 |
| AceGPT-7b-chat | 35.98 | 30.33 | 30.11 | 47.31 |
| AceGPT-13b-chat | 41.09 | 38.35 | 33.11 | 52.79 |
| gemma-2-9b-it | 35.91 | 32.19 | 31.00 | 90.86 |
| Llama-3.1-8B-Instruct | 44.13 | 31.40 | 47.00 | 78.08 |
| Atlas-Chat-9B | 58.23 | 43.65 | 74.56 | 95.62 |
| jais-family-30b-8k-chat | 51.88 | 35.61 | 65.67 | 24.64 |
| gemma-2-27b-it | 36.47 | 37.04 | 35.78 | 95.07 |
| Atlas-Chat-27B | 61.95 | 48.37 | 75.67 | 96.58 |
| Model | DODa-10k (Translation) | MADAR (Translation) | FLORES+ (Translation) | NLLB-Seed (Translation) | DODa-10k (Transliteration) | MArSum (Summarization) (LLM as a judge) | Sentiment Analysis | |||||
| BLEU | chrF | BLEU | chrF | BLEU | chrF | BLEU | chrF | BLEU | chrF | |||
| jais-family-1p3b-chat | 00.13 | 06.18 | 00.50 | 15.43 | 02.44 | 19.14 | 01.99 | 12.60 | 00.01 | 03.01 | 00.50 | 45.29 |
| jais-family-2p7b-chat | 00.25 | 07.46 | 00.62 | 16.36 | 04.25 | 18.22 | 03.10 | 08.19 | 00.01 | 03.27 | 00.90 | 51.56 |
| gemma-2-2b-it | 00.10 | 04.96 | 00.12 | 06.66 | 01.55 | 18.59 | 02.78 | 23.69 | 00.01 | 02.08 | 06.80 | 53.36 |
| Llama-3.2-1B-Instruct | 00.07 | 05.95 | 00.80 | 18.71 | 04.53 | 18.39 | 04.52 | 17.06 | 00.02 | 03.74 | 08.23 | 46.27 |
| Llama-3.2-3B-Instruct | 00.62 | 13.67 | 01.18 | 22.12 | 08.59 | 35.21 | 13.75 | 43.63 | 00.21 | 09.68 | 08.23 | 49.20 |
| Atlas-Chat-2B | 22.76 | 44.86 | 16.67 | 41.64 | 14.92 | 43.03 | 23.88 | 52.19 | 08.18 | 21.54 | 55.22 | 73.99 |
| jais-family-6p7b-chat | 00.73 | 11.85 | 01.88 | 23.22 | 04.25 | 18.22 | 04.62 | 20.22 | 00.02 | 03.79 | 03.02 | 56.78 |
| jais-adapted-7b-chat | 00.60 | 09.43 | 03.45 | 25.88 | 07.25 | 23.21 | 01.25 | 02.22 | 00.04 | 03.24 | 02.82 | 52.72 |
| jais-family-13b-chat | 00.92 | 11.71 | 04.01 | 28.48 | 05.70 | 27.24 | 04.50 | 22.56 | 00.03 | 03.57 | 01.77 | 41.73 |
| jais-adapted-13b-chat | 00.87 | 10.52 | 04.02 | 25.29 | 06.66 | 23.46 | 20.14 | 47.87 | 0.04 | 04.77 | 01.92 | 66.68 |
| AceGPT-7b-chat | 00.44 | 11.33 | 01.05 | 19.24 | 06.92 | 36.03 | 11.05 | 44.55 | 00.06 | 04.74 | 02.28 | 40.23 |
| AceGPT-13b-chat | 00.98 | 16.70 | 00.81 | 20.23 | 08.73 | 40.76 | 14.02 | 48.28 | 00.12 | 06.32 | 02.80 | 59.58 |
| gemma-2-9b-it | 03.10 | 19.16 | 01.72 | 24.35 | 05.18 | 36.96 | 08.23 | 43.57 | 00.17 | 09.14 | 13.81 | 59.87 |
| Llama-3.1-8B-Instruct | 00.92 | 14.19 | 01.46 | 23.82 | 08.89 | 33.08 | 11.85 | 35.51 | 00.11 | 06.02 | 16.14 | 44.08 |
| Atlas-Chat-9B | 28.08 | 50.48 | 18.16 | 43.91 | 18.63 | 47.53 | 29.98 | 58.26 | 22.08 | 34.17 | 59.76 | 81.89 |
| jais-family-30b-8k-chat | 01.10 | 14.40 | 01.67 | 23.37 | 08.52 | 35.41 | 13.71 | 41.33 | 00.05 | 04.48 | 00.46 | 56.73 |
| gemma-2-27b-it | 00.67 | 13.04 | 01.74 | 24.63 | 05.17 | 37.08 | 07.36 | 42.49 | 00.03 | 04.94 | 11.10 | 57.59 |
| Atlas-Chat-27B | 29.55 | 51.74 | 19.66 | 45.65 | 20.34 | 49.19 | 31.61 | 59.37 | 33.03 | 40.95 | 60.70 | 73.00 |