Back to News
RSS feedmagazine.sebastianraschka.com

Building an AI Text Detector From Scratch

Summary

Sebastian Raschka presents an educational project for building an AI text detector from scratch, prompted partly by Substack’s built-in detection feature and interest in local small-language-model projects. The project has two linked aims: explain how AI detectors work and use the detector as a verifier while training a small language model to produce text that avoids detection. The tutorial frames this as a broader example of building a scorer or verifier for an LLM application, rather than as a definitive test of authorship. The proposed system is intended to support both human users and agents through an API and a local browser interface that reports a whole-text AI score and can highlight scores for individual chunks. The article discusses several detection approaches, including supervised classifiers, perturbation-based probability tests, perplexity measures, and watermarking, but focuses on a classifier similar to the models believed to support Substack’s detector. The planned implementation fine-tunes DistilBERT to return a 0–100 score representing the classifier’s estimated probability for the AI-generated class under its training distribution. The author stresses that this score is not a general probability that a text was written by AI. The project also targets practical uses such as filtering spam and checking whether grammar or editing tools have made a person’s writing appear overly AI-like. Its central limitation is the adversarial, changing relationship between detectors and language models: a detector may learn one model’s patterns, while another model may avoid them deliberately or incidentally, forcing future updates. Human-written text can also be falsely flagged, so detection results require cautious interpretation.