AI-Generated Text Detection and Rewriting: Technical Principles and Engineering Practices

    This article explains why detecting AI-generated text has become an engineering problem, and reviews the main technical approaches for detection, rewriting, and content governance. It covers unsupervised signals such as perplexity and burstiness, supervised classification models, watermarking and provenance methods, as well as engineering challenges including false positives, adversarial paraphrasing, multilingual drift, and evaluation. It also examines legitimate rewriting use cases, context-aware rewriting, compliance boundaries, and practical recommendations for building measurable, reliable text content systems.

    1. Why “human or machine” has become an engineering problem

    The widespread adoption of generative large models has sharply reduced the cost of text production. It has also introduced new governance challenges. Content platforms need to identify low-quality or non-compliant text generated at scale. Academic and educational settings need to guard against ghostwriting and academic misconduct. Content operations teams need to judge where source material comes from in order to control quality risk.

    As a result, the question “was this text generated by AI?” has moved from a philosophical question to an engineering problem that can be modeled, measured, and optimized.

    It is important to understand that AI text detection and text rewriting form a pair of opposing but related technologies. Detection tries to recover the true origin of text as accurately as possible, while rewriting tries to change surface-level statistical characteristics. Understanding the technical mechanics of both sides is a prerequisite for building any text content governance system.

    This article does not focus on any specific commercial tool. Instead, it describes the general technical principles behind this workflow and the key engineering trade-offs.

    2. Technical principles of AI text detection

    The core assumption behind text detection is that machine-generated text and human-written text show observable differences in statistical distribution. Based on this assumption, the industry mainly follows three technical approaches.

    2.1 Unsupervised methods based on statistical features

    These methods do not rely on labeled data. Instead, they directly measure statistical properties of text. Two typical indicators are:

    • Perplexity: This measures how “surprised” a language model is by a piece of text. The less surprising a sequence is to the model, meaning the more predictable each token is, the lower the perplexity. Because large models tend to generate high-probability, low-perplexity text, machine-generated content often has systematically lower perplexity than human writing.
    • Burstiness: This measures fluctuations in sentence length and complexity. Human writing often mixes short and long sentences with a more varied rhythm, so it tends to have higher burstiness. Machine-generated text is more uniform in sentence length and structure.

    The following example code shows how these two signals can be used as an initial detection signal. It is for illustrative purposes only and is not production-ready.

    1. import math
    2. def compute_perplexity(token_logprobs):
    3. """
    4. Compute perplexity from the log probabilities of tokens output by a language model.
    5. Lower perplexity means the text is more predictable and may be more likely to be machine-generated.
    6. """
    7. if not token_logprobs:
    8. return float('inf')
    9. avg_nll = -sum(token_logprobs) / len(token_logprobs) # Average negative log-likelihood
    10. return math.exp(avg_nll)
    11. def burstiness(sentence_lengths):
    12. """
    13. Approximate text burstiness using the coefficient of variation of sentence lengths.
    14. Human writing often has a more uneven distribution of sentence lengths and higher burstiness.
    15. """
    16. if len(sentence_lengths) < 2:
    17. return 0.0
    18. mean = sum(sentence_lengths) / len(sentence_lengths)
    19. var = sum((x - mean) ** 2 for x in sentence_lengths) / len(sentence_lengths)
    20. std = math.sqrt(var)
    21. return std / mean if mean else 0.0

    The advantages of this type of method are that it requires no training, is relatively interpretable, and transfers reasonably well across languages. The disadvantage is that it can be sensitive to rewriting, translation, or light human editing. Used alone, its discriminative power is limited.

    2.2 Methods based on supervised classification models

    Another approach treats detection as a binary or multi-class classification problem. A classifier is trained on a large number of “human text / machine text” samples. In practice, a pretrained language model is often used as the encoder, followed by a classification head. Compared with purely statistical methods, this approach can learn more abstract and more robust features, making it more tolerant to local rewriting.

    In real-world engineering, it is often necessary to distinguish three categories rather than two: purely human-written, mixed human-machine, and purely machine-generated. It is also common to provide a continuous confidence score rather than a strict binary decision.

    2.3 Methods based on watermarking and provenance signaling

    The first two approaches are post-hoc detection methods. In essence, they involve making an educated guess. A more reliable approach is to embed an identifiable signal during generation itself. This is known as text watermarking: by introducing controlled perturbations into tokenization or probability distributions during generation, a specific detector can more confidently determine whether text was produced by a given model.

    This approach can achieve higher accuracy, but it requires active cooperation from the generation side. In addition, watermarks can be weakened by copying, translation, or rewriting.

    3. Engineering challenges of detection systems

    When these principles are applied in production environments, the real difficulty lies in robustness and trustworthiness, not in the accuracy of a single model.

    • Balancing false positives and false negatives: Flagging human-original text as AI-generated can have serious consequences in academic and creative settings. Failing to detect machine-generated text weakens governance efforts. In engineering, false positives are usually controlled through threshold adjustment and “human-in-the-loop” review rather than by blindly chasing a single accuracy figure.
    • Adversarial rewriting: Once detection rules can be inferred, rewriting systems can evade them through synonym replacement, sentence restructuring, or noise insertion. Detection providers therefore need continuous adversarial training and should include known rewritten samples in training data.
    • Multilingual and domain drift: Performance can drop noticeably on non-English text, texts with dense specialized terminology, or domains not covered by training data. Robust systems need multilingual corpora and domain-specific adaptation for particular scenarios.
    • Do not blindly trust single accuracy claims: Claims of “near-perfect accuracy” often come from specific test sets. Performance in real-world distributions can vary greatly depending on sample composition. Before deployment, it is important to evaluate the detector on the target data.

    4. Technical evolution of AI text rewriting and humanization

    Rewriting technology and detection are closely linked. Legitimate uses of rewriting are broad: improving the fluency of machine translation, refining written expression, performing text simplification and accessibility adaptation, and supporting localization. Understanding the technical levels of rewriting helps us use the capability responsibly and understand why detection is difficult.

    4.1 Surface-level replacement: limits of synonym substitution

    The simplest form of rewriting is lexical replacement. It is easy to implement but lacks contextual understanding. It can damage semantics, collocations, and logical coherence, producing text that feels unnatural. Such text is also easiest to detect with statistical features.

    4.2 Context-aware rewriting

    More mature solutions are based on sequence-to-sequence models or large language models. They rewrite at the sentence or paragraph level. Instead of replacing words one by one, they first understand meaning and logic, then reorganize the expression. Key engineering capabilities include:

    • Semantic preservation: The core viewpoints, facts, and logic should not be distorted after rewriting.
    • Entity and terminology locking: Names of people, places, proper nouns, quotations, and other critical entities should not be modified incorrectly.
    • Controlled generation: Dimensions such as formality, readability, and sentence-style diversity should be adjustable.

    4.3 Application constraints and compliance boundaries

    Rewriting capability is inherently dual-use. It is legitimate when used to improve expression quality, support accessibility, or perform localization. However, if it is used to evade content moderation, fake academic originality, or manipulate search rankings, it raises integrity and compliance risks.

    From an engineering perspective, rewriting should be positioned as “quality enhancement,” not as “source disguise.” Traceability of content origin should also be preserved.

    5. Evaluation metrics and engineering recommendations

    Whether building detection or rewriting systems, evaluation should be data-driven rather than based on subjective impression.

    • Detection side: Focus on accuracy, precision, recall, F1, AUC, and most importantly the false positive rate. It is recommended to build an evaluation set that covers target languages, domains, and rewriting methods, and to run regular regression tests.
    • Rewriting side: Evaluate from three dimensions: semantic preservation (whether facts and viewpoints remain consistent), fluency, and target-attribute achievement (such as readability or keyword retention). Human review combined with automatic metrics can provide cross-validation.
    • System architecture: Text detection, rewriting, logging, and monitoring can be treated as independent natural language processing capabilities and orchestrated through APIs. For large-scale text processing, object storage can be used to hold corpora, message queues can decouple tasks, container platforms can support elastic scaling, and logging and monitoring services can provide quality and stability observation. Generic cloud capabilities, such as natural language processing, storage, compute, and monitoring service categories offered by providers like Baidu AI Cloud, can support an observable and extensible content governance pipeline.

    6. Conclusion

    AI text detection and rewriting are not the exclusive domain of any single “magical tool.” They are a set of technical capabilities with clear principles, measurable properties, and composable components. Understanding the underlying logic of perplexity, burstiness, classification models, watermarking, and context-aware rewriting is more valuable than remembering any product name.

    In practice, let evaluation data be the standard, let false-positive control be the baseline, and let compliant use be the boundary. Only then can these capabilities become a robust, trustworthy, and sustainable content governance solution.