Toxicity prediction model trained on the GEMINI-3.5-FLASH dataset.
1from src.models.lstm import TreeLSTMModel
2
3model = TreeLSTMModel(
4 vocab: dict, # Token-to-index mapping
5 hidden_dim: int = 256, # Hidden dimension
6 num_classes: int = 1, # 1=regression, 2+=classification
7 dropout: float = 0.3,
8 lr: float = 0.001,
9 loss_fn: str = 'auto'
10)
The model expects constituency trees converted to a PyTorch Geometric batch with:
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-tree-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.lstm import TreeLSTMModel
21
22checkpoint = torch.load(f"{model_dir}/checkpoints/best.pt", map_location='cpu')
23hparams = checkpoint.get('hyper_parameters', {})
24
25model = TreeLSTMModel(
26 vocab=vocab,
27 hidden_dim=hparams.get('hidden_dim', 256),
28 num_classes=hparams.get('num_classes', 3)
29)
30model.load_state_dict(checkpoint.get('state_dict', checkpoint), strict=False)
31model.eval()
32
33# 5. For inference, use the preprocessing pipeline to convert text to tree format
34from src.preprocessing.tree_utils import text_to_tree_batch
35
36# Parse and convert text to tree batch
37tree_batch = text_to_tree_batch("Your text here", vocab)
38
39with torch.no_grad():
40 logits = model(tree_batch)
41 if model.num_classes == 1:
42 score = torch.sigmoid(logits).item()
43 print(f"Score: {score}")
44 else:
45 probs = torch.softmax(logits, dim=-1)
46 print(f"Probabilities: {probs}")
TreeLSTM requires constituency parsing and tree-to-graph conversion. For standalone usage, you would need to implement the tree preprocessing pipeline. We recommend using ToxicThesis directly.
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}