Built for the
Balance Tes Haters project, which collects and analyses cyberbullying reports from Instagram, TikTok, YouTube and Twitter.
1from huggingface_hub import hf_hub_download
2from sentence_transformers import SentenceTransformer
3import joblib
4import numpy as np
5
6# Load components
7clf = joblib.load(hf_hub_download(
8 repo_id="DataForGood/balance-tes-haters-classifier",
9 filename="harassment_arctic_mlp.joblib",
10))
11encoder = SentenceTransformer("Snowflake/snowflake-arctic-embed-l-v2.0")
12
13def predict(text: str) -> int:
14 """Returns 1 (harassment) or 0 (benign)."""
15 X = encoder.encode([text], convert_to_numpy=True)
16 return int(clf.predict(X)[0])
17
18def predict_proba(text: str) -> float:
19 """Returns harassment probability between 0 and 1."""
20 X = encoder.encode([text], convert_to_numpy=True)
21 return float(clf.predict_proba(X)[0, 1])
22
23# Examples
24predict("<Insert hateful french comment>") # → 1
25predict("super vidéo, continue comme ça") # → 0