Text Classification
Transformers
Safetensors
English
roberta
toxicity
llada
distillation
custom_code
text-embeddings-inference
Run this model with HF Jobs
Run kl1/roberta_toxicity_classifier_LLaDA on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/kl1/roberta_toxicity_classifier_LLaDA. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/kl1/roberta_toxicity_classifier_LLaDA on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use kl1/roberta_toxicity_classifier_LLaDA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kl1/roberta_toxicity_classifier_LLaDA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="kl1/roberta_toxicity_classifier_LLaDA", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("kl1/roberta_toxicity_classifier_LLaDA", trust_remote_code=True) model = AutoModelForSequenceClassification.from_pretrained("kl1/roberta_toxicity_classifier_LLaDA", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download smoke_test.py from kl1/roberta_toxicity_classifier_LLaDA: direct link, hf CLI and curl.
- Browser
- Download file 1.52 kB
-
https://huggingface.co/kl1/roberta_toxicity_classifier_LLaDA/resolve/main/smoke_test.py
- Command line
-
hf download hf://kl1/roberta_toxicity_classifier_LLaDA/smoke_test.py
-
curl -L -o smoke_test.py https://huggingface.co/kl1/roberta_toxicity_classifier_LLaDA/resolve/main/smoke_test.py
1.52 kB
| from __future__ import annotations | |
| import argparse | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| "model_path", | |
| nargs="?", | |
| default=Path(__file__).resolve().parent, | |
| help="Local path or Hugging Face model id.", | |
| ) | |
| args = parser.parse_args() | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| args.model_path, | |
| trust_remote_code=True, | |
| use_fast=True, | |
| ) | |
| model = AutoModelForSequenceClassification.from_pretrained( | |
| args.model_path, | |
| trust_remote_code=True, | |
| ).eval() | |
| texts = [ | |
| "I hope you have a wonderful day.", | |
| "You are disgusting and should disappear.", | |
| ] | |
| inputs = tokenizer( | |
| texts, | |
| padding=True, | |
| truncation=True, | |
| max_length=512, | |
| return_tensors="pt", | |
| ) | |
| cls_token_id = getattr(model.config, "student_cls_token_id", tokenizer.cls_token_id) | |
| if cls_token_id is not None and int(inputs.input_ids[0, 0]) != int(cls_token_id): | |
| raise RuntimeError("Tokenizer did not prepend the expected CLS token.") | |
| with torch.inference_mode(): | |
| probs = torch.softmax(model(**inputs).logits, dim=-1) | |
| toxic_id = int(model.config.label2id.get("toxic", 1)) | |
| for text, score in zip(texts, probs[:, toxic_id].tolist()): | |
| print(f"{score:.6f}\t{text}") | |
| if __name__ == "__main__": | |
| main() | |