CoolFace
Modelpublic

simocorbo/toxicthesis-gemini-3.5-flash-rntn-classification-3

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
Model Card

RNTN - GEMINI-3.5-FLASH - Classification (3 classes)

Toxicity prediction model trained on the GEMINI-3.5-FLASH dataset.

PropertyValue
ModelRNTN
TaskClassification (3 classes)
Datasetgemini-3.5-flash
FrameworkPyTorch / PyTorch Lightning

Class: RNTNLightning

python
from src.models.rntn import RNTNLightning

model = RNTNLightning(
    vocab: dict,                      # Token-to-index mapping
    hidden_dim: int = 300,            # Hidden dimension
    use_tensor: bool = True,          # Use tensor composition
    use_linear: bool = True,          # Use linear composition
    dropout: float = 0.2,
    num_classes: int = 1,             # 1=regression, 2+=classification
    loss_type: str = 'mse',           # 'mse', 'bce', 'cross_entropy'
    lr: float = 5e-4,
    gradient_clip_norm: float = 1.0,
    use_residual: bool = True,
    residual_weight: float = 0.2,
    activation: str = 'tanh'          # 'tanh', 'relu', 'gelu'
)

Methods

MethodDescription
forward(batch)Process batch of constituency trees. Returns dict with 'predictions'.
predict_score(text)Predict toxicity score for raw text string. Handles parsing internally.
predict_batch(texts)Predict scores for a list of texts.
load_from_checkpoint(path)Load model from checkpoint file.

Required Files

  • vocab_stanza_hybrid.pkl: Vocabulary mapping (token -> index)
  • label_mappings.pkl: Constituency label mappings
  • cc.en.300.bin: FastText embeddings (300-dim)

Usage with ToxicThesis (Recommended)

python
# 1. Clone ToxicThesis repository
# git clone https://github.com/simo-corbo/ToxicThesis
# cd ToxicThesis && pip install -r requirements.txt

from huggingface_hub import snapshot_download
import torch
import pickle

# 2. Download model files
model_dir = snapshot_download(
    repo_id="simocorbo/toxicthesis-gemini-3.5-flash-rntn-classification-3",
    allow_patterns=["checkpoints/*", "*.pkl"]
)

# 3. Load vocabulary
with open(f"{model_dir}/vocab_stanza_hybrid.pkl", 'rb') as f:
    vocab = pickle.load(f)

# 4. Import and load model from ToxicThesis
from src.models.rntn import RNTNLightning

model = RNTNLightning.load_from_checkpoint(
    f"{model_dir}/checkpoints/best.pt",
    vocab=vocab,
    offline_init=False  # Set True to skip loading FastText/Stanza at init
)
model.eval()

# 5. Predict score for a single text (handles parsing internally)
with torch.no_grad():
    score = model.predict_score("Your text here")
    print(f"Toxicity score: {score}")

# 6. Predict for multiple texts
texts = ["Hello friend", "You are terrible", "Have a nice day"]
with torch.no_grad():
    for text in texts:
        score = model.predict_score(text)
        print(f"{text}: {score:.4f}")

Note on Standalone Usage

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.

Score Interpretation

OutputRangeMeaning
probabilitiesList[float]Probability distribution over 3 classes.
class0 to 2Predicted class (argmax of probabilities).

Classes: 3 toxicity levels, where higher class index = more toxic.

Files

FileDescription
checkpoints/best.ptModel checkpoint (best validation loss)
hparams.yamlHyperparameters used for training
train.csvTraining metrics per epoch
val.csvValidation metrics per epoch
vocab_stanza_hybrid.pklVocabulary (for tree-based models)

Installation

bash
# Clone ToxicThesis for full model implementations
git clone https://github.com/simo-corbo/ToxicThesis
cd ToxicThesis
pip install -r requirements.txt

# Or install dependencies directly
pip install torch transformers huggingface_hub fasttext-wheel stanza

Citation

bibtex
@software{toxicthesis2025,
  title={ToxicThesis},
  author={Corbo, Simone},
  year={2025},
  url={https://github.com/simo-corbo/ToxicThesis}
}