RyanStudio commited on
Commit
e46e884
·
verified ·
1 Parent(s): 6696502

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +187 -0
README.md CHANGED
@@ -1,3 +1,190 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - FacebookAI/roberta-large
7
+ pipeline_tag: text-classification
8
+ tags:
9
+ - content-moderation
10
+ - content-guard
11
+ - moderation
12
+ - guard
13
+ - safety
14
  ---
15
+ # Mezzo Content Guard Large
16
+
17
+ **Mezzo Content Guard** is a series of RoBERTa-based, English-only Content Moderation Models trained on approximately 14M tokens (360k+ rows) of labelled examples.
18
+
19
+ **Mezzo Content Guard** comes in 3 different sizes, based on RoBERTa Large, Base, and DistilRoBERTa Base
20
+ - Large (355M Params)
21
+ - Base (125M Params)
22
+ - Small (82.8M Params)
23
+
24
+ Try out the demo at the [`Mezzo Content Guard Demo`](https://huggingface.co/spaces/RyanStudio/Mezzo-Content-Guard-Demo) Space
25
+
26
+ ## Categories
27
+ **Mezzo Content Guard** covers 5 different categories
28
+
29
+ - **Hate Speech:** Content that attacks or uses discriminatory and pejorative language toward a person or group based on inherent characteristics such as race, religion, ethnicity, gender, sexual orientation, or disability.
30
+
31
+ - **Self Harm:** Content where individuals express a desire to harm themselves, or encouraging acts that lead to self harm.
32
+
33
+ - **Sexual:** Content involving any references, descriptions or intent of sexual acts.
34
+
35
+ - **Toxic:** Content that attacks, harasses, or discriminates towards an individual.
36
+
37
+ - **Violence:** Content that depicts violence and gore, or content that incites acts of violence.
38
+
39
+ ## Benchmarks
40
+ All benchmarks were done with a threshold of 0.5, though the threshold can be increased or decreased to trade between precision and recall
41
+
42
+ ### Sexual
43
+ | Model | Precision | Recall | F1 | ROC-AUC |
44
+ | --- | --- | --- | --- | --- |
45
+ | Mezzo Content Guard Large | 0.8396 | 0.8370 | **0.8383** | **0.9917** |
46
+ | Mezzo Content Guard Base | 0.8190 | 0.8227 | 0.8209 | 0.9895 |
47
+ | Mezzo Content Guard Small | 0.8376 | 0.7740 | 0.8045 | 0.9865 |
48
+ | KoalaAI/Text-Moderation | 0.1503 | **0.8423** | 0.2551 | 0.8770 |
49
+ | ifmain/ModerationBERT-En-02 | **0.8500** | 0.3591 | 0.5049 | 0.9373 |
50
+
51
+ ### Violence
52
+ | Model | Precision | Recall | F1 | ROC-AUC |
53
+ | --- | --- | --- | --- | --- |
54
+ | Mezzo Content Guard Large | 0.7050 | 0.7827 | **0.7418** | 0.9921 |
55
+ | Mezzo Content Guard Base | **0.7330** | 0.7460 | 0.7394 | **0.9924** |
56
+ | Mezzo Content Guard Small | 0.6772 | 0.7269 | 0.7011 | 0.9883 |
57
+ | KoalaAI/Text-Moderation | 0.0136 | **1.0000** | 0.0269 | 0.8737 |
58
+ | ifmain/ModerationBERT-En-02 | 0.5414 | 0.3554 | 0.4291 | 0.9461 |
59
+
60
+ ### Self-Harm
61
+ | Model | Precision | Recall | F1 | ROC-AUC |
62
+ | --- | --- | --- | --- | --- |
63
+ | Mezzo Content Guard Large | 0.8558 | 0.8711 | 0.8634 | **0.9888** |
64
+ | Mezzo Content Guard Base | 0.8524 | 0.8749 | **0.8635** | 0.9868 |
65
+ | Mezzo Content Guard Small | 0.8595 | 0.8401 | 0.8497 | 0.9853 |
66
+ | KoalaAI/Text-Moderation | 0.0923 | **0.8946** | 0.1673 | 0.9178 |
67
+ | ifmain/ModerationBERT-En-02 | **0.9174** | 0.4807 | 0.6309 | 0.9471 |
68
+
69
+ ### Hate Speech
70
+ | Model | Precision | Recall | F1 | ROC-AUC |
71
+ | --- | --- | --- | --- | --- |
72
+ | Mezzo Content Guard Large | 0.8268 | 0.8229 | **0.8248** | **0.9865** |
73
+ | Mezzo Content Guard Base | 0.7991 | 0.8398 | 0.8190 | 0.9855 |
74
+ | Mezzo Content Guard Small | 0.8043 | 0.8055 | 0.8049 | 0.9829 |
75
+ | KoalaAI/Text-Moderation | 0.1000 | **0.9967** | 0.1817 | 0.9172 |
76
+ | ifmain/ModerationBERT-En-02 | **0.9111** | 0.3436 | 0.4990 | 0.9506 |
77
+
78
+ ### Toxic
79
+ | Model | Precision | Recall | F1 | ROC-AUC |
80
+ | --- | --- | --- | --- | --- |
81
+ | Mezzo Content Guard Large | **0.7647** | 0.7459 | **0.7552** | **0.9778** |
82
+ | Mezzo Content Guard Base | 0.7456 | **0.7498** | 0.7477 | 0.9760 |
83
+ | Mezzo Content Guard Small | 0.7394 | 0.7162 | 0.7276 | 0.9720 |
84
+ | KoalaAI/Text-Moderation | 0.4884 | 0.6878 | 0.5712 | 0.9162 |
85
+ | ifmain/ModerationBERT-En-02 | 0.4781 | 0.6406 | 0.5475 | 0.9128 |
86
+
87
+ ### Macro Averages
88
+ | Model | Precision | Recall | F1 | ROC-AUC |
89
+ | --- | --- | --- | --- | --- |
90
+ | Mezzo Content Guard Large | **0.7984** | 0.8119 | **0.8047** | **0.9874** |
91
+ | Mezzo Content Guard Base | 0.7898 | 0.8066 | 0.7981 | 0.9860 |
92
+ | Mezzo Content Guard Small | 0.7836 | 0.7725 | 0.7776 | 0.9830 |
93
+ | KoalaAI/Text-Moderation | 0.1689 | **0.8843** | 0.2404 | 0.9004 |
94
+ | ifmain/ModerationBERT-En-02 | 0.7396 | 0.4359 | 0.5223 | 0.9388 |
95
+
96
+ # Quickstart
97
+ Introducing our new custom [`mezzo-guard`](https://github.com/RyanStudioo/MezzoGuard) library that supports the Mezzo Prompt Guard and Mezzo Content Guard models. It offers automatic chunking, organized policies, and redactions.
98
+
99
+ Installation:
100
+ ```bash
101
+ pip install mezzo-guard
102
+ ```
103
+
104
+ ```py
105
+ from mezzoguard import CONTENTGUARD
106
+ from mezzoguard.content_guard import ContentPolicy, Category, Guard
107
+
108
+ model = Guard(CONTENTGUARD.MEZZO_CONTENT_GUARD_LARGE)
109
+ content_policy = ContentPolicy().add_threshold(Category.SEXUAL, 0.5)
110
+
111
+ sexual_query = "I want to fuck you"
112
+ benign_query = "I want to have a nice day"
113
+ violent_query = "I want to kill you"
114
+
115
+ result_1 = model.scan(text=sexual_query)
116
+ print(content_policy.evaluate(result_1))
117
+ # True
118
+
119
+ result_2 = model.scan(text=benign_query)
120
+ print(content_policy.evaluate(result_2))
121
+ # False
122
+
123
+ result_3 = model.scan(text=violent_query)
124
+ print(content_policy.evaluate(result_3))
125
+ # False
126
+ ```
127
+
128
+ With `transformers`
129
+ ```py
130
+ from transformers import pipeline
131
+
132
+ model = pipeline("text-classification", model="RyanStudio/Mezzo-Content-Guard-Large")
133
+
134
+
135
+ safe_prompt = "I love mezzo content guard!!!"
136
+ print(model(safe_prompt))
137
+
138
+ hate_speech_prompt = "I hate faggots"
139
+ print(model(hate_speech_prompt))
140
+
141
+ self_harm_prompt = "I want to kill myself"
142
+ print(model(self_harm_prompt))
143
+
144
+ sexual_prompt = "I want to fuck someone"
145
+ print(model(sexual_prompt))
146
+
147
+ toxic_prompt = "You are a cunt"
148
+ print(model(toxic_prompt))
149
+
150
+ violence_prompt = "I want to kill someone"
151
+ print(model(violence_prompt))
152
+
153
+ violence_hate_speech_toxic = "I want to kill you because you're a gay faggot"
154
+ print(model(violence_hate_speech_toxic, top_k=None))
155
+
156
+ ```
157
+
158
+ # Training:
159
+ The training data was sourced from various open-sourced datasets, as well as synthetically generated from LLMs such as Deepseek v4 Pro, Claude Sonnet 4.6, and Kimi K2.6.
160
+
161
+ Due to inconsistent labelling and definitions across various datasets, the data was re-laballed using Qwen3Guard-4B and Qwen3.5-4B to fit the specific categorical definitions.
162
+
163
+ The following table shows the data distribution:
164
+
165
+ | Label | Positives | % of Data |
166
+ |-------------|----------:|----------:|
167
+ | sexual | 18,233 | 4.95% |
168
+ | violence | 5,440 | 1.48% |
169
+ | self-harm | 7,826 | 2.13% |
170
+ | hate-speech | 31,597 | 8.59% |
171
+ | toxic | 33,088 | 8.99% |
172
+
173
+ Mezzo Content Guard Large was the first model trained, and then further distilled into the Base and Small models. All models were trained with a max seq length of 256, which filtered out less than 1% of the data in the dataset
174
+
175
+ In initial experiments, RoBERTa-base was only able to hit a 71% macro f1 score, however with distillation, it is able to punch above its weight and hit a 79% macro f1 score.
176
+
177
+ While a "Divisive" Category was added in the Preview Model, targeting political and religious speech, it was deemed unnecessary and harmed the model's overall performance
178
+
179
+ # Limitations
180
+ - **Re-labelling**: Due to the training data being relabelled by Qwen3Guard and Qwen3.5, any inaccuracies from when these models were trained may be passed on to the model
181
+ - **Context Length**: Although a context length of 256 is more than enough for most applications, the model may suffer above it. Due to limitations of RoBERTa, the model can only scan texts up to 512 tokens in length, and chunking is required in lengths above it
182
+ - **Edge Cases**: A large majority of the open sourced datasets used were often dated, and may not take into account modern day slang words or more subtle bypasses, we recommend finetuning the model on your own usecase
183
+ - **English Only**: The RoBERTa models are primarily english-based models, and will suffer in multilingual contexts
184
+
185
+ # Future Iterations
186
+ This model, while suitable for most casual applications, it can still be significantly improved.
187
+
188
+ Future Content Guard models may employ
189
+ - utilization of newer BERT-based models such as ModernBERT or Ettin-Encoder models to support larger contexts and improve general performance
190
+ - improvements to the base dataset in order to account for slang and edge cases, reducing False Positives and Negatives