Text Generation
GGUF
orca
orca2
microsoft
Inference Endpoints
aashish1904 commited on
Commit
8b431d9
1 Parent(s): bb0a09e

Upload README.md with huggingface_hub

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