harmony-v2 / README.md
sollamon's picture
Update README.md
54f7e6f verified
|
Raw
History Blame Contribute Delete
5.03 kB

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:

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

Install dependencies:

pip install -r requirements.txt

πŸ“¦ Load the Model

from transformers import (
    AutoTokenizer,
    AutoModelForSequenceClassification
)

model_path = "./Harmony-v2"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path)

πŸ” Prediction Example

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: Π±Π»Ρ–Π½ сСрвСр Π²ΠΏΠ°Π², Ρ‚Ρ€Π΅Ρ‚Ρ–ΠΉ Ρ€Π°Π· ΡΡŒΠΎΠ³ΠΎΠ΄Π½Ρ–

Score: 0.021

Prediction: βœ… Safe

πŸ— Training

Train locally:

python train.py

Or inside Google Colab:

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