aashish1904 commited on
Commit
f014421
·
verified ·
1 Parent(s): 14f32e9

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +736 -0
README.md ADDED
@@ -0,0 +1,736 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ language:
5
+ - en
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - facebook
9
+ - meta
10
+ - pytorch
11
+ - llama
12
+ - llama-3
13
+ license: llama3.1
14
+ extra_gated_prompt: >-
15
+ ### LLAMA 3.1 COMMUNITY LICENSE AGREEMENT
16
+
17
+ Llama 3.1 Version Release Date: July 23, 2024
18
+
19
+ "Agreement" means the terms and conditions for use, reproduction, distribution and modification of the
20
+ Llama Materials set forth herein.
21
+
22
+ "Documentation" means the specifications, manuals and documentation accompanying Llama 3.1
23
+ distributed by Meta at https://llama.meta.com/doc/overview.
24
+
25
+ "Licensee" or "you" means you, or your employer or any other person or entity (if you are entering into
26
+ this Agreement on such person or entity’s behalf), of the age required under applicable laws, rules or
27
+ regulations to provide legal consent and that has legal authority to bind your employer or such other
28
+ person or entity if you are entering in this Agreement on their behalf.
29
+
30
+ "Llama 3.1" means the foundational large language models and software and algorithms, including
31
+ machine-learning model code, trained model weights, inference-enabling code, training-enabling code,
32
+ fine-tuning enabling code and other elements of the foregoing distributed by Meta at
33
+ https://llama.meta.com/llama-downloads.
34
+
35
+ "Llama Materials" means, collectively, Meta’s proprietary Llama 3.1 and Documentation (and any
36
+ portion thereof) made available under this Agreement.
37
+
38
+ "Meta" or "we" means Meta Platforms Ireland Limited (if you are located in or, if you are an entity, your
39
+ principal place of business is in the EEA or Switzerland) and Meta Platforms, Inc. (if you are located
40
+ outside of the EEA or Switzerland).
41
+
42
+ 1. License Rights and Redistribution.
43
+
44
+ a. Grant of Rights. You are granted a non-exclusive, worldwide, non-transferable and royalty-free
45
+ limited license under Meta’s intellectual property or other rights owned by Meta embodied in the Llama
46
+ Materials to use, reproduce, distribute, copy, create derivative works of, and make modifications to the
47
+ Llama Materials.
48
+
49
+ b. Redistribution and Use.
50
+
51
+ i. If you distribute or make available the Llama Materials (or any derivative works
52
+ thereof), or a product or service (including another AI model) that contains any of them, you shall (A)
53
+ provide a copy of this Agreement with any such Llama Materials; and (B) prominently display “Built with
54
+ Llama” on a related website, user interface, blogpost, about page, or product documentation. If you use
55
+ the Llama Materials or any outputs or results of the Llama Materials to create, train, fine tune, or
56
+ otherwise improve an AI model, which is distributed or made available, you shall also include “Llama” at
57
+ the beginning of any such AI model name.
58
+
59
+ ii. If you receive Llama Materials, or any derivative works thereof, from a Licensee as part
60
+ of an integrated end user product, then Section 2 of this Agreement will not apply to you.
61
+
62
+ iii. You must retain in all copies of the Llama Materials that you distribute the following
63
+ attribution notice within a “Notice” text file distributed as a part of such copies: “Llama 3.1 is
64
+ licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights
65
+ Reserved.”
66
+
67
+ iv. Your use of the Llama Materials must comply with applicable laws and regulations
68
+ (including trade compliance laws and regulations) and adhere to the Acceptable Use Policy for the Llama
69
+ Materials (available at https://llama.meta.com/llama3_1/use-policy), which is hereby incorporated by
70
+ reference into this Agreement.
71
+
72
+ 2. Additional Commercial Terms. If, on the Llama 3.1 version release date, the monthly active users
73
+ of the products or services made available by or for Licensee, or Licensee’s affiliates, is greater than 700
74
+ million monthly active users in the preceding calendar month, you must request a license from Meta,
75
+ which Meta may grant to you in its sole discretion, and you are not authorized to exercise any of the
76
+ rights under this Agreement unless or until Meta otherwise expressly grants you such rights.
77
+
78
+ 3. Disclaimer of Warranty. UNLESS REQUIRED BY APPLICABLE LAW, THE LLAMA MATERIALS AND ANY
79
+ OUTPUT AND RESULTS THEREFROM ARE PROVIDED ON AN “AS IS” BASIS, WITHOUT WARRANTIES OF
80
+ ANY KIND, AND META DISCLAIMS ALL WARRANTIES OF ANY KIND, BOTH EXPRESS AND IMPLIED,
81
+ INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF TITLE, NON-INFRINGEMENT,
82
+ MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. YOU ARE SOLELY RESPONSIBLE FOR
83
+ DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE LLAMA MATERIALS AND
84
+ ASSUME ANY RISKS ASSOCIATED WITH YOUR USE OF THE LLAMA MATERIALS AND ANY OUTPUT AND
85
+ RESULTS.
86
+
87
+ 4. Limitation of Liability. IN NO EVENT WILL META OR ITS AFFILIATES BE LIABLE UNDER ANY THEORY OF
88
+ LIABILITY, WHETHER IN CONTRACT, TORT, NEGLIGENCE, PRODUCTS LIABILITY, OR OTHERWISE, ARISING
89
+ OUT OF THIS AGREEMENT, FOR ANY LOST PROFITS OR ANY INDIRECT, SPECIAL, CONSEQUENTIAL,
90
+ INCIDENTAL, EXEMPLARY OR PUNITIVE DAMAGES, EVEN IF META OR ITS AFFILIATES HAVE BEEN ADVISED
91
+ OF THE POSSIBILITY OF ANY OF THE FOREGOING.
92
+
93
+ 5. Intellectual Property.
94
+
95
+ a. No trademark licenses are granted under this Agreement, and in connection with the Llama
96
+ Materials, neither Meta nor Licensee may use any name or mark owned by or associated with the other
97
+ or any of its affiliates, except as required for reasonable and customary use in describing and
98
+ redistributing the Llama Materials or as set forth in this Section 5(a). Meta hereby grants you a license to
99
+ use “Llama” (the “Mark”) solely as required to comply with the last sentence of Section 1.b.i. You will
100
+ comply with Meta’s brand guidelines (currently accessible at
101
+ https://about.meta.com/brand/resources/meta/company-brand/ ). All goodwill arising out of your use
102
+ of the Mark will inure to the benefit of Meta.
103
+
104
+ b. Subject to Meta’s ownership of Llama Materials and derivatives made by or for Meta, with
105
+ respect to any derivative works and modifications of the Llama Materials that are made by you, as
106
+ between you and Meta, you are and will be the owner of such derivative works and modifications.
107
+
108
+ c. If you institute litigation or other proceedings against Meta or any entity (including a
109
+ cross-claim or counterclaim in a lawsuit) alleging that the Llama Materials or Llama 3.1 outputs or
110
+ results, or any portion of any of the foregoing, constitutes infringement of intellectual property or other
111
+ rights owned or licensable by you, then any licenses granted to you under this Agreement shall
112
+ terminate as of the date such litigation or claim is filed or instituted. You will indemnify and hold
113
+ harmless Meta from and against any claim by any third party arising out of or related to your use or
114
+ distribution of the Llama Materials.
115
+
116
+ 6. Term and Termination. The term of this Agreement will commence upon your acceptance of this
117
+ Agreement or access to the Llama Materials and will continue in full force and effect until terminated in
118
+ accordance with the terms and conditions herein. Meta may terminate this Agreement if you are in
119
+ breach of any term or condition of this Agreement. Upon termination of this Agreement, you shall delete
120
+ and cease use of the Llama Materials. Sections 3, 4 and 7 shall survive the termination of this
121
+ Agreement.
122
+
123
+ 7. Governing Law and Jurisdiction. This Agreement will be governed and construed under the laws of
124
+ the State of California without regard to choice of law principles, and the UN Convention on Contracts
125
+ for the International Sale of Goods does not apply to this Agreement. The courts of California shall have
126
+ exclusive jurisdiction of any dispute arising out of this Agreement.
127
+
128
+ ### Llama 3.1 Acceptable Use Policy
129
+
130
+ Meta is committed to promoting safe and fair use of its tools and features, including Llama 3.1. If you
131
+ access or use Llama 3.1, you agree to this Acceptable Use Policy (“Policy”). The most recent copy of
132
+ this policy can be found at [https://llama.meta.com/llama3_1/use-policy](https://llama.meta.com/llama3_1/use-policy)
133
+
134
+ #### Prohibited Uses
135
+
136
+ We want everyone to use Llama 3.1 safely and responsibly. You agree you will not use, or allow
137
+ others to use, Llama 3.1 to:
138
+ 1. Violate the law or others’ rights, including to:
139
+ 1. Engage in, promote, generate, contribute to, encourage, plan, incite, or further illegal or unlawful activity or content, such as:
140
+ 1. Violence or terrorism
141
+ 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
142
+ 3. Human trafficking, exploitation, and sexual violence
143
+ 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.
144
+ 5. Sexual solicitation
145
+ 6. Any other criminal activity
146
+ 3. Engage in, promote, incite, or facilitate the harassment, abuse, threatening, or bullying of individuals or groups of individuals
147
+ 4. 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
148
+ 5. Engage in the unauthorized or unlicensed practice of any profession including, but not limited to, financial, legal, medical/health, or related professional practices
149
+ 6. 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
150
+ 7. 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 Materials
151
+ 8. 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
152
+ 2. Engage in, promote, incite, facilitate, or assist in the planning or development of activities that present a risk of death or bodily harm to individuals, including use of Llama 3.1 related to the following:
153
+ 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
154
+ 2. Guns and illegal weapons (including weapon development)
155
+ 3. Illegal drugs and regulated/controlled substances
156
+ 4. Operation of critical infrastructure, transportation technologies, or heavy machinery
157
+ 5. Self-harm or harm to others, including suicide, cutting, and eating disorders
158
+ 6. Any content intended to incite or promote violence, abuse, or any infliction of bodily harm to an individual
159
+ 3. Intentionally deceive or mislead others, including use of Llama 3.1 related to the following:
160
+ 1. Generating, promoting, or furthering fraud or the creation or promotion of disinformation
161
+ 2. Generating, promoting, or furthering defamatory content, including the creation of defamatory statements, images, or other content
162
+ 3. Generating, promoting, or further distributing spam
163
+ 4. Impersonating another individual without consent, authorization, or legal right
164
+ 5. Representing that the use of Llama 3.1 or outputs are human-generated
165
+ 6. Generating or facilitating false online engagement, including fake reviews and other means of fake online engagement
166
+ 4. Fail to appropriately disclose to end users any known dangers of your AI system
167
+
168
+ Please report any violation of this Policy, software “bug,” or other problems that could lead to a violation
169
+ of this Policy through one of the following means:
170
+ * Reporting issues with the model: [https://github.com/meta-llama/llama-models/issues](https://github.com/meta-llama/llama-models/issues)
171
+ * Reporting risky content generated by the model:
172
+ developers.facebook.com/llama_output_feedback
173
+ * Reporting bugs and security concerns: facebook.com/whitehat/info
174
+ * Reporting violations of the Acceptable Use Policy or unlicensed uses of Meta Llama 3: LlamaUseReport@meta.com
175
+ extra_gated_fields:
176
+ First Name: text
177
+ Last Name: text
178
+ Date of birth: date_picker
179
+ Country: country
180
+ Affiliation: text
181
+ Job title:
182
+ type: select
183
+ options:
184
+ - Student
185
+ - Research Graduate
186
+ - AI researcher
187
+ - AI developer/engineer
188
+ - Reporter
189
+ - Other
190
+ geo: ip_location
191
+ 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
192
+ extra_gated_description: The information you provide will be collected, stored, processed and shared in accordance with the [Meta Privacy Policy](https://www.facebook.com/privacy/policy/).
193
+ extra_gated_button_content: Submit
194
+
195
+ ---
196
+
197
+ ![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)
198
+
199
+ # QuantFactory/Llama-Guard-3-8B-GGUF
200
+ This is quantized version of [meta-llama/Llama-Guard-3-8B](https://huggingface.co/meta-llama/Llama-Guard-3-8B) created using llama.cpp
201
+
202
+ # Original Model Card
203
+
204
+
205
+
206
+ # Model Details
207
+
208
+ Llama Guard 3 is a Llama-3.1-8B pretrained model, fine-tuned for content safety classification. Similar to previous versions, it can be used to classify content in both LLM inputs (prompt classification) and in LLM responses (response classification). It acts as an LLM – it generates text in its output that indicates whether a given prompt or response is safe or unsafe, and if unsafe, it also lists the content categories violated.
209
+
210
+ Llama Guard 3 was aligned to safeguard against the MLCommons standardized hazards taxonomy and designed to support Llama 3.1 capabilities. Specifically, it provides content moderation in 8 languages, and was optimized to support safety and security for search and code interpreter tool calls.
211
+
212
+ Below is a response classification example for Llama Guard 3.
213
+
214
+
215
+ <p align="center">
216
+ <img src="llama_guard_3_figure.png" width="800"/>
217
+ </p>
218
+
219
+ In order to produce classifier scores, we look at the probability for the first token, and use that as the “unsafe” class probability. We can then apply score thresholding to make binary decisions.
220
+
221
+ # Hazard Taxonomy and Policy
222
+
223
+ The model is trained to predict safety labels on the 14 categories shown below, based on the [MLCommons taxonomy](https://mlcommons.org/2024/04/mlc-aisafety-v0-5-poc/) of 13 hazards, as well as an additional category for Code Interpreter Abuse for tool calls use cases
224
+
225
+ <table align="center">
226
+ <thead>
227
+ <tr>
228
+ <th colspan="2">Hazard categories</th>
229
+ </tr>
230
+ </thead>
231
+ <tbody>
232
+ <tr>
233
+ <td>S1: Violent Crimes</td>
234
+ <td>S2: Non-Violent Crimes</td>
235
+ </tr>
236
+ <tr>
237
+ <td>S3: Sex-Related Crimes</td>
238
+ <td>S4: Child Sexual Exploitation</td>
239
+ </tr>
240
+ <tr>
241
+ <td>S5: Defamation</td>
242
+ <td>S6: Specialized Advice</td>
243
+ </tr>
244
+ <tr>
245
+ <td>S7: Privacy</td>
246
+ <td>S8: Intellectual Property</td>
247
+ </tr>
248
+ <tr>
249
+ <td>S9: Indiscriminate Weapons</td>
250
+ <td>S10: Hate</td>
251
+ </tr>
252
+ <tr>
253
+ <td>S11: Suicide &amp; Self-Harm</td>
254
+ <td>S12: Sexual Content</td>
255
+ </tr>
256
+ <tr>
257
+ <td>S13: Elections</td>
258
+ <td>S14: Code Interpreter Abuse</td>
259
+ </tr>
260
+ </tbody>
261
+ </table>
262
+
263
+ **S1 - Violent Crimes**
264
+
265
+ Responses that enable, encourage, or endorse the commission of violent crimes, including: (1) unlawful violence toward people (ex: terrorism, genocide, murder, hate-motivated violent crimes, child abuse, assault, battery, kidnapping) and (2) unlawful violence toward animals (ex: animal abuse)
266
+
267
+ **S2 - Non-Violent Crimes**
268
+
269
+ Responses that enable, encourage, or endorse the commission of non-violent crimes, including: (1) personal crimes (ex: labor trafficking, threats, intimidation, hate-motivated non-violent crimes), (2) financial crimes (ex: fraud, scams, money laundering), (3) property crimes (ex: theft, arson, vandalism), (4) drug crimes (ex: creating or using regulated substances), (5) weapons crimes (ex: producing unlicensed firearms), and (6) cyber crimes (ex: hacking)
270
+
271
+ **S3 - Sex-Related Crimes**
272
+
273
+ Responses that enable, encourage, or endorse the commission of sex-related crimes, including: (1) sex trafficking, (2) sexual assault (ex: rape), (3) sexual harassment (physical, verbal, or visual), and (4) prostitution
274
+
275
+ **S4 - Child Sexual Exploitation**
276
+
277
+ Responses that contain, describe, enable, encourage, or endorse the sexual abuse of children
278
+
279
+ **S5 - Defamation**
280
+
281
+ Responses that are both verifiably false and likely to injure a living person’s reputation
282
+
283
+ **S6 - Specialized Advice**
284
+
285
+ Responses that contain specialized financial, medical, or legal advice, or that indicate dangerous activities or objects are safe
286
+
287
+ **S7 - Privacy**
288
+
289
+ Responses that contain sensitive, nonpublic personal information that could undermine someone’s physical, digital, or financial security
290
+
291
+ **S8 - Intellectual Property**
292
+
293
+ Responses that may violate the intellectual property rights of any third party
294
+
295
+ **S9 - Indiscriminate Weapons**
296
+
297
+ Responses that enable, encourage, or endorse the creation of indiscriminate weapons, including: (1) chemical weapons (ex: nerve gas), (2) biological weapons (ex: anthrax), (3) radiological weapons (ex: cobalt bombs), (4) nuclear weapons (ex: fission bombs), and (5) high-yield explosive weapons (ex: cluster munitions)
298
+
299
+ **S10 - Hate**
300
+
301
+ Responses that demean or dehumanize people on the basis of their sensitive, personal characteristics (i.e., race, color, ethnicity, national origin, disability, religious affiliation, caste, sexual orientation, sex, gender identity, and/or serious disease)
302
+
303
+ **S11 - Suicide &amp; Self-Harm**
304
+
305
+ Responses that enable, encourage, or endorse acts of intentional self-harm, including: (1) suicide, (2) self-injury (ex: cutting), and (3) disordered eating
306
+
307
+ **S12 - Sexual Content**
308
+
309
+ Responses that contain erotica
310
+
311
+ **S13 - Elections**
312
+
313
+ Responses that contain factually incorrect information about electoral systems and processes, including in the time, place, or manner of voting in civic elections
314
+
315
+ **S14 - Code Interpreter Abuse**
316
+
317
+ Responses that seek to abuse code interpreters, including those that enable denial of service attacks, container escapes or privilege escalation exploits
318
+
319
+
320
+ # Supported languages
321
+
322
+ Llama Guard 3 supports content safety for the following languages : English, French, German, Hindi, Italian, Portuguese, Spanish, Thai.
323
+
324
+ # Usage
325
+
326
+ > [!IMPORTANT]
327
+ >
328
+ > This repository corresponds to half-precision version of the model. A 8-bit precision version is also provided, please visit [meta-llama/Llama-Guard-3-8B-INT8](https://huggingface.co/meta-llama/Llama-Guard-3-8B-INT8).
329
+
330
+ Llama Guard 3 can be directly used with `transformers`. It is only supported since `transformers` version 4.43.
331
+
332
+ ```python
333
+ import torch
334
+ from transformers import AutoTokenizer, AutoModelForCausalLM
335
+
336
+ model_id = "meta-llama/Llama-Guard-3-8B"
337
+ device = "cuda"
338
+ dtype = torch.bfloat16
339
+
340
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
341
+ model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=dtype, device_map=device)
342
+
343
+ def moderate(chat):
344
+ input_ids = tokenizer.apply_chat_template(chat, return_tensors="pt").to(device)
345
+ output = model.generate(input_ids=input_ids, max_new_tokens=100, pad_token_id=0)
346
+ prompt_len = input_ids.shape[-1]
347
+ return tokenizer.decode(output[0][prompt_len:], skip_special_tokens=True)
348
+
349
+ moderate([
350
+ {"role": "user", "content": "I forgot how to kill a process in Linux, can you help?"},
351
+ {"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."},
352
+ ])
353
+ ```
354
+
355
+ # Training Data
356
+
357
+ We use the English data used by Llama Guard [1], which are obtained by getting Llama 2 and Llama 3 generations on prompts from the hh-rlhf dataset [2]. In order to scale training data for new categories and new capabilities such as multilingual and tool use, we collect additional human and synthetically generated data. Similar to the English data, the multilingual data are Human-AI conversation data that are either single-turn or multi-turn. To reduce the model’s false positive rate, we curate a set of multilingual benign prompt and response data where LLMs likely reject the prompts.
358
+
359
+ For the tool use capability, we consider search tool calls and code interpreter abuse. To develop training data for search tool use, we use Llama3 to generate responses to a collected and synthetic set of prompts. The generations are based on the query results obtained from the Brave Search API. To develop synthetic training data to detect code interpreter attacks, we use an LLM to generate safe and unsafe prompts. Then, we use a non-safety-tuned LLM to generate code interpreter completions that comply with these instructions. For safe data, we focus on data close to the boundary of what would be considered unsafe, to minimize false positives on such borderline examples.
360
+
361
+ # Evaluation
362
+
363
+ **Note on evaluations:** As discussed in the original Llama Guard paper, comparing model performance is not straightforward as each model is built on its own policy and is expected to perform better on an evaluation dataset with a policy aligned to the model. This highlights the need for industry standards. By aligning the Llama Guard family of models with the Proof of Concept MLCommons taxonomy of hazards, we hope to drive adoption of industry standards like this and facilitate collaboration and transparency in the LLM safety and content evaluation space.
364
+
365
+ In this regard, we evaluate the performance of Llama Guard 3 on MLCommons hazard taxonomy and compare it across languages with Llama Guard 2 [3] on our internal test. We also add GPT4 as baseline with zero-shot prompting using MLCommons hazard taxonomy.
366
+
367
+ Tables 1, 2, and 3 show that Llama Guard 3 improves over Llama Guard 2 and outperforms GPT4 in English, multilingual, and tool use capabilities. Noteworthily, Llama Guard 3 achieves better performance with much lower false positive rates. We also benchmark Llama Guard 3 in the OSS dataset XSTest [4] and observe that it achieves the same F1 score but a lower false positive rate compared to Llama Guard 2.
368
+
369
+ <div align="center">
370
+ <small> Table 1: Comparison of performance of various models measured on our internal English test set for MLCommons hazard taxonomy (response classification).</small>
371
+
372
+ | | **F1 ↑** | **AUPRC ↑** | **False Positive<br>Rate ↓** |
373
+ |--------------------------|:--------:|:-----------:|:----------------------------:|
374
+ | Llama Guard 2 | 0.877 | 0.927 | 0.081 |
375
+ | Llama Guard 3 | 0.939 | 0.985 | 0.040 |
376
+ | GPT4 | 0.805 | N/A | 0.152 |
377
+ </div>
378
+
379
+ <br>
380
+
381
+ <table align="center">
382
+ <small><center>Table 2: Comparison of multilingual performance of various models measured on our internal test set for MLCommons hazard taxonomy (prompt+response classification).</center></small>
383
+ <thead>
384
+ <tr>
385
+ <th colspan="8"><center>F1 ↑ / FPR ↓</center></th>
386
+ </tr>
387
+ </thead>
388
+ <tbody>
389
+ <tr>
390
+ <td></td>
391
+ <td><center>French</center></td>
392
+ <td><center>German</center></td>
393
+ <td><center>Hindi</center></td>
394
+ <td><center>Italian</center></td>
395
+ <td><center>Portuguese</center></td>
396
+ <td><center>Spanish</center></td>
397
+ <td><center>Thai</center></td>
398
+ </tr>
399
+ <tr>
400
+ <td>Llama Guard 2</td>
401
+ <td><center>0.911/0.012</center></td>
402
+ <td><center>0.795/0.062</center></td>
403
+ <td><center>0.832/0.062</center></td>
404
+ <td><center>0.681/0.039</center></td>
405
+ <td><center>0.845/0.032</center></td>
406
+ <td><center>0.876/0.001</center></td>
407
+ <td><center>0.822/0.078</center></td>
408
+ </tr>
409
+ <tr>
410
+ <td>Llama Guard 3</td>
411
+ <td><center>0.943/0.036</center></td>
412
+ <td><center>0.877/0.032</center></td>
413
+ <td><center>0.871/0.050</center></td>
414
+ <td><center>0.873/0.038</center></td>
415
+ <td><center>0.860/0.060</center></td>
416
+ <td><center>0.875/0.023</center></td>
417
+ <td><center>0.834/0.030</center></td>
418
+ </tr>
419
+ <tr>
420
+ <td>GPT4</td>
421
+ <td><center>0.795/0.157</center></td>
422
+ <td><center>0.691/0.123</center></td>
423
+ <td><center>0.709/0.206</center></td>
424
+ <td><center>0.753/0.204</center></td>
425
+ <td><center>0.738/0.207</center></td>
426
+ <td><center>0.711/0.169</center></td>
427
+ <td><center>0.688/0.168</center></td>
428
+ </tr>
429
+ </tbody>
430
+ </table>
431
+
432
+ <br>
433
+
434
+ <table align="center">
435
+ <small><center>Table 3: Comparison of performance of various models measured on our internal test set for other moderation capabilities (prompt+response classification).</center></small>
436
+ <thead>
437
+ <tr>
438
+ <th></th>
439
+ <th colspan="3">Search tool calls</th>
440
+ <th colspan="3">Code interpreter abuse</th>
441
+ </tr>
442
+ </thead>
443
+ <tbody>
444
+ <tr>
445
+ <td></td>
446
+ <td><center>F1 ↑</center></td>
447
+ <td><center>AUPRC ↑</center></td>
448
+ <td><center>FPR ↓</center></td>
449
+ <td><center>F1 ↑</center></td>
450
+ <td><center>AUPRC ↑</center></td>
451
+ <td><center>FPR ↓</center></td>
452
+ </tr>
453
+ <tr>
454
+ <td>Llama Guard 2</td>
455
+ <td><center>0.749</center></td>
456
+ <td><center>0.794</center></td>
457
+ <td><center>0.284</center></td>
458
+ <td><center>0.683</center></td>
459
+ <td><center>0.677</center></td>
460
+ <td><center>0.670</center></td>
461
+ </tr>
462
+ <tr>
463
+ <td>Llama Guard 3</td>
464
+ <td><center>0.856</center></td>
465
+ <td><center>0.938</center></td>
466
+ <td><center>0.174</center></td>
467
+ <td><center>0.885</center></td>
468
+ <td><center>0.967</center></td>
469
+ <td><center>0.125</center></td>
470
+ </tr>
471
+ <tr>
472
+ <td>GPT4</td>
473
+ <td><center>0.732</center></td>
474
+ <td><center>N/A</center></td>
475
+ <td><center>0.525</center></td>
476
+ <td><center>0.636</center></td>
477
+ <td><center>N/A</center></td>
478
+ <td><center>0.90</center></td>
479
+ </tr>
480
+ </tbody>
481
+ </table>
482
+
483
+ # Application
484
+
485
+ As outlined in the Llama 3 paper, Llama Guard 3 provides industry leading system-level safety performance and is recommended to be deployed along with Llama 3.1. Note that, while deploying Llama Guard 3 will likely improve the safety of your system, it might increase refusals to benign prompts (False Positives). Violation rate improvement and impact on false positives as measured on internal benchmarks are provided in the Llama 3 paper.
486
+
487
+ # Quantization
488
+
489
+ We are committed to help the community deploy Llama systems responsibly. We provide a quantized version of Llama Guard 3 to lower the deployment cost. We used int 8 [implementation](https://huggingface.co/docs/transformers/main/en/quantization/bitsandbytes) integrated into the hugging face ecosystem, reducing the checkpoint size by about 40% with very small impact on model performance. In Table 5, we observe that the performance quantized model is comparable to the original model.
490
+
491
+ <table align="center">
492
+ <small><center>Table 5: Impact of quantization on Llama Guard 3 performance.</center></small>
493
+ <tbody>
494
+ <tr>
495
+ <td rowspan="2"><br />
496
+ <p><span>Task</span></p>
497
+ </td>
498
+ <td rowspan="2"><br />
499
+ <p><span>Capability</span></p>
500
+ </td>
501
+ <td colspan="4">
502
+ <p><center><span>Non-Quantized</span></center></p>
503
+ </td>
504
+ <td colspan="4">
505
+ <p><center><span>Quantized</span></center></p>
506
+ </td>
507
+ </tr>
508
+ <tr>
509
+ <td>
510
+ <p><span>Precision</span></p>
511
+ </td>
512
+ <td>
513
+ <p><span>Recall</span></p>
514
+ </td>
515
+ <td>
516
+ <p><span>F1</span></p>
517
+ </td>
518
+ <td>
519
+ <p><span>FPR</span></p>
520
+ </td>
521
+ <td>
522
+ <p><span>Precision</span></p>
523
+ </td>
524
+ <td>
525
+ <p><span>Recall</span></p>
526
+ </td>
527
+ <td>
528
+ <p><span>F1</span></p>
529
+ </td>
530
+ <td>
531
+ <p><span>FPR</span></p>
532
+ </td>
533
+ </tr>
534
+ <tr>
535
+ <td rowspan="3">
536
+ <p><span>Prompt Classification</span></p>
537
+ </td>
538
+ <td>
539
+ <p><span>English</span></p>
540
+ </td>
541
+ <td>
542
+ <p><span>0.952</span></p>
543
+ </td>
544
+ <td>
545
+ <p><span>0.943</span></p>
546
+ </td>
547
+ <td>
548
+ <p><span>0.947</span></p>
549
+ </td>
550
+ <td>
551
+ <p><span>0.057</span></p>
552
+ </td>
553
+ <td>
554
+ <p><span>0.961</span></p>
555
+ </td>
556
+ <td>
557
+ <p><span>0.939</span></p>
558
+ </td>
559
+ <td>
560
+ <p><span>0.950</span></p>
561
+ </td>
562
+ <td>
563
+ <p><span>0.045</span></p>
564
+ </td>
565
+ </tr>
566
+ <tr>
567
+ <td>
568
+ <p><span>Multilingual</span></p>
569
+ </td>
570
+ <td>
571
+ <p><span>0.901</span></p>
572
+ </td>
573
+ <td>
574
+ <p><span>0.899</span></p>
575
+ </td>
576
+ <td>
577
+ <p><span>0.900</span></p>
578
+ </td>
579
+ <td>
580
+ <p><span>0.054</span></p>
581
+ </td>
582
+ <td>
583
+ <p><span>0.906</span></p>
584
+ </td>
585
+ <td>
586
+ <p><span>0.892</span></p>
587
+ </td>
588
+ <td>
589
+ <p><span>0.899</span></p>
590
+ </td>
591
+ <td>
592
+ <p><span>0.051</span></p>
593
+ </td>
594
+ </tr>
595
+ <tr>
596
+ <td>
597
+ <p><span>Tool Use</span></p>
598
+ </td>
599
+ <td>
600
+ <p><span>0.884</span></p>
601
+ </td>
602
+ <td>
603
+ <p><span>0.958</span></p>
604
+ </td>
605
+ <td>
606
+ <p><span>0.920</span></p>
607
+ </td>
608
+ <td>
609
+ <p><span>0.126</span></p>
610
+ </td>
611
+ <td>
612
+ <p><span>0.876</span></p>
613
+ </td>
614
+ <td>
615
+ <p><span>0.946</span></p>
616
+ </td>
617
+ <td>
618
+ <p><span>0.909</span></p>
619
+ </td>
620
+ <td>
621
+ <p><span>0.134</span></p>
622
+ </td>
623
+ </tr>
624
+ <tr>
625
+ <td rowspan="3">
626
+ <p><span>Response Classification</span></p>
627
+ </td>
628
+ <td>
629
+ <p><span>English</span></p>
630
+ </td>
631
+ <td>
632
+ <p><span>0.947</span></p>
633
+ </td>
634
+ <td>
635
+ <p><span>0.931</span></p>
636
+ </td>
637
+ <td>
638
+ <p><span>0.939</span></p>
639
+ </td>
640
+ <td>
641
+ <p><span>0.040</span></p>
642
+ </td>
643
+ <td>
644
+ <p><span>0.947</span></p>
645
+ </td>
646
+ <td>
647
+ <p><span>0.925</span></p>
648
+ </td>
649
+ <td>
650
+ <p><span>0.936</span></p>
651
+ </td>
652
+ <td>
653
+ <p><span>0.040</span></p>
654
+ </td>
655
+ </tr>
656
+ <tr>
657
+ <td>
658
+ <p><span>Multilingual</span></p>
659
+ </td>
660
+ <td>
661
+ <p><span>0.929</span></p>
662
+ </td>
663
+ <td>
664
+ <p><span>0.805</span></p>
665
+ </td>
666
+ <td>
667
+ <p><span>0.862</span></p>
668
+ </td>
669
+ <td>
670
+ <p><span>0.033</span></p>
671
+ </td>
672
+ <td>
673
+ <p><span>0.931</span></p>
674
+ </td>
675
+ <td>
676
+ <p><span>0.785</span></p>
677
+ </td>
678
+ <td>
679
+ <p><span>0.851</span></p>
680
+ </td>
681
+ <td>
682
+ <p><span>0.031</span></p>
683
+ </td>
684
+ </tr>
685
+ <tr>
686
+ <td>
687
+ <p><span>Tool Use</span></p>
688
+ </td>
689
+ <td>
690
+ <p><span>0.774</span></p>
691
+ </td>
692
+ <td>
693
+ <p><span>0.884</span></p>
694
+ </td>
695
+ <td>
696
+ <p><span>0.825</span></p>
697
+ </td>
698
+ <td>
699
+ <p><span>0.176</span></p>
700
+ </td>
701
+ <td>
702
+ <p><span>0.793</span></p>
703
+ </td>
704
+ <td>
705
+ <p><span>0.865</span></p>
706
+ </td>
707
+ <td>
708
+ <p><span>0.827</span></p>
709
+ </td>
710
+ <td>
711
+ <p><span>0.155</span></p>
712
+ </td>
713
+ </tr>
714
+ </tbody>
715
+ </table>
716
+
717
+ # Get started
718
+
719
+ Llama Guard 3 is available by default on Llama 3.1 [reference implementations](https://github.com/meta-llama). You can learn more about how to configure and customize using [Llama Recipes](https://github.com/meta-llama/llama-recipes/tree/main/recipes/responsible_ai/) shared on our Github repository.
720
+
721
+ # Limitations
722
+ There are some limitations associated with Llama Guard 3. First, Llama Guard 3 itself is an LLM fine-tuned on Llama 3.1. Thus, its performance (e.g., judgments that need common sense knowledge, multilingual capability, and policy coverage) might be limited by its (pre-)training data.
723
+
724
+ Some hazard categories may require factual, up-to-date knowledge to be evaluated (for example, S5: Defamation, S8: Intellectual Property, and S13: Elections) . We believe more complex systems should be deployed to accurately moderate these categories for use cases highly sensitive to these types of hazards, but Llama Guard 3 provides a good baseline for generic use cases.
725
+
726
+ Lastly, as an LLM, Llama Guard 3 may be susceptible to adversarial attacks or prompt injection attacks that could bypass or alter its intended use. Please feel free to [report](https://github.com/meta-llama/PurpleLlama) vulnerabilities and we will look to incorporate improvements in future versions of Llama Guard.
727
+
728
+ # References
729
+
730
+ [1] [Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations](https://arxiv.org/abs/2312.06674)
731
+
732
+ [2] [Training a Helpful and Harmless Assistant with Reinforcement Learning from Human Feedback](https://arxiv.org/abs/2204.05862)
733
+
734
+ [3] [Llama Guard 2 Model Card](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard2/MODEL_CARD.md)
735
+
736
+ [4] [XSTest: A Test Suite for Identifying Exaggerated Safety Behaviors in Large Language Models](https://arxiv.org/abs/2308.01263)