File size: 5,033 Bytes
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
565bd53
0b7f3a3
 
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
 
 
54f7e6f
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
f5238e8
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
 
 
0b7f3a3
 
 
 
 
 
565bd53
0b7f3a3
 
565bd53
0b7f3a3
 
565bd53
0b7f3a3
565bd53
 
 
 
 
 
 
0b7f3a3
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
 
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
 
 
 
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
565bd53
0b7f3a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Harmony v2 — Toxicity Classifier

> **Lightweight, context-aware toxicity detection that understands intent, not just keywords.**

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**.

Unlike traditional keyword-based filters, Harmony v2 focuses on **who is being targeted, the intent behind the message, and conversational context**.

> **Profanity ≠ Toxicity**

---

# 🧠 Overview

Harmony v2 is designed for modern chat moderation, especially for Telegram communities, forums, games, and social platforms.

It distinguishes between:

### 🚨 Toxic
- Personal attacks
- Harassment
- Threats
- Humiliation
- Dehumanization
- Hate directed at another person

### ✅ Safe
- Emotional expression
- Frustration
- Profanity without a target
- Friendly banter
- Sarcasm
- Jokes
- Self-directed insults

Instead of blocking words, Harmony v2 evaluates **intent**.

---

# ✨ Features

| Feature | Value |
|----------|-------|
| Base model | gravitee-io/bert-tiny-toxicity |
| Dataset | HarmonyDataset v2 |
| Samples | 7,000 |
| Languages | Ukrainian, Russian, mixed UA/RU |
| Max sequence length | 512 tokens |
| Framework | Hugging Face Transformers |
| Model format | PyTorch |
| Quantized size | ~9 MB (INT8) |
| License | Apache-2.0 |

---

# ⚡ Performance

| Metric | Result |
|---------|--------|
| Evaluation Loss | **0.4255** |
| F1 Score | **98.4%** |
| CPU Inference | **~11 ms** |
| Precision | High |
| Recall | High |

---

# 📊 Dataset

HarmonyDataset v2 contains **7,000 balanced synthetic chat messages**.

| Category | Share |
|----------|------:|
| Safe | 15% |
| Friendly profanity | 10% |
| Frustration | 10% |
| Self-insult | 5% |
| Joke | 10% |
| Sarcasm | 10% |
| Criticism | 5% |
| Insult | 10% |
| Harassment | 15% |
| Threat | 10% |

Dataset philosophy:

- realistic conversations
- Telegram-like writing
- slang
- spelling mistakes
- emojis
- mixed Ukrainian/Russian
- contextual toxicity

---

# 🚀 Installation

Clone the repository:

```bash

git clone https://github.com/floxoris/harmony-v2

cd harmony-v2

```

Install dependencies:

```bash

pip install -r requirements.txt

```

---

# 📦 Load the Model

```python

from transformers import (

    AutoTokenizer,

    AutoModelForSequenceClassification

)



model_path = "./Harmony-v2"



tokenizer = AutoTokenizer.from_pretrained(model_path)

model = AutoModelForSequenceClassification.from_pretrained(model_path)

```

---

# 🔍 Prediction Example

```python

import torch



def predict(text):

    inputs = tokenizer(

        text,

        return_tensors="pt",

        truncation=True,

        max_length=512

    )



    with torch.no_grad():

        outputs = model(**inputs)



    probs = torch.softmax(outputs.logits, dim=1)

    toxic_score = probs[0][1].item()



    return toxic_score



text = "блін сервер впав, третій раз сьогодні"



score = predict(text)



label = "🚨 Toxic" if score > 0.5 else "✅ Safe"



print(f"""

Text: {text}



Score: {score:.3f}



Prediction: {label}

""")

```

Example output:

```text

Text: блін сервер впав, третій раз сьогодні



Score: 0.021



Prediction: ✅ Safe

```

---

# 🏗 Training

Train locally:

```bash

python train.py

```

Or inside Google Colab:

```python

!python train.py

```

---

# 📁 Repository Structure

```

Harmony-v2/


├── config.json

├── tokenizer.json

├── tokenizer_config.json

├── special_tokens_map.json

├── model.safetensors

├── train.py

├── requirements.txt

└── README.md

```

---

# 💡 Intended Use

Harmony v2 is suitable for:

- Telegram bots
- Discord moderation
- Forum moderation
- Live chat filtering
- AI assistants
- Comment moderation
- Social platforms
- Community management

---

# ❌ Not Intended For

Harmony v2 should **not** be used as the sole decision-maker for:

- legal decisions
- law enforcement
- employment screening
- medical applications

Human review is recommended for critical moderation.

---

# 📚 References

**Base model**

- gravitee-io/bert-tiny-toxicity

**Frameworks**

- Hugging Face Transformers
- Hugging Face Datasets
- PyTorch

---

# 📄 License

Licensed under the **Apache License 2.0**.

You are free to:

- ✅ use commercially
- ✅ modify
- ✅ redistribute
- ✅ include in proprietary software

Subject to the Apache-2.0 license terms.

---

# 🤝 Contributing

Pull requests, bug reports, and suggestions are welcome.

If you find a false positive or false negative, please open an issue.

---

# 🌸 Floxoris Labs

**Harmony v2** is developed by **Floxoris Labs**.

> *Lightweight AI. Maximum Intelligence.*