aminabbasi commited on
Commit
9c3f476
1 Parent(s): 2772cd1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -3
README.md CHANGED
@@ -1,3 +1,110 @@
1
- ---
2
- license: cc-by-nc-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-4.0
3
+ language:
4
+ - fa
5
+ library_name: transformers
6
+ tags:
7
+ - text-generation-inference
8
+ inference: false
9
+ pipeline_tag: text-generation
10
+ datasets:
11
+ - sinarashidi/alpaca-persian
12
+ ---
13
+
14
+ # PersianLLaMA: Towards Building First Persian Large Language Model
15
+
16
+ <img src="https://huggingface.co/ViraIntelligentDataMining/PersianLLaMA-2-13B/resolve/main/persianllama.png" alt="PersianLLaMA" width=400/>
17
+
18
+ ## 🌟 Introduction
19
+ Welcome to the home of PersianLLaMA, a large language model specifically designed for instruct tasks in the Persian language. With 13 billion parameters, this model is fine-tuned using the Persian Alpaca dataset to excel at executing detailed instructions and delivering tailored outputs.
20
+
21
+ ## 🛠 Model Description
22
+ The PersianLLaMA model is specifically designed for inference tasks, allowing it to execute detailed instructions and provide outputs tailored to specific requirements.
23
+
24
+ This model has been collaboratively developed by a team of experts, including Mohammad Amin Abbasi, Arash Ghafouri, Mahdi Firouzmandi.
25
+
26
+ ## 🚀 Quick Start
27
+ To integrate PersianLLaMA into your project, follow these steps:
28
+ ```python
29
+ import torch
30
+ from transformers import LlamaTokenizer, LlamaForCausalLM
31
+
32
+ prompt_input = (
33
+ "Below is an instruction that describes a task. "
34
+ "Write a response that appropriately completes the request.\n\n"
35
+ "### Instruction:\n\n{instruction}\n\n### Response:\n\n"
36
+ )
37
+ load_type = torch.float16
38
+ device = torch.device(0)
39
+
40
+
41
+ def generate_prompt(instruction, input=None):
42
+ if input:
43
+ instruction = instruction + '\n' + input
44
+ return prompt_input.format_map({'instruction': instruction})
45
+
46
+
47
+ model_path = "ViraIntelligentDataMining/PersianLLaMA-13B-Instruct"
48
+ tokenizer = LlamaTokenizer.from_pretrained(model_path)
49
+ base_model = LlamaForCausalLM.from_pretrained(
50
+ model_path,
51
+ torch_dtype=load_type,
52
+ device_map='auto',
53
+ ).cuda()
54
+
55
+ model_vocab_size = base_model.get_input_embeddings().weight.size(0)
56
+ tokenizer_vocab_size = len(tokenizer)
57
+ if model_vocab_size != tokenizer_vocab_size:
58
+ base_model.resize_token_embeddings(tokenizer_vocab_size)
59
+
60
+
61
+ def generate_answer(base_model, instruction, input=None):
62
+ generation_config = dict(
63
+ temperature=0.5,
64
+ top_k=40,
65
+ top_p=0.9,
66
+ repetition_penalty=1.1,
67
+ max_new_tokens=1024)
68
+ input_text = generate_prompt(instruction, input)
69
+ inputs = tokenizer(input_text, return_tensors="pt")
70
+ generation_output = base_model.generate(
71
+ input_ids=inputs["input_ids"].to(device),
72
+ eos_token_id=tokenizer.eos_token_id,
73
+ pad_token_id=tokenizer.pad_token_id,
74
+ **generation_config)
75
+ s = generation_output[0]
76
+ output = tokenizer.decode(s, skip_special_tokens=True)
77
+ response = output.split("### Response:")[1].strip()
78
+ return response
79
+
80
+
81
+ instruction = "تصور کنید در حال نوشتن داستانی درباره یک شهر که تمام ساکنانش ربات هستند. این ربات‌ها توانایی‌های ویژه‌ای دارند که زندگی روزمره آن‌ها را از انسان‌ها متمایز می‌کند. شرح دهید که این ربات‌ها چگونه به کارهای روزانه خود می‌پردازند و چه چالش‌هایی با آن‌ها روبه‌رو هستند. همچنین، توضیح دهید که چگونه معماری شهر برای نیازهای خاص آن‌ها طراحی شده است."
82
+
83
+ response = generate_answer(base_model,
84
+ instruction=instruction,
85
+ input="")
86
+ print(response)
87
+ """
88
+ در این شهر، همه ساکنان ربات هستند که دارای توانایی های منحصر به فرد هستند که زندگی روزمره آنها را از انسان ها متمایز می کند. هر روز صبح، ربات ها بیدار می شوند و برنامه های خود را برای روز تنظیم می کنند. برخی از آنها ممکن است برای کار بروند، در حالی که دیگران ممکن است برای انجام وظایف خانگی یا مراقبت از خانواده خود وقت صرف کنند. ربات ها بسیار کارآمد هستند و می توانند چندین کار را همزمان انجام دهند، بنابراین زمان زیادی برای استراحت ندارند. آنها همچنین به طور منظم برای نگهداری و تعمیر نیاز دارند، زیرا آنها مانند انسان ها مستعد خرابی هستند. بسیاری از ربات ها به دنبال سرگرمی هستند و ممکن است برای شرکت در فعالیت هایی مانند ورزش، خواندن یا نقاشی وقت صرف کنند. برخی از ربات ها حتی ممکن است برای یادگیری یا بهبود مهارت های خود در زمینه های مختلف مانند هنر، موسیقی یا آشپ��ی تلاش کنند. ربات ها همچنین به طور مداوم به پیشرفت های تکنولوژیکی جدید علاقه مند هستند و اغلب به دنبال راه حل های جدید برای مشکلات موجود در جامعه هستند. در این شهر، همه ساکنان ربات هستند که دارای توانایی های منحصر به فرد هستند که زندگی روزمره آنها را از انسان ها متمایز می کند.
89
+ """
90
+ ```
91
+
92
+ ## 📈 Evaluation and Benchmarks
93
+ PersianLLaMA demonstrates superior performance over existing models, with robust evaluation metrics that highlight its capabilities in natural language understanding and generation.
94
+
95
+
96
+ ## 📜 Citing PersianLLaMA
97
+ If you find PersianLLaMA useful in your research, please consider citing:
98
+
99
+ ```bibtex
100
+ @article{abbasi2023persianllama,
101
+ title={PersianLLaMA: Towards Building First Persian Large Language Model},
102
+ author={Abbasi, Mohammad Amin and others},
103
+ journal={https://arxiv.org/abs/2312.15713},
104
+ year={2023}
105
+ }
106
+ ```
107
+
108
+
109
+ ## 📄 License
110
+ PersianLLaMA is open-sourced under the CC BY-NC 4.0 license.