Toxicity prediction model trained on the GEMINI-3.5-FLASH dataset.
1from src.models.lstm import LSTMModel
2
3model = LSTMModel(
4 input_dim: int = 300, # Dimension of input embeddings
5 hidden_dim: int = 128, # LSTM hidden dimension
6 num_layers: int = 2, # Number of LSTM layers
7 dropout: float = 0.3, # Dropout probability
8 bidirectional: bool = True, # Use bidirectional LSTM
9 num_classes: int = 2, # 1=regression, 2=binary, 3+=multi-class
10 loss_fn: str = 'auto',
11 lr: float = 0.001,
12 gradient_clip_norm: float = 1.0
13)
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 hf_hub_download
6import torch
7import numpy as np
8
9# 2. Download checkpoint
10checkpoint_path = hf_hub_download(
11 repo_id="simocorbo/toxicthesis-gemini-3.5-flash-lstm-classification-3",
12 filename="checkpoints/best.pt"
13)
14
15# 3. Import and load model from ToxicThesis
16from src.models.lstm import LSTMModel
17
18# Load using the built-in class method
19model = LSTMModel.load_from_checkpoint(checkpoint_path, map_location='cpu')
20model.eval()
21
22# 4. Load FastText for embeddings
23from src.utils.fasttext_utils import load_fasttext_model
24ft = load_fasttext_model('cc.en.300.bin')
25
26# 5. Get predictions
27def predict(text: str, max_len: int = 128) -> dict:
28 tokens = text.lower().split()[:max_len]
29 embeddings = [ft.get_word_vector(w) for w in tokens] or [np.zeros(300)]
30
31 # Pad sequence
32 while len(embeddings) < max_len:
33 embeddings.append(np.zeros(300))
34
35 x = torch.tensor(np.array(embeddings[:max_len]), dtype=torch.float32).unsqueeze(0)
36
37 with torch.no_grad():
38 logits = model(x)
39
40 if model.num_classes == 1:
41 score = torch.sigmoid(logits).item()
42 return {'score': score}
43 elif model.num_classes == 2:
44 prob = torch.sigmoid(logits).item()
45 return {'probability': prob, 'class': int(prob >= 0.5)}
46 else:
47 probs = torch.softmax(logits, dim=-1).squeeze().tolist()
48 return {'probabilities': probs, 'class': int(np.argmax(probs))}
49
50result = predict("Your text here")
51print(result)
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}