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-lora \
2 --local-dir models/ai-text-detector-distilbert-lora1import json
2from pathlib import Path
3
4import torch
5from peft import AutoPeftModelForSequenceClassification
6from transformers import AutoTokenizer
7
8
9model_dir = Path("models/ai-text-detector-distilbert-lora")
10metadata = json.loads(
11 (model_dir / "detector-config.json").read_text(encoding="utf-8")
12)
13tokenizer = AutoTokenizer.from_pretrained(model_dir)
14model = AutoPeftModelForSequenceClassification.from_pretrained(model_dir)
15model.eval()
16
17text = "Paste the text to classify here."
18inputs = tokenizer(
19 text,
20 truncation=True,
21 max_length=metadata["max_length"],
22 return_tensors="pt",
23)
24
25with torch.inference_mode():
26 logits = model(**inputs).logits / metadata["temperature"]
27 probabilities = logits.float().softmax(dim=-1)
28
29ai_index = metadata["label_mapping"]["ai"]
30ai_probability = probabilities[0, ai_index].item()
31print({"score": round(100 * ai_probability, 4)})detector-config.json contains the adapter, calibration, and training metadata. The recommended inference implementation is provided in the rasbt/ai-detector repository.