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.
File size: 1,515 Bytes
f850fbb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()