Views
No views yet
rasbt/human-vs-ai-50k. Human-written text has label 0 and AI-generated text has label 1.1hf download rasbt/ai-text-detector-distilbert \
2 --local-dir models/ai-text-detector-distilbert1import json
2from pathlib import Path
3
4import torch
5from transformers import AutoModelForSequenceClassification, AutoTokenizer
6
7
8model_dir = Path("models/ai-text-detector-distilbert")
9metadata = json.loads(
10 (model_dir / "detector-config.json").read_text(encoding="utf-8")
11)
12tokenizer = AutoTokenizer.from_pretrained(model_dir)
13model = AutoModelForSequenceClassification.from_pretrained(model_dir)
14model.eval()
15
16text = "Paste the text to classify here."
17inputs = tokenizer(
18 text,
19 truncation=True,
20 max_length=metadata["max_length"],
21 return_tensors="pt",
22)
23
24with torch.inference_mode():
25 logits = model(**inputs).logits / metadata["temperature"]
26 probabilities = logits.float().softmax(dim=-1)
27
28ai_index = metadata["label_mapping"]["ai"]
29ai_probability = probabilities[0, ai_index].item()
30print({"score": round(100 * ai_probability, 4)})detector-config.json contains the calibration temperature and training metadata. The recommended inference implementation is provided in the rasbt/ai-detector repository.