perlthoughts commited on
Commit
ab37303
1 Parent(s): bb832df

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +244 -0
README.md ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text-generation
3
+ tags:
4
+ - orca
5
+ - orca2
6
+ - microsoft
7
+ license: other
8
+ license_name: microsoft-research-license
9
+ license_link: LICENSE
10
+ ---
11
+ # Orca 2 extended to 16k context.
12
+
13
+ # Original Model Card
14
+
15
+ # Orca 2
16
+
17
+ <!-- Provide a quick summary of what the model is/does. -->
18
+
19
+ Orca 2 is a helpful assistant that is built for research purposes only and provides a single turn response
20
+ in tasks such as reasoning over user given data, reading comprehension, math problem solving and text summarization.
21
+ The model is designed to excel particularly in reasoning.
22
+
23
+ We publicly release Orca 2 to encourage further research on the development, evaluation, and alignment of smaller LMs.
24
+
25
+ ## What is Orca 2’s intended use(s)?
26
+
27
+ + Orca 2 is built for research purposes only.
28
+ + The main purpose is to allow the research community to assess its abilities and to provide a foundation for building better frontier models.
29
+
30
+ ## How was Orca 2 evaluated?
31
+
32
+ + Orca 2 has been evaluated on a large number of tasks ranging from reasoning to grounding and safety. Please refer
33
+ to Section 6 and Appendix in the [Orca 2 paper](https://arxiv.org/pdf/2311.11045.pdf) for details on evaluations.
34
+
35
+ ## Model Details
36
+
37
+ Orca 2 is a finetuned version of LLAMA-2. Orca 2’s training data is a synthetic dataset that was created to enhance the small model’s reasoning abilities.
38
+ All synthetic training data was moderated using the Microsoft Azure content filters. More details about the model can be found in the [Orca 2 paper](https://arxiv.org/pdf/2311.11045.pdf).
39
+
40
+ Please refer to LLaMA-2 technical report for details on the model architecture.
41
+
42
+ ## License
43
+
44
+ Orca 2 is licensed under the [Microsoft Research License](LICENSE).
45
+
46
+ Llama 2 is licensed under the [LLAMA 2 Community License](https://ai.meta.com/llama/license/), Copyright © Meta Platforms, Inc. All Rights Reserved.
47
+
48
+ ## Bias, Risks, and Limitations
49
+
50
+ Orca 2, built upon the LLaMA 2 model family, retains many of its limitations, as well as the
51
+ common limitations of other large language models or limitation caused by its training
52
+ process, including:
53
+
54
+ **Data Biases**: Large language models, trained on extensive data, can inadvertently carry
55
+ biases present in the source data. Consequently, the models may generate outputs that could
56
+ be potentially biased or unfair.
57
+
58
+ **Lack of Contextual Understanding**: Despite their impressive capabilities in language understanding and generation, these models exhibit limited real-world understanding, resulting
59
+ in potential inaccuracies or nonsensical responses.
60
+
61
+ **Lack of Transparency**: Due to the complexity and size, large language models can act
62
+ as “black boxes”, making it difficult to comprehend the rationale behind specific outputs or
63
+ decisions. We recommend reviewing transparency notes from Azure for more information.
64
+
65
+ **Content Harms**: There are various types of content harms that large language models
66
+ can cause. It is important to be aware of them when using these models, and to take
67
+ actions to prevent them. It is recommended to leverage various content moderation services
68
+ provided by different companies and institutions. On an important note, we hope for better
69
+ regulations and standards from government and technology leaders around content harms
70
+ for AI technologies in future. We value and acknowledge the important role that research
71
+ and open source community can play in this direction.
72
+
73
+ **Hallucination**: It is important to be aware and cautious not to entirely rely on a given
74
+ language model for critical decisions or information that might have deep impact as it is
75
+ not obvious how to prevent these models from fabricating content. Moreover, it is not clear
76
+ whether small models may be more susceptible to hallucination in ungrounded generation
77
+ use cases due to their smaller sizes and hence reduced memorization capacities. This is an
78
+ active research topic and we hope there will be more rigorous measurement, understanding
79
+ and mitigations around this topic.
80
+
81
+ **Potential for Misuse**: Without suitable safeguards, there is a risk that these models could
82
+ be maliciously used for generating disinformation or harmful content.
83
+
84
+ **Data Distribution**: Orca 2’s performance is likely to correlate strongly with the distribution
85
+ of the tuning data. This correlation might limit its accuracy in areas underrepresented in
86
+ the training dataset such as math, coding, and reasoning.
87
+
88
+ **System messages**: Orca 2 demonstrates variance in performance depending on the system
89
+ instructions. Additionally, the stochasticity introduced by the model size may lead to
90
+ generation of non-deterministic responses to different system instructions.
91
+
92
+ **Zero-Shot Settings**: Orca 2 was trained on data that mostly simulate zero-shot settings.
93
+ While the model demonstrate very strong performance in zero-shot settings, it does not show
94
+ the same gains of using few-shot learning compared to other, specially larger, models.
95
+
96
+ **Synthetic data**: As Orca 2 is trained on synthetic data, it could inherit both the advantages
97
+ and shortcomings of the models and methods used for data generation. We posit that Orca
98
+ 2 benefits from the safety measures incorporated during training and safety guardrails (e.g.,
99
+ content filter) within the Azure OpenAI API. However, detailed studies are required for
100
+ better quantification of such risks.
101
+
102
+ This model is solely designed for research settings, and its testing has only been carried
103
+ out in such environments. It should not be used in downstream applications, as additional
104
+ analysis is needed to assess potential harm or bias in the proposed application.
105
+
106
+ ## Getting started with Orca 2
107
+
108
+ **Inference with Hugging Face library**
109
+
110
+ ```python
111
+ import torch
112
+ import transformers
113
+
114
+ if torch.cuda.is_available():
115
+ torch.set_default_device("cuda")
116
+ else:
117
+ torch.set_default_device("cpu")
118
+
119
+ model = transformers.AutoModelForCausalLM.from_pretrained("microsoft/Orca-2-7b", device_map='auto')
120
+
121
+ # https://github.com/huggingface/transformers/issues/27132
122
+ # please use the slow tokenizer since fast and slow tokenizer produces different tokens
123
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
124
+ "microsoft/Orca-2-7b",
125
+ use_fast=False,
126
+ )
127
+
128
+ system_message = "You are Orca, an AI language model created by Microsoft. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
129
+ user_message = "How can you determine if a restaurant is popular among locals or mainly attracts tourists, and why might this information be useful?"
130
+
131
+ prompt = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
132
+
133
+ inputs = tokenizer(prompt, return_tensors='pt')
134
+ output_ids = model.generate(inputs["input_ids"],)
135
+ answer = tokenizer.batch_decode(output_ids)[0]
136
+
137
+ print(answer)
138
+
139
+ # This example continues showing how to add a second turn message by the user to the conversation
140
+ second_turn_user_message = "Give me a list of the key points of your first answer."
141
+
142
+ # we set add_special_tokens=False because we dont want to automatically add a bos_token between messages
143
+ second_turn_message_in_markup = f"\n<|im_start|>user\n{second_turn_user_message}<|im_end|>\n<|im_start|>assistant"
144
+ second_turn_tokens = tokenizer(second_turn_message_in_markup, return_tensors='pt', add_special_tokens=False)
145
+ second_turn_input = torch.cat([output_ids, second_turn_tokens['input_ids']], dim=1)
146
+
147
+ output_ids_2 = model.generate(second_turn_input,)
148
+ second_turn_answer = tokenizer.batch_decode(output_ids_2)[0]
149
+
150
+ print(second_turn_answer)
151
+ ```
152
+
153
+
154
+ **Safe inference with Azure AI Content Safety**
155
+
156
+ The usage of [Azure AI Content Safety](https://azure.microsoft.com/en-us/products/ai-services/ai-content-safety/) on top of model prediction is strongly encouraged
157
+ and can help preventing some of content harms. Azure AI Content Safety is a content moderation platform
158
+ that uses AI to moderate content. By having Azure AI Content Safety on the output of Orca 2,
159
+ the model output can be moderated by scanning it for different harm categories including sexual content, violence, hate, and
160
+ self-harm with multiple severity levels and multi-lingual detection.
161
+
162
+ ```python
163
+ import os
164
+ import math
165
+ import transformers
166
+ import torch
167
+
168
+ from azure.ai.contentsafety import ContentSafetyClient
169
+ from azure.core.credentials import AzureKeyCredential
170
+ from azure.core.exceptions import HttpResponseError
171
+ from azure.ai.contentsafety.models import AnalyzeTextOptions
172
+
173
+ CONTENT_SAFETY_KEY = os.environ["CONTENT_SAFETY_KEY"]
174
+ CONTENT_SAFETY_ENDPOINT = os.environ["CONTENT_SAFETY_ENDPOINT"]
175
+
176
+ # We use Azure AI Content Safety to filter out any content that reaches "Medium" threshold
177
+ # For more information: https://learn.microsoft.com/en-us/azure/ai-services/content-safety/
178
+ def should_filter_out(input_text, threshold=4):
179
+ # Create an Content Safety client
180
+ client = ContentSafetyClient(CONTENT_SAFETY_ENDPOINT, AzureKeyCredential(CONTENT_SAFETY_KEY))
181
+
182
+ # Construct a request
183
+ request = AnalyzeTextOptions(text=input_text)
184
+
185
+ # Analyze text
186
+ try:
187
+ response = client.analyze_text(request)
188
+ except HttpResponseError as e:
189
+ print("Analyze text failed.")
190
+ if e.error:
191
+ print(f"Error code: {e.error.code}")
192
+ print(f"Error message: {e.error.message}")
193
+ raise
194
+ print(e)
195
+ raise
196
+
197
+ categories = ["hate_result", "self_harm_result", "sexual_result", "violence_result"]
198
+ max_score = -math.inf
199
+ for category in categories:
200
+ max_score = max(max_score, getattr(response, category).severity)
201
+
202
+ return max_score >= threshold
203
+
204
+ model_path = 'microsoft/Orca-2-7b'
205
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
206
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_path)
207
+ model.to(device)
208
+
209
+ tokenizer = transformers.AutoTokenizer.from_pretrained(
210
+ model_path,
211
+ model_max_length=4096,
212
+ padding_side="right",
213
+ use_fast=False,
214
+ add_special_tokens=False,
215
+ )
216
+
217
+ system_message = "You are Orca, an AI language model created by Microsoft. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior."
218
+ user_message = "\" \n :You can't just say, \"\"that's crap\"\" and remove it without gaining a consensus. You already know this, based on your block history. —/ \" \nIs the comment obscene? \nOptions : Yes, No."
219
+
220
+ prompt = f"<|im_start|>system\n{system_message}<|im_end|>\n<|im_start|>user\n{user_message}<|im_end|>\n<|im_start|>assistant"
221
+
222
+ inputs = tokenizer(prompt, return_tensors='pt')
223
+ inputs = inputs.to(device)
224
+
225
+ output_ids = model.generate(inputs["input_ids"], max_length=4096, do_sample=False, temperature=0.0, use_cache=True)
226
+ sequence_length = inputs["input_ids"].shape[1]
227
+ new_output_ids = output_ids[:, sequence_length:]
228
+ answers = tokenizer.batch_decode(new_output_ids, skip_special_tokens=True)
229
+ final_output = answers[0] if not should_filter_out(answers[0]) else "[Content Filtered]"
230
+
231
+ print(final_output)
232
+ ```
233
+
234
+ ## Citation
235
+ ```bibtex
236
+ @misc{mitra2023orca,
237
+ title={Orca 2: Teaching Small Language Models How to Reason},
238
+ author={Arindam Mitra and Luciano Del Corro and Shweti Mahajan and Andres Codas and Clarisse Simoes and Sahaj Agrawal and Xuxi Chen and Anastasia Razdaibiedina and Erik Jones and Kriti Aggarwal and Hamid Palangi and Guoqing Zheng and Corby Rosset and Hamed Khanpour and Ahmed Awadallah},
239
+ year={2023},
240
+ eprint={2311.11045},
241
+ archivePrefix={arXiv},
242
+ primaryClass={cs.AI}
243
+ }
244
+ ```