// HACKER NEWS — CYBERSECURITY
Better AI code comment detector
When I trained the previous ai comment classifier, I used partially personal
private data to do it, and built it on a somewhat shaky foundation, so I
couldn’t share the code or data. I rebuilt it on public data and a better
foundation!
First off, you might want to try it out. Nothing you paste into that web page
leaves your browser, so you can safely try it with whatever you like. I have
invited some testers to try out an earlier version of it, and they had mainly
positive feedback to give.
We won’t break down robot-isms the way we broke down Claude-isms in the previous
article, because in the ui of the new classifier you can just click any part
of the text being classified to see which features activate on that portion of
the text, and how they contribute to the overall judgment. Here’s an example of
the expanded feature activation view.
In terms of performance, the headline number is the balanced accuracy of 77 %.
This is how often the classifier gets the human vs. robot verdict right,
assuming human-written and robot-generated comments are equally likely.
The classifier also prints a predicted percentage which is calibrated, meaning
it can be read as the probability that any specific verdict is correct. We test
this through the calibration curve, which shows what probability the classifier
assigns to an event with a known probability.
Since all dots lie very close to the reference diagonal, we know they are
approximately correct. This holds true across comments of multiple lengths,
where a fitted temperature parameter adjusts for increased confidence as the
amount of data increases.
We can get more details about the classifier’s failure modes by looking at its
confusion matrix. In this table, “robot” is considered the positive class, i.e.
the thing we want to detect. The abbreviations stand for true/false
positive/negative rate.
When presented with a known-human input, the classifier correctly judges it as
human 73 % of the time. With a known-robot input, it is correctly judged 80 % of
the time. This means in both cases (known-human and known-robot) the mistake
rate is around 25 %. That might sound high!
But remember that this mistake rate is the aggregate over all possible
inputs. We don’t need to pay too much attention to it, because the classifier
outputs a calibrated predictive percentage every time it classifies something.
Thus, for individual judgments, we know when the risk of false positives is
lower or higher. When the classifier is very confident – e.g. when the confidence is
80 % or more – the risk of a false positive drops to 5 %. When the classifier is
uncertain – when confidence is around 50 % – then by calibration it will issue
the wrong verdict around half the time.
I mention the numbers in this confusion matrix only because they are so often
used when discussing classifiers, so more academically inclined readers may
expect to see it. Here are some other requested numbers: