Michael Zazon

AI & agents · Build log

Training my own AI text detector with Claude Code

I fine-tuned a small open model on pairs of human writing and AI rewrites of the same text, with Claude Code orchestrating the data builds, training runs and evaluation.

Part 1 · Model training

I am always looking for ways to improve my workflow and I recently read a research article about the Ettin 1B models and how training on top of them with public datasets and also being able to generate my own data using my own writing could layer on top of this for developing my own efficient AI text detection model.

The paper I read was Ettin, an open suite of paired encoders and decoders, which used the same training recipe for several model sizes. This means that small open models are a realistic starting point for building a classifier. But my question is narrow. General detectors can catch most AI text written from scratch, but they struggle with short human writing, which is where I need help.

Claude Code runs the experiment jointly with me: I set the goals and rules, and we plan each round together. It creates the datasets and executes training and evaluation jobs on Colab, and I review the results and decide what to do next. The training data consists of pairs: a human-written paragraph in the style I’m targeting versus AI rewrites of the same text by several frontier models. I hold back one model family from the training data to see if the detector recognizes a model from a provider it hasn’t seen before. I use LoRA adapters on an open base model for fine-tuning, and the resulting model runs on my laptop at about half a second per text.

Most of the time I spent on this was proving that it works. Before I even started generating training data, I wrote down the main metric I cared about: the false-flag rate on human text at the threshold where the model catches 90% of AI text, split by text length. At the time, I wrote down “Better on our text”. I did a small pilot and found that the base model already caught 84-96% of fully AI-written text, so where it was failing was short human writing.

One thing I learned during the pilot about test sets: I hadn’t tagged paragraphs with their source document, so I ended up with parts of the same document in both train and test. An outside review of the pilot by another model concluded that the pilot’s conclusions held “only narrowly”, which I think is a fair criticism of that setup. I’ve made sure that all splits are by source document, so no paragraph or rewrite of a test document makes it into training. I held back a final test set and scored it just once.

That single final run is the result I trust. For human-written text under 60 words, the base model flagged 39.8% as AI, and the round-two model flagged 5.7%. The development set suggested 2.6% (which looked better), but the final set is the fairer number, and that’s what I’ve reported.

The rules were written down before training began, and they could veto new work. Round three needed to keep round two’s short-text numbers and improve on at least one new kind of AI-generated text. It passed. I wondered whether we were fine-tuning the right model, so we raced two smaller models on the same data. Both lagged on every measure. A later challenger, trained on the same data, missed the short-text bar by a wide margin and wasn’t shipped. The current model stays.

I built it to study detectors, not to beat them: how often they flag human writing, and which sentences drive a score up, so I can tell when a detector’s number means something. The number of short-text samples is still small, so these claims are based on bootstrap intervals. I haven’t tested it on other people’s writing yet.

Next up is a long-lived evaluation harness that uses a fixed probe set and lets me score any new model with a single command. I think we need test harnesses and evals that can scale for years as we continue to train new models and model families. This is planned but not yet built, and I’ll write more about it once it’s running.