How to run a free AI detector on your own computer
You can run an open-source AI detector locally with Python and the Hugging Face transformers library, with no account and no text leaving your computer. Desklib, the detector with the fewest false positives in our test (6.3%), took 0.57 seconds per 1,000 words on an Apple M4 Pro. The code below is the setup we used.
Tested
What you need
Python, the transformers and torch libraries, and about 1.7 GB of disk space for the Desklib model, which downloads automatically the first time you run it.
pip install torch transformers sentencepiece
The code
Desklib’s model has a custom output layer, so it needs a small class. This is the code we used in our benchmark, based on the example in Desklib’s model card.
import sys
import torch
import torch.nn as nn
from transformers import AutoConfig, AutoModel, AutoTokenizer, PreTrainedModel
MODEL = "desklib/ai-text-detector-v1.01"
class DesklibModel(PreTrainedModel):
config_class = AutoConfig
def __init__(self, config):
super().__init__(config)
self.model = AutoModel.from_config(config)
self.classifier = nn.Linear(config.hidden_size, 1)
self.post_init()
def forward(self, input_ids, attention_mask):
hidden = self.model(input_ids, attention_mask=attention_mask)[0]
mask = attention_mask.unsqueeze(-1).float()
pooled = (hidden * mask).sum(1) / mask.sum(1).clamp(min=1e-9)
return self.classifier(pooled)
device = "mps" if torch.backends.mps.is_available() else "cuda" if torch.cuda.is_available() else "cpu"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
model = DesklibModel.from_pretrained(MODEL).to(device).eval()
text = open(sys.argv[1]).read()
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=768).to(device)
with torch.no_grad():
probability = torch.sigmoid(model(inputs["input_ids"], inputs["attention_mask"])).item()
print(f"AI probability: {probability:.3f} ({'flagged as AI' if probability >= 0.5 else 'not flagged'})")
Save it as detect.py, put the text in a file, and run python detect.py essay.txt.
How to read the result
Desklib flags a text when the probability is 0.5 or higher. In our test that threshold flagged 6.3% of human texts and caught 58.3% of AI texts. Desklib reads at most 768 tokens, roughly 550 words, so for longer texts score sections separately.
A score near 0.5 means little either way. A high score on news writing deserves extra doubt, because Desklib flagged 20.8% of human news reports. A low score on text that may have been edited means little too: after a humanizer rewrite, Desklib caught 32.5% of Claude Opus 5.5 texts.
To compare detectors on your own texts, download our scores and texts and check how each one does on the kind of writing you care about.
Questions people ask
Is it safe to paste private text into an online AI detector?
That depends on the service. Running a detector locally means the text never leaves your computer, which matters for student work, client documents and unpublished writing.
Do I need a graphics card?
No. The detectors in our test ran on an Apple laptop chip. A normal processor works too, only more slowly.