Views
No views yet
FALSE (Not NSFW), TRUE (NSFW)1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="your-username/distilbert-nsfw-classifier",
6 tokenizer="your-username/distilbert-nsfw-classifier"
7)
8
9# Prepare input text (combine domain, title, description)
10text = """domain: example.com
11title: Article Title Here
12description: Article description text goes here"""
13
14result = classifier(text)
15print(result)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "your-username/distilbert-nsfw-classifier"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Prepare input text
10text = """domain: example.com
11title: Article Title Here
12description: Article description text goes here"""
13
14# Tokenize
15inputs = tokenizer(
16 text,
17 return_tensors="pt",
18 truncation=True,
19 padding=True,
20 max_length=512
21)
22
23# Predict
24with torch.no_grad():
25 outputs = model(**inputs)
26 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
27 predicted_class_id = predictions.argmax().item()
28 confidence = predictions[0][predicted_class_id].item()
29
30# Get label
31id2label = model.config.id2label
32predicted_label = id2label[predicted_class_id]
33
34print(f"Predicted: {predicted_label} (confidence: {confidence:.4f})")domain: example.com
title: Article Title Here
description: Article description text goes herefield_name: valueTest Accuracy: 1.0000
Test Loss: 0.0016
Classification Report:
precision recall f1-score support
FALSE 1.00 1.00 1.00 120
TRUE 1.00 1.00 1.00 133
accuracy 1.00 2531@misc{distilbert-nsfw-classifier,
2 title={DistilBERT NSFW Article Classifier},
3 author={Your Name},
4 year={2024},
5 howpublished={\url{https://huggingface.co/your-username/distilbert-nsfw-classifier}}
6}