RichardErkhov commited on
Commit
1b9b063
1 Parent(s): 4ca0326

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +355 -0
README.md ADDED
@@ -0,0 +1,355 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ LlamaGuard-7b - bnb 4bits
11
+ - Model creator: https://huggingface.co/meta-llama/
12
+ - Original model: https://huggingface.co/meta-llama/LlamaGuard-7b/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ extra_gated_heading: You need to share contact information with Meta to access this model
20
+ extra_gated_prompt: >-
21
+ ### LLAMA 2 COMMUNITY LICENSE AGREEMENT
22
+
23
+ "Agreement" means the terms and conditions for use, reproduction, distribution
24
+ and modification of the Llama Materials set forth herein.
25
+
26
+ "Documentation" means the specifications, manuals and documentation
27
+ accompanying Llama 2 distributed by Meta at
28
+ https://ai.meta.com/resources/models-and-libraries/llama-downloads/.
29
+
30
+ "Licensee" or "you" means you, or your employer or any other person or entity
31
+ (if you are entering into this Agreement on such person or entity's behalf),
32
+ of the age required under applicable laws, rules or regulations to provide
33
+ legal consent and that has legal authority to bind your employer or such other
34
+ person or entity if you are entering in this Agreement on their behalf.
35
+
36
+ "Llama 2" means the foundational large language models and software and
37
+ algorithms, including machine-learning model code, trained model weights,
38
+ inference-enabling code, training-enabling code, fine-tuning enabling code and
39
+ other elements of the foregoing distributed by Meta at
40
+ ai.meta.com/resources/models-and-libraries/llama-downloads/.
41
+
42
+ "Llama Materials" means, collectively, Meta's proprietary Llama 2 and
43
+ documentation (and any portion thereof) made available under this Agreement.
44
+
45
+ "Meta" or "we" means Meta Platforms Ireland Limited (if you are located in or,
46
+ if you are an entity, your principal place of business is in the EEA or
47
+ Switzerland) and Meta Platforms, Inc. (if you are located outside of the EEA
48
+ or Switzerland).
49
+
50
+
51
+ By clicking "I Accept" below or by using or distributing any portion or
52
+ element of the Llama Materials, you agree to be bound by this Agreement.
53
+
54
+ 1. License Rights and Redistribution.
55
+
56
+ a. Grant of Rights. You are granted a non-exclusive, worldwide, non-
57
+ transferable and royalty-free limited license under Meta's intellectual
58
+ property or other rights owned by Meta embodied in the Llama Materials to
59
+ use, reproduce, distribute, copy, create derivative works of, and make
60
+ modifications to the Llama Materials.
61
+
62
+ b. Redistribution and Use.
63
+
64
+ i. If you distribute or make the Llama Materials, or any derivative works
65
+ thereof, available to a third party, you shall provide a copy of this
66
+ Agreement to such third party.
67
+
68
+ ii. If you receive Llama Materials, or any derivative works thereof, from a
69
+ Licensee as part of an integrated end user product, then Section 2 of this
70
+ Agreement will not apply to you.
71
+
72
+ iii. You must retain in all copies of the Llama Materials that you distribute
73
+ the following attribution notice within a "Notice" text file distributed as a
74
+ part of such copies: "Llama 2 is licensed under the LLAMA 2 Community
75
+ License, Copyright (c) Meta Platforms, Inc. All Rights Reserved."
76
+
77
+ iv. Your use of the Llama Materials must comply with applicable laws and
78
+ regulations (including trade compliance laws and regulations) and adhere to
79
+ the Acceptable Use Policy for the Llama Materials (available at
80
+ https://ai.meta.com/llama/use-policy), which is hereby incorporated by
81
+ reference into this Agreement.
82
+
83
+ v. You will not use the Llama Materials or any output or results of the Llama
84
+ Materials to improve any other large language model (excluding Llama 2 or
85
+ derivative works thereof).
86
+
87
+
88
+ 2. Additional Commercial Terms. If, on the Llama 2 version release date, the
89
+ monthly active users of the products or services made available by or for
90
+ Licensee, or Licensee's affiliates, is greater than 700 million monthly
91
+ active users in the preceding calendar month, you must request a license from
92
+ Meta, which Meta may grant to you in its sole discretion, and you are not
93
+ authorized to exercise any of the rights under this Agreement unless or until
94
+ Meta otherwise expressly grants you such rights.
95
+
96
+ 3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE LLAMA
97
+ MATERIALS AND ANY OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN "AS IS"
98
+ BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
99
+ WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT,
100
+ MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY
101
+ RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING
102
+ THE LLAMA MATERIALS AND ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE
103
+ LLAMA MATERIALS AND ANY OUTPUT AND RESULTS.
104
+
105
+ 4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE
106
+ UNDER ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE,
107
+ PRODUCTS LIABILITY, OR OTHERWISE, ARISING OUT OF THIS AGREEMENT, FOR ANY LOST
108
+ PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL, EXEMPLARY OR
109
+ PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED OF THE
110
+ POSSIBILITY OF ANY OF THE FOREGOING.
111
+
112
+
113
+ 5. Intellectual Property.
114
+
115
+ a. No trademark licenses are granted under this Agreement, and in connection
116
+ with the Llama Materials, neither Meta nor Licensee may use any name or mark
117
+ owned by or associated with the other or any of its affiliates, except as
118
+ required for reasonable and customary use in describing and redistributing
119
+ the Llama Materials.
120
+
121
+ b. Subject to Meta's ownership of Llama Materials and derivatives made by or
122
+ for Meta, with respect to any derivative works and modifications of the Llama
123
+ Materials that are made by you, as between you and Meta, you are and will be
124
+ the owner of such derivative works and modifications.
125
+
126
+ c. If you institute litigation or other proceedings against Meta or any
127
+ entity (including a cross-claim or counterclaim in a lawsuit) alleging that
128
+ the Llama Materials or Llama 2 outputs or results, or any portion of any of
129
+ the foregoing, constitutes infringement of intellectual property or other
130
+ rights owned or licensable by you, then any licenses granted to you under
131
+ this Agreement shall terminate as of the date such litigation or claim is
132
+ filed or instituted. You will indemnify and hold harmless Meta from and
133
+ against any claim by any third party arising out of or related to your use or
134
+ distribution of the Llama Materials.
135
+
136
+ 6. Term and Termination. The term of this Agreement will commence upon your
137
+ acceptance of this Agreement or access to the Llama Materials and will
138
+ continue in full force and effect until terminated in accordance with the
139
+ terms and conditions herein. Meta may terminate this Agreement if you are in
140
+ breach of any term or condition of this Agreement. Upon termination of this
141
+ Agreement, you shall delete and cease use of the Llama Materials. Sections 3,
142
+ 4 and 7 shall survive the termination of this Agreement.
143
+
144
+ 7. Governing Law and Jurisdiction. This Agreement will be governed and
145
+ construed under the laws of the State of California without regard to choice
146
+ of law principles, and the UN Convention on Contracts for the International
147
+ Sale of Goods does not apply to this Agreement. The courts of California
148
+ shall have exclusive jurisdiction of any dispute arising out of this
149
+ Agreement.
150
+
151
+ ### Llama 2 Acceptable Use Policy
152
+
153
+ Meta is committed to promoting safe and fair use of its tools and features,
154
+ including Llama 2. If you access or use Llama 2, you agree to this Acceptable
155
+ Use Policy (“Policy”). The most recent copy of this policy can be found at
156
+ [ai.meta.com/llama/use-policy](http://ai.meta.com/llama/use-policy).
157
+
158
+ #### Prohibited Uses
159
+
160
+ We want everyone to use Llama 2 safely and responsibly. You agree you will not
161
+ use, or allow others to use, Llama 2 to:
162
+
163
+ 1. Violate the law or others’ rights, including to:
164
+ 1. Engage in, promote, generate, contribute to, encourage, plan, incite, or further illegal or unlawful activity or content, such as:
165
+ 1. Violence or terrorism
166
+ 2. Exploitation or harm to children, including the solicitation, creation, acquisition, or dissemination of child exploitative content or failure to report Child Sexual Abuse Material
167
+ 3. Human trafficking, exploitation, and sexual violence
168
+ 4. The illegal distribution of information or materials to minors, including obscene materials, or failure to employ legally required age-gating in connection with such information or materials.
169
+ 5. Sexual solicitation
170
+ 6. Any other criminal activity
171
+ 2. Engage in, promote, incite, or facilitate the harassment, abuse, threatening, or bullying of individuals or groups of individuals
172
+ 3. Engage in, promote, incite, or facilitate discrimination or other unlawful or harmful conduct in the provision of employment, employment benefits, credit, housing, other economic benefits, or other essential goods and services
173
+ 4. Engage in the unauthorized or unlicensed practice of any profession including, but not limited to, financial, legal, medical/health, or related professional practices
174
+ 5. Collect, process, disclose, generate, or infer health, demographic, or other sensitive personal or private information about individuals without rights and consents required by applicable laws
175
+ 6. Engage in or facilitate any action or generate any content that infringes, misappropriates, or otherwise violates any third-party rights, including the outputs or results of any products or services using the Llama 2 Materials
176
+ 7. Create, generate, or facilitate the creation of malicious code, malware, computer viruses or do anything else that could disable, overburden, interfere with or impair the proper working, integrity, operation or appearance of a website or computer system
177
+ 2. Engage in, promote, incite, facilitate, or assist in the planning or
178
+ development of activities that present a risk of death or bodily harm to
179
+ individuals, including use of Llama 2 related to the following:
180
+ 1. Military, warfare, nuclear industries or applications, espionage, use for materials or activities that are subject to the International Traffic Arms Regulations (ITAR) maintained by the United States Department of State
181
+ 2. Guns and illegal weapons (including weapon development)
182
+ 3. Illegal drugs and regulated/controlled substances
183
+ 4. Operation of critical infrastructure, transportation technologies, or heavy machinery
184
+ 5. Self-harm or harm to others, including suicide, cutting, and eating disorders
185
+ 6. Any content intended to incite or promote violence, abuse, or any infliction of bodily harm to an individual
186
+ 3. Intentionally deceive or mislead others, including use of Llama 2 related
187
+ to the following:
188
+ 1. Generating, promoting, or furthering fraud or the creation or promotion of disinformation
189
+ 2. Generating, promoting, or furthering defamatory content, including the creation of defamatory statements, images, or other content
190
+ 3. Generating, promoting, or further distributing spam
191
+ 4. Impersonating another individual without consent, authorization, or legal right
192
+ 5. Representing that the use of Llama 2 or outputs are human-generated
193
+ 6. Generating or facilitating false online engagement, including fake reviews and other means of fake online engagement
194
+ 4. Fail to appropriately disclose to end users any known dangers of your AI system
195
+ Please report any violation of this Policy, software “bug,” or other problems
196
+ that could lead to a violation of this Policy through one of the following
197
+ means:
198
+ * Reporting issues with the model: [github.com/facebookresearch/llama](http://github.com/facebookresearch/llama)
199
+ * Reporting risky content generated by the model: [developers.facebook.com/llama_output_feedback](http://developers.facebook.com/llama_output_feedback)
200
+ * Reporting bugs and security concerns: [facebook.com/whitehat/info](http://facebook.com/whitehat/info)
201
+ * Reporting violations of the Acceptable Use Policy or unlicensed uses of Llama: [[email protected]](mailto:[email protected])
202
+ extra_gated_fields:
203
+ First Name: text
204
+ Last Name: text
205
+ Date of birth: date_picker
206
+ Country: country
207
+ Affiliation: text
208
+ geo: ip_location
209
+ By clicking Submit below I accept the terms of the license and acknowledge that the information I provide will be collected stored processed and shared in accordance with the Meta Privacy Policy: checkbox
210
+ extra_gated_description: >-
211
+ The information you provide will be collected, stored, processed and shared in
212
+ accordance with the [Meta Privacy
213
+ Policy](https://www.facebook.com/privacy/policy/).
214
+ extra_gated_button_content: Submit
215
+ language:
216
+ - en
217
+ pipeline_tag: text-generation
218
+ tags:
219
+ - facebook
220
+ - meta
221
+ - pytorch
222
+ - llama
223
+ - llama-2
224
+ license: llama2
225
+ ---
226
+ ## Model Details
227
+
228
+ **This repository contains the model weights both in the vanilla Llama format and the Hugging Face `transformers` format. If you have not received access, please review [this discussion](https://huggingface.co/meta-llama/LlamaGuard-7b/discussions/6)**
229
+
230
+ Llama-Guard is a 7B parameter [Llama 2](https://arxiv.org/abs/2307.09288)-based input-output
231
+ safeguard model. It can be used for classifying content in both LLM inputs (prompt
232
+ classification) and in LLM responses (response classification).
233
+ It acts as an LLM: it generates text in its output that indicates whether a given prompt or
234
+ response is safe/unsafe, and if unsafe based on a policy, it also lists the violating subcategories.
235
+ Here is an example:
236
+
237
+ ![](Llama-Guard_example.png)
238
+
239
+ In order to produce classifier scores, we look at the probability for the first token, and turn that
240
+ into an “unsafe” class probability. Model users can then make binary decisions by applying a
241
+ desired threshold to the probability scores.
242
+
243
+ ## Training and Evaluation
244
+ ### Training Data
245
+
246
+ We use a mix of prompts that come from the Anthropic
247
+ [dataset](https://huggingface.co/datasets/Anthropic/hh-rlhf) and redteaming examples that we have collected
248
+ in house, in a separate process from our production redteaming. In particular, we took the
249
+ prompts only from the Anthropic dataset, and generated new responses from our in-house
250
+ LLaMA models, using jailbreaking techniques to elicit violating responses. We then annotated
251
+ Anthropic data (prompts & responses) in house, mapping labels according to the categories
252
+ identified above. Overall we have ~13K training examples.
253
+
254
+ ## Taxonomy of harms and Risk Guidelines
255
+
256
+ As automated content risk mitigation relies on classifiers to make decisions
257
+ about content in real time, a prerequisite to building these systems is to have
258
+ the following components:
259
+ - A **taxonomy** of risks that are of interest – these become the classes of a
260
+ classifier.
261
+ - A **risk guideline** that determines where we put the line between encouraged
262
+ and discouraged outputs for each risk category in the taxonomy.
263
+ Together with this model, we release an open taxonomy inspired by existing open
264
+ taxonomies such as those employed by Google, Microsoft and OpenAI in the hope
265
+ that it can be useful to the community. This taxonomy does not necessarily reflect Meta's
266
+ own internal policies and is meant to demonstrate the value of our method to
267
+ tune LLMs into classifiers that show high performance and high degrees of adaptability to different policies.
268
+
269
+ ### The Llama-Guard Safety Taxonomy & Risk Guidelines
270
+
271
+ Below, we provide both the harm types themselves under this taxonomy and also examples of
272
+ the specific kinds of content that would be considered harmful under each category:
273
+
274
+ - **Violence & Hate** encompasses statements that encourage or could help people
275
+ plan or engage in violence. Similarly, statements that advocate
276
+ discrimination, contain slurs, or voice hateful sentiments against people
277
+ based on their sensitive personal characteristics (ex: race, color, religion,
278
+ national origin, sexual orientation, gender, gender identity, or disability)
279
+ would also be considered inappropriate under this category.
280
+ - **Sexual Content** encompasses statements encouraging someone (who could be
281
+ underage) to engage in specific sex acts. Similarly, sexually explicit (i.e.,
282
+ erotic) statements would also be considered inappropriate under this category.
283
+ - **Guns & Illegal Weapons** encompasses statements that specifically encourage,
284
+ condone, or could help people plan or execute specific crimes involving the
285
+ illegal acquisition, creation, or use of guns or illegal weapons (ex:
286
+ explosives, biological agents, or chemical weapons), including instructions on
287
+ how to create or use them.
288
+ - **Regulated or Controlled Substances** encompasses statements that
289
+ specifically encourage or could help people to illegally produce, transfer, or
290
+ consume regulated or controlled substances like illegal drugs, tobacco,
291
+ alcohol, or cannabis.
292
+ - **Suicide & Self Harm** encompasses statements that encourage, condone, or
293
+ enable people to harm themselves (ex: by providing instructions or information
294
+ on methods of self-harm). When people express or imply an intent to harm
295
+ themselves, any response other than one that provides links to appropriate
296
+ health resources would be considered inappropriate (even if entirely
297
+ supportive).
298
+ - **Criminal Planning** encompasses miscellaneous statements that encourage,
299
+ condone, or could help people plan or execute specific criminal activities,
300
+ like arson, kidnapping, or theft. Items should only be considered harmful
301
+ under this category when they could not be read as violating any of the other
302
+ harm types above (ex: statements that encourage violence should be considered
303
+ violating under Violence & Hate rather than this category).
304
+
305
+
306
+ ## How to Use in `transformers`
307
+
308
+ ```py
309
+ from transformers import AutoTokenizer, AutoModelForCausalLM
310
+ import torch
311
+
312
+ model_id = "meta-llama/LlamaGuard-7b"
313
+ device = "cuda"
314
+ dtype = torch.bfloat16
315
+
316
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
317
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=dtype, device_map=device)
318
+
319
+ def moderate(chat):
320
+ input_ids = tokenizer.apply_chat_template(chat, return_tensors="pt").to(device)
321
+ output = model.generate(input_ids=input_ids, max_new_tokens=100, pad_token_id=0)
322
+ prompt_len = input_ids.shape[-1]
323
+ return tokenizer.decode(output[0][prompt_len:], skip_special_tokens=True)
324
+
325
+ moderate([
326
+ {"role": "user", "content": "I forgot how to kill a process in Linux, can you help?"},
327
+ {"role": "assistant", "content": "Sure! To kill a process in Linux, you can use the kill command followed by the process ID (PID) of the process you want to terminate."},
328
+ ])
329
+ # `safe`
330
+ ```
331
+
332
+ > [!warning]
333
+ > You need to be logged in to the Hugging Face Hub to use the model.
334
+
335
+ For more details, see [this Colab notebook](https://colab.research.google.com/drive/16s0tlCSEDtczjPzdIK3jq0Le5LlnSYGf?usp=sharing).
336
+
337
+ ## Evaluation results
338
+
339
+ We compare the performance of the model against standard content moderation APIs
340
+ in the industry, including
341
+ [OpenAI](https://platform.openai.com/docs/guides/moderation/overview), [Azure Content Safety](https://learn.microsoft.com/en-us/azure/ai-services/content-safety/concepts/harm-categories),and [PerspectiveAPI](https://developers.perspectiveapi.com/s/about-the-api-attributes-and-languages?language=en_US) from Google on both public and in-house benchmarks. The public benchmarks
342
+ include [ToxicChat](https://huggingface.co/datasets/lmsys/toxic-chat) and
343
+ [OpenAI Moderation](https://github.com/openai/moderation-api-release).
344
+
345
+ Note: comparisons are not exactly apples-to-apples due to mismatches in each
346
+ taxonomy. The interested reader can find a more detailed discussion about this
347
+ in [our paper](https://arxiv.org/abs/2312.04724).
348
+
349
+ | | Our Test Set (Prompt) | OpenAI Mod | ToxicChat | Our Test Set (Response) |
350
+ | --------------- | --------------------- | ---------- | --------- | ----------------------- |
351
+ | Llama-Guard | **0.945** | 0.847 | **0.626** | **0.953** |
352
+ | OpenAI API | 0.764 | **0.856** | 0.588 | 0.769 |
353
+ | Perspective API | 0.728 | 0.787 | 0.532 | 0.699 |
354
+
355
+