sollamon commited on
Commit
0b7f3a3
·
verified ·
1 Parent(s): 565bd53

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +184 -90
README.md CHANGED
@@ -1,108 +1,152 @@
1
- Harmony v2 — Toxicity Classifier
2
 
3
- Lightweight, context-aware toxicity detection that reads intent, not just keywords.
4
 
 
5
 
 
6
 
7
- 🧠 Model Overview
8
 
9
- Harmony v2 is a fine-tuned version of gravitee-io/bert-tiny-toxicity trained on a custom 7000-sample dataset (HarmonyDataset v2). It distinguishes between:
10
 
 
11
 
 
12
 
13
- Toxic: Direct personal attacks, harassment, threats, humiliation, dehumanization.
14
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
16
 
17
- Safe: Emotional expression, profanity without a target, frustration, jokes, sarcasm, friendly banter.
18
 
 
19
 
 
20
 
21
- Core philosophy:
 
 
 
 
 
 
 
 
 
 
22
 
23
- Profanity ≠ toxicity.
24
 
25
- The model learns to recognize intent and target, not just a list of "bad words."
26
 
 
 
 
 
 
 
 
27
 
 
28
 
29
- 📊 Key Features
30
 
31
- Feature Details
32
 
33
- Base model gravitee-io/bert-tiny-toxicity
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- Training data 7,000 human-like Telegram/chat messages
36
 
37
- Context window 512 tokens
 
 
 
 
 
 
38
 
39
- Format PyTorch (Hugging Face compatible)
40
 
41
- Size \~184 MB (int8)
42
 
43
- License Apache-2.0
44
-
45
- ⚡ Performance
46
-
47
- Metric Value
48
-
49
- Evaluation loss 0.4255
50
-
51
- F1 score 98.4%
52
-
53
- Languages Ukrainian, Russian, mixed (UA/RU)
54
-
55
- Inference latency \~11 ms on CPU
56
-
57
- 🚀 Quick Start
58
-
59
- 1\. Clone \& install
60
-
61
- bash
62
 
 
63
  git clone https://github.com/your-username/harmony-v2
64
-
65
  cd harmony-v2
 
66
 
67
- pip install -r requirements.txt
68
-
69
- 2\. Load model in Python
70
-
71
- python
72
 
73
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
 
74
 
 
75
 
 
76
 
77
- model\_path = "./Harmony-v2"
 
 
 
 
78
 
79
- tokenizer = AutoTokenizer.from\_pretrained(model\_path)
80
 
81
- model = AutoModelForSequenceClassification.from\_pretrained(model\_path)
 
 
82
 
83
- 3\. Predict
84
 
85
- python
86
 
 
87
  import torch
88
 
89
-
90
-
91
  def predict(text):
 
 
 
 
 
 
92
 
93
-   inputs = tokenizer(text, return\_tensors="pt", truncation=True, max\_length=512)
94
-
95
-   with torch.no\_grad():
96
-
97
-   outputs = model(\*\*inputs)
98
-
99
-   probs = torch.softmax(outputs.logits, dim=1)
100
-
101
-   toxic\_score = probs\[0]\[1].item()
102
-
103
-   return toxic\_score
104
 
 
 
105
 
 
106
 
107
  text = "блін сервер впав, третій раз сьогодні"
108
 
@@ -110,77 +154,127 @@ score = predict(text)
110
 
111
  label = "🚨 Toxic" if score > 0.5 else "✅ Safe"
112
 
113
- print(f"Text: {text}\\nScore: {score:.2f} → {label}")
 
114
 
115
- 📂 Dataset
116
 
117
- Trained on HarmonyDataset v2 — 7,000 synthetically generated samples with balanced categories:
 
 
118
 
 
119
 
 
 
120
 
121
- Category Share
122
 
123
- Safe 15%
 
124
 
125
- Friendly profanity 10%
126
 
127
- Frustration 10%
128
 
129
- Self-insult 5%
130
 
131
- Joke 10%
 
 
132
 
133
- Sarcasm 10%
134
 
135
- Criticism 5%
 
 
136
 
137
- Insult 10%
138
 
139
- Harassment 15%
140
 
141
- Threat 10%
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- 🔧 Training
144
 
145
- Run the training script:
146
 
 
147
 
 
 
 
 
 
 
 
 
148
 
149
- bash
150
 
151
- python train.py
152
 
153
- Or use the provided Colab notebook:
154
 
 
 
 
 
155
 
 
156
 
157
- python
158
 
159
- \# Launch training directly in Colab
160
 
161
- !python train.py
162
 
163
- 📄 License
164
 
165
- Apache-2.0 — free for commercial and research use.
166
 
 
 
 
167
 
 
168
 
169
- 🙋 Feedback / Contributions
170
 
171
- Open an issue or PR on GitHub — feedback welcome.
172
 
 
173
 
 
 
 
 
174
 
175
- 📎 References
176
 
177
- Base model: gravitee-io/bert-tiny-toxicity
178
 
 
179
 
 
180
 
181
- Framework: Hugging Face transformers + datasets
182
 
 
183
 
 
184
 
185
- Built by Floxoris Labs lightweight AI, maximum intelligence.
186
 
 
 
1
+ # Harmony v2 — Toxicity Classifier
2
 
3
+ > **Lightweight, context-aware toxicity detection that understands intent, not just keywords.**
4
 
5
+ Harmony v2 is a lightweight toxicity classifier fine-tuned from **gravitee-io/bert-tiny-toxicity** on **HarmonyDataset v2**, a custom dataset of **7,000 human-like chat messages**.
6
 
7
+ Unlike traditional keyword-based filters, Harmony v2 focuses on **who is being targeted, the intent behind the message, and conversational context**.
8
 
9
+ > **Profanity ≠ Toxicity**
10
 
11
+ ---
12
 
13
+ # 🧠 Overview
14
 
15
+ Harmony v2 is designed for modern chat moderation, especially for Telegram communities, forums, games, and social platforms.
16
 
17
+ It distinguishes between:
18
 
19
+ ### 🚨 Toxic
20
+ - Personal attacks
21
+ - Harassment
22
+ - Threats
23
+ - Humiliation
24
+ - Dehumanization
25
+ - Hate directed at another person
26
 
27
+ ### ✅ Safe
28
+ - Emotional expression
29
+ - Frustration
30
+ - Profanity without a target
31
+ - Friendly banter
32
+ - Sarcasm
33
+ - Jokes
34
+ - Self-directed insults
35
 
36
+ Instead of blocking words, Harmony v2 evaluates **intent**.
37
 
38
+ ---
39
 
40
+ # ✨ Features
41
 
42
+ | Feature | Value |
43
+ |----------|-------|
44
+ | Base model | gravitee-io/bert-tiny-toxicity |
45
+ | Dataset | HarmonyDataset v2 |
46
+ | Samples | 7,000 |
47
+ | Languages | Ukrainian, Russian, mixed UA/RU |
48
+ | Max sequence length | 512 tokens |
49
+ | Framework | Hugging Face Transformers |
50
+ | Model format | PyTorch |
51
+ | Quantized size | ~184 MB (INT8) |
52
+ | License | Apache-2.0 |
53
 
54
+ ---
55
 
56
+ # Performance
57
 
58
+ | Metric | Result |
59
+ |---------|--------|
60
+ | Evaluation Loss | **0.4255** |
61
+ | F1 Score | **98.4%** |
62
+ | CPU Inference | **~11 ms** |
63
+ | Precision | High |
64
+ | Recall | High |
65
 
66
+ ---
67
 
68
+ # 📊 Dataset
69
 
70
+ HarmonyDataset v2 contains **7,000 balanced synthetic chat messages**.
71
 
72
+ | Category | Share |
73
+ |----------|------:|
74
+ | Safe | 15% |
75
+ | Friendly profanity | 10% |
76
+ | Frustration | 10% |
77
+ | Self-insult | 5% |
78
+ | Joke | 10% |
79
+ | Sarcasm | 10% |
80
+ | Criticism | 5% |
81
+ | Insult | 10% |
82
+ | Harassment | 15% |
83
+ | Threat | 10% |
84
 
85
+ Dataset philosophy:
86
 
87
+ - realistic conversations
88
+ - Telegram-like writing
89
+ - slang
90
+ - spelling mistakes
91
+ - emojis
92
+ - mixed Ukrainian/Russian
93
+ - contextual toxicity
94
 
95
+ ---
96
 
97
+ # 🚀 Installation
98
 
99
+ Clone the repository:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
+ ```bash
102
  git clone https://github.com/your-username/harmony-v2
 
103
  cd harmony-v2
104
+ ```
105
 
106
+ Install dependencies:
 
 
 
 
107
 
108
+ ```bash
109
+ pip install -r requirements.txt
110
+ ```
111
 
112
+ ---
113
 
114
+ # 📦 Load the Model
115
 
116
+ ```python
117
+ from transformers import (
118
+ AutoTokenizer,
119
+ AutoModelForSequenceClassification
120
+ )
121
 
122
+ model_path = "./Harmony-v2"
123
 
124
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
125
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
126
+ ```
127
 
128
+ ---
129
 
130
+ # 🔍 Prediction Example
131
 
132
+ ```python
133
  import torch
134
 
 
 
135
  def predict(text):
136
+ inputs = tokenizer(
137
+ text,
138
+ return_tensors="pt",
139
+ truncation=True,
140
+ max_length=512
141
+ )
142
 
143
+ with torch.no_grad():
144
+ outputs = model(**inputs)
 
 
 
 
 
 
 
 
 
145
 
146
+ probs = torch.softmax(outputs.logits, dim=1)
147
+ toxic_score = probs[0][1].item()
148
 
149
+ return toxic_score
150
 
151
  text = "блін сервер впав, третій раз сьогодні"
152
 
 
154
 
155
  label = "🚨 Toxic" if score > 0.5 else "✅ Safe"
156
 
157
+ print(f"""
158
+ Text: {text}
159
 
160
+ Score: {score:.3f}
161
 
162
+ Prediction: {label}
163
+ """)
164
+ ```
165
 
166
+ Example output:
167
 
168
+ ```text
169
+ Text: блін сервер впав, третій раз сьогодні
170
 
171
+ Score: 0.021
172
 
173
+ Prediction: ✅ Safe
174
+ ```
175
 
176
+ ---
177
 
178
+ # 🏗 Training
179
 
180
+ Train locally:
181
 
182
+ ```bash
183
+ python train.py
184
+ ```
185
 
186
+ Or inside Google Colab:
187
 
188
+ ```python
189
+ !python train.py
190
+ ```
191
 
192
+ ---
193
 
194
+ # 📁 Repository Structure
195
 
196
+ ```
197
+ Harmony-v2/
198
+
199
+ ├── config.json
200
+ ├── tokenizer.json
201
+ ├── tokenizer_config.json
202
+ ├── special_tokens_map.json
203
+ ├── model.safetensors
204
+ ├── train.py
205
+ ├── requirements.txt
206
+ └── README.md
207
+ ```
208
 
209
+ ---
210
 
211
+ # 💡 Intended Use
212
 
213
+ Harmony v2 is suitable for:
214
 
215
+ - Telegram bots
216
+ - Discord moderation
217
+ - Forum moderation
218
+ - Live chat filtering
219
+ - AI assistants
220
+ - Comment moderation
221
+ - Social platforms
222
+ - Community management
223
 
224
+ ---
225
 
226
+ # ❌ Not Intended For
227
 
228
+ Harmony v2 should **not** be used as the sole decision-maker for:
229
 
230
+ - legal decisions
231
+ - law enforcement
232
+ - employment screening
233
+ - medical applications
234
 
235
+ Human review is recommended for critical moderation.
236
 
237
+ ---
238
 
239
+ # 📚 References
240
 
241
+ **Base model**
242
 
243
+ - gravitee-io/bert-tiny-toxicity
244
 
245
+ **Frameworks**
246
 
247
+ - Hugging Face Transformers
248
+ - Hugging Face Datasets
249
+ - PyTorch
250
 
251
+ ---
252
 
253
+ # 📄 License
254
 
255
+ Licensed under the **Apache License 2.0**.
256
 
257
+ You are free to:
258
 
259
+ - ✅ use commercially
260
+ - ✅ modify
261
+ - ✅ redistribute
262
+ - ✅ include in proprietary software
263
 
264
+ Subject to the Apache-2.0 license terms.
265
 
266
+ ---
267
 
268
+ # 🤝 Contributing
269
 
270
+ Pull requests, bug reports, and suggestions are welcome.
271
 
272
+ If you find a false positive or false negative, please open an issue.
273
 
274
+ ---
275
 
276
+ # 🌸 Floxoris Labs
277
 
278
+ **Harmony v2** is developed by **Floxoris Labs**.
279
 
280
+ > *Lightweight AI. Maximum Intelligence.*