Toxicity prediction model trained on the GEMINI-3.5-FLASH dataset.
1from src.models.rntn import RNTNLightning
2
3model = RNTNLightning(
4 vocab: dict, # Token-to-index mapping
5 hidden_dim: int = 300, # Hidden dimension
6 use_tensor: bool = True, # Use tensor composition
7 use_linear: bool = True, # Use linear composition
8 dropout: float = 0.2,
9 num_classes: int = 1, # 1=regression, 2+=classification
10 loss_type: str = 'mse', # 'mse', 'bce', 'cross_entropy'
11 lr: float = 5e-4,
12 gradient_clip_norm: float = 1.0,
13 use_residual: bool = True,
14 residual_weight: float = 0.2,
15 activation: str = 'tanh' # 'tanh', 'relu', 'gelu'
16)
1# 1. Clone ToxicThesis repository
2# git clone https://github.com/simo-corbo/ToxicThesis
3# cd ToxicThesis && pip install -r requirements.txt
4
5from huggingface_hub import snapshot_download
6import torch
7import pickle
8
9# 2. Download model files
10model_dir = snapshot_download(
11 repo_id="simocorbo/toxicthesis-gemini-3.5-flash-rntn-classification-3",
12 allow_patterns=["checkpoints/*", "*.pkl"]
13)
14
15# 3. Load vocabulary
16with open(f"{model_dir}/vocab_stanza_hybrid.pkl", 'rb') as f:
17 vocab = pickle.load(f)
18
19# 4. Import and load model from ToxicThesis
20from src.models.rntn import RNTNLightning
21
22model = RNTNLightning.load_from_checkpoint(
23 f"{model_dir}/checkpoints/best.pt",
24 vocab=vocab,
25 offline_init=False # Set True to skip loading FastText/Stanza at init
26)
27model.eval()
28
29# 5. Predict score for a single text (handles parsing internally)
30with torch.no_grad():
31 score = model.predict_score("Your text here")
32 print(f"Toxicity score: {score}")
33
34# 6. Predict for multiple texts
35texts = ["Hello friend", "You are terrible", "Have a nice day"]
36with torch.no_grad():
37 for text in texts:
38 score = model.predict_score(text)
39 print(f"{text}: {score:.4f}")
RNTN requires constituency parsing via Stanza and tree processing. For standalone usage without ToxicThesis, you would need to implement the full tree preprocessing pipeline. We recommend using ToxicThesis directly. See src/models/rntn.py for the complete implementation.
1# Clone ToxicThesis for full model implementations
2git clone https://github.com/simo-corbo/ToxicThesis
3cd ToxicThesis
4pip install -r requirements.txt
5
6# Or install dependencies directly
7pip install torch transformers huggingface_hub fasttext-wheel stanza
1@software{toxicthesis2025,
2 title={ToxicThesis},
3 author={Corbo, Simone},
4 year={2025},
5 url={https://github.com/simo-corbo/ToxicThesis}
6}