<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[RewriteAI Lab]]></title><description><![CDATA[RewriteAI Lab is the research and writing blog of RewriteAI (https://rewriteai.site), a platform for AI text humanizing and detection. We publish original tests, explainers, and practical guides on AI-assisted writing.]]></description><link>https://rewriteai.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6add98fbf31315eb13cc810e/01e29aa5-df60-456d-91e1-d12b48d57259.png</url><title>RewriteAI Lab</title><link>https://rewriteai.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Thu, 29 Oct 2026 22:21:49 GMT</lastBuildDate><atom:link href="https://rewriteai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How AI Detectors Actually Work: Perplexity and Burstiness, Explained with Code]]></title><description><![CDATA[What these two signals measure, how to compute them yourself, and why they produce false positives.]]></description><link>https://rewriteai.hashnode.dev/how-ai-detectors-actually-work-perplexity-and-burstiness-explained-with-code</link><guid isPermaLink="true">https://rewriteai.hashnode.dev/how-ai-detectors-actually-work-perplexity-and-burstiness-explained-with-code</guid><category><![CDATA[AI]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[Python]]></category><category><![CDATA[writing]]></category><category><![CDATA[rewriteaisite]]></category><category><![CDATA[rewriteai]]></category><dc:creator><![CDATA[Khubru Alee]]></dc:creator><pubDate>Mon, 26 Oct 2026 13:00:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6add98fbf31315eb13cc810e/b7256b28-a699-4450-b332-45dc6dc3742a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>AI detectors don't tell you who wrote a text but instead give an estimate of how similar the text is to what would be produced by a language model.</p>
<p>Most explanations about how AI Detectors work will mention Perplexity and Burstiness. This post explains what they are, how to calculate a basic version and why they result in false positives.</p>
<p>Perplexity</p>
<p>Perplexity is calculated by taking the probability assigned to each subsequent token by the language model. It gives an indication of how much of the text surprised the language model. Lower perplexity means the text was easier to predict. Higher perplexity means it was harder.</p>
<p>Language models will generally have low perplexities as they are sampling the most likely tokens. Human written texts will often have higher perplexities due to the variability of choice of words, tangents and idioms.</p>
<p>A basic example of this with GPT2 is:</p>
<p>import math
import torch
from transformers import GPT2LMHeadModel, GPT2TokenizerFast</p>
<p>tokenizer = GPT2TokenizerFast.from_pretrained("gpt2")
model = GPT2LMHeadModel.from_pretrained("gpt2").eval()</p>
<p>def perplexity(text: str) -&gt; float:
enc = tokenizer(text, return_tensors="pt", truncation=True, max_length=1024)
with torch.no_grad():
loss = model(enc, labels=enc["input_ids"]).loss
return math.exp(loss.item())</p>
<p>This value will vary based on the model used. It won't give you a universal "AI score" but just an indication of how likely the text was to be AI based compared to the same model.</p>
<p>Burstiness</p>
<p>Humans usually write in a way that has a mixture of both short and long sentences. Language models often have a more even flow. This is what Burstiness is trying to measure. The easiest way to do this is by measuring how long your sentences are.</p>
<p>import re</p>
<p>def burstiness(text: str) -&gt; float:
sentences = [s for s in re.split(r"(?&lt;=[.!?])\s+", text.strip()) if s]
lengths = [len(s.split()) for s in sentences]
if len(lengths) &lt; 2:
return 0.0
mean = sum(lengths)/len(lengths)
variance = sum( (n - mean) 2 for n in lengths)/len(lengths)
return (variance ** 0.5)/mean #Coefficient of variation</p>
<p>Higher values indicate more variable sentence lengths. This is a basic example of how you could calculate burstiness. True detectors use much more complex features.</p>
<p>Why they give false positives</p>
<p>These are both style based indicators and are therefore susceptible to:</p>
<p>Formal/technical documents often have low perplexities and even flow, making them appear like they were written by a machine.</p>
<p>Non-native English often has common words and simple and consistent sentences.</p>
<p>Short texts will not have enough of a signal and can get almost any score for a 2 sentence paragraph.</p>
<p>Text that has been heavily edited (by humans editing AI text or AI editing human text) will fall into the middle ground.</p>
<p>We have seen this ourselves. We tested 8 texts and a human written paragraph gave a 99% AI score. This does not mean they are useless but you shouldn't take them as proof.</p>
<p>What to look out for in a useful detector</p>
<p>When building or choosing a detector look out for:</p>
<p>Probability.</p>
<p>Sentence level information.</p>
<p>Clear limitations of what the detector can do. This should state what the minimum text length is, what languages it works on and that it is probabilistic.</p>
<p>No automatic actions.</p>
<p>Our <a href="https://rewriteai.site/ai-detector">RewriteAI AI Detector</a> gives you a probability of how likely the text is AI and Sentence level information. Some other terminology you may see can be found in our <a href="https://rewriteai.site/post/ai-detection-glossary">AI Detection Glossary</a>.</p>
<p>Key Points</p>
<p>Perplexity = How predictable the text is.</p>
<p>Burstiness = How varied the flow of the text is.</p>
<p>They are both style based so will cause issues with formal, non-native and short texts.</p>
<p>Never take the score as proof. Just take it as evidence.</p>
<p>If you need to prove who wrote the text keep your drafts, notes and version history. This will be a much better indicator than any score.</p>
<p>Let me know if you have had any surprising results from an AI Detector in the comments.</p>
]]></content:encoded></item></channel></rss>