RichardErkhov commited on
Commit
912db2d
·
verified ·
1 Parent(s): c063dd0

uploaded readme

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