Skip to Content
AIAI
  • Article
  • Open Access

19 August 2026

36 Pages

Detecting AI-Generated Text and Code: An Empirical Study of Cross-Generator and Cross-Domain Generalization

,
and
1
Department of Computer Science and Engineering, K L University, Vaddeswaram 522302, Andhra Pradesh, India
2
Department of Information Technology, S.R.K.R Engineering College, Bhimavaram 534204, Andhra Pradesh, India
*
Author to whom correspondence should be addressed.

Abstract

Large language models (LLMs) now generate fluent natural language and source code, creating challenges for authorship attribution, academic integrity, and software supply-chain security. Most existing detectors for AI-generated content are evaluated separately on natural language or source code, often under matched train–test conditions that can overestimate real-world reliability. We present a paired-prompt benchmark for human-versus-machine detection across English text, Python code, and mixed text–code documents. The benchmark includes 22,141 instances from HC3, CodeSearchNet, MBPP, and HumanEval across training, validation, and test partitions, plus Mix-Eval, a mixed-content set of 997 Jupyter-notebook-style samples. We evaluate RoBERTa-large for text, GraphCodeBERT and CodeBERT-base for code, a unified RoBERTa-base detector trained on both modalities, and zero-shot baselines. Fine-tuned detectors achieve near-perfect in-distribution performance, with AUROC 1.0000 ± 0.0000 and accuracy above 99.5 % . Across five instruction-tuned generator families of varying size (3.8B–7B) and architecture, with the human and problem distributions held fixed, cross-generator transfer causes negligible degradation (AUROC spread 0.0002 ; drops of at most 0.0003 ). In contrast, domain shift is the main failure mode: on MBPP+HumanEval, GraphCodeBERT drops to 0.85 ± 0.02 AUROC and CodeBERT-base to 0.67 ± 0.02 . On Mix-Eval, the unified detector outperforms a routed text–code pipeline by 21 AUROC points ( 0.96 vs. 0.75 ), largely because of router failures on mixed inputs. Training-time augmentation improves low-false-positive performance, while legacy supervised detectors show systematic class inversion on modern LLM outputs. These results show that reliable deployment requires cross-domain evaluation, mixed-content testing, and calibration beyond in-distribution accuracy.

1. Introduction

The boundary between human-authored and machine-generated content is becoming increasingly difficult to observe. High-capacity large language and code models, including most prominently GPT-3 [1], GPT-4 [2], the Claude family [3], LLaMA [4], and StarCoder [5], now produce fluent essays, explanations, dialogues, tutorials, peer-review-style commentary, and source code that often resembles human writing at the surface level, making authorship attribution a growing challenge for education, online information ecosystems, and software engineering [6]. Human judgment alone is unreliable in this setting: prior studies show that non-expert evaluators often struggle to distinguish GPT-generated text from human-authored text, and that intuitive cues for identifying AI-written language can be misleading [7,8]. At the same time, evidence of large-scale AI-assisted writing is emerging in real-world settings, including scientific peer review [9], and online news websites [10].
The same capabilities that make these systems useful also create practical risks. In education, machine-generated writing can be submitted as original work, raising concerns about academic integrity and assessment design [11,12]. In online platforms, synthetic text can reduce the cost of producing persuasive or misleading content at scale, including for automated influence operations and misinformation campaigns [13,14,15]. In software development, the rapid uptake of code-generation assistants [16,17] means that generated code may be accepted into repositories without sufficient review, complicating attribution and licensing and potentially introducing vulnerable code patterns [18,19]. These risks motivate reliable post hoc detectors that can operate when provenance metadata, watermarking, or access to the original generator are unavailable.
These concerns have motivated a growing literature on automatic detection of AI-generated content. Existing methods can be broadly grouped into three families. The first family consists of zero-shot statistical detectors, which use signals from a reference language model, such as token likelihood, rank, perplexity, or likelihood curvature, without training a task-specific classifier  [20,21,22]. The second family consists of supervised detectors, which train classifiers on labeled human- and machine-written samples, often using pre-trained transformer encoders or probability-based feature sets  [23,24,25]. The third family consists of watermarking and provenance methods, which aim to embed or record generation-time signals that can later be verified, but typically require cooperation from the model provider or content-generation pipeline [26,27]. In open-world post hoc settings, where the detector has no access to the generator, its decoding process, or reliable provenance metadata, the first two families remain the most widely applicable.
Despite this progress, much prior work has evaluated detectors either on natural-language text or on source code, rather than studying them under a unified text-and-code detection setting [21,24,25]. Moreover, recent work has shown that detector performance can degrade substantially when models are evaluated beyond their training conditions, including under unseen generators, shifted domains, and adversarial rewriting [28,29,30]. We therefore focus on three deployment-relevant failure modes. First, generator shift occurs when a detector trained on outputs from one model family is evaluated on outputs from a different model family. Second, domain shift occurs when a detector trained on one kind of content, such as open-domain answers or utility functions, is evaluated on another kind of content, such as medical answers, peer reviews, programming-contest solutions, or tutorial-style code. Third, baseline drift occurs when detectors originally developed for older generators are reused as baselines for newer instruction-tuned LLMs, even though the distribution of generated text has changed substantially [23,29]. These issues are especially important for deployment because high in-distribution accuracy does not guarantee robustness under unseen generators, unseen domains, or evolving model families. The present paper directly studies these failure modes through a paired-prompt benchmark covering English natural language and Python source code. We ask the following research questions:
  • RQ1 (Effectiveness and generator shift). Are supervised detectors accurate in-distribution, and do they survive a cross-family generator swap?
  • RQ2 (Domain shift). Do they generalize across content domains within a modality, including an external benchmark?
  • RQ3 (Mixed content and routing). On interleaved prose-and-code inputs, is explicit modality routing necessary, and which fusion rule is best?
  • RQ4 (Robustness). How robust are detectors to lightweight post-generation transformations, and does training-time augmentation help under distribution shift?
  • RQ5 (Baselines). How do legacy and zero-shot baselines (OpenAI RoBERTa, GPT-2-XL log-perplexity) fare on modern LLM outputs?
  • RQ6 (Component contributions). What do hand-engineered features and post hoc calibration/threshold tuning add, especially out-of-distribution?
Designing detectors that work across both natural language and source code is non-trivial. The two modalities differ in syntax, semantics, and statistical structure. English text may expose generation artifacts through lexical choice, stylistic regularity, repetition patterns, and language-model likelihood statistics, whereas Python code may expose artifacts through identifier naming, formatting conventions, control-flow structure, comment density, and Abstract Syntax Tree (AST) complexity. These differences raise two central questions: (i) whether a single shared encoder can capture detection signals across both modalities, or whether modality-specific encoders are necessary; and (ii) whether detectors trained under one generator, content domain, or post-generation transformation transfer reliably to others. These questions are especially important in deployment, where detectors may face unseen generators, shifted content domains, edited outputs, and evolving model families. In such settings, in-distribution accuracy alone is insufficient for assessing detector reliability.
In this paper, we study these challenges through a paired-prompt benchmark spanning English text and Python source code. The English track is based on HC3 [31], while the Python track uses CodeSearchNet [32] for training and MBPP [33]+HumanEval [34] as a contamination-suspect held-out split. We evaluate four supervised detectors and two zero-shot reference baselines. For natural language, we fine-tune a RoBERTa-large detector [35]. For Python code, we compare GraphCodeBERT [36], which incorporates data-flow information, against CodeBERT-base [37]. To test whether a single shared encoder can support both modalities, we also train a unified RoBERTa-base model [35] on the union of text and code samples. Finally, to assess transfer beyond the training distribution, we evaluate each detector along six axes: in-distribution performance, cross-generator transfer from Qwen2.5-7B-Instruct [38,39] to Mistral-7B-Instruct-v0.3 [40] for text and from Qwen2.5-Coder-7B-Instruct [41] to DeepSeek-Coder-6.7B-Instruct [42] for code, cross-domain transfer (CodeSearchNet → MBPP+HumanEval), mixed-content evaluation on Jupyter-notebook-style inputs that interleave prose and Python (Mix-Eval), lightweight post-generation transformations, and comparison against zero-shot baselines including the OpenAI RoBERTa detector [23] and a GPT-2-XL log-perplexity threshold [43]. For the transformation setting, we use same-family paraphrasing for text and Abstract Syntax Tree (AST)-based variable renaming with comment removal for code. Our contributions are as follows:
  • Paired-prompt human-vs.-machine benchmark. We construct a paired-prompt benchmark with three splits (text, code, and code2), totaling 22,141 train/validation/test instances. The benchmark is deduplicated via MinHash near-duplicate detection, length-matched between human and machine outputs, and stratified by source.
  • Controlled comparison of modality-specific and unified detectors. We evaluate four supervised detectors, RoBERTa-large, GraphCodeBERT, CodeBERT-base, and a unified RoBERTa-base model, across 29 evaluation conditions covering in-distribution performance, cross-generator transfer, cross-domain held-out transfer, mixed-content evaluation, and lightweight post-generation transformations. The unified detector matches modality-specific detectors on every same-modality condition tested.
  • Domain shift is more limiting than generator shift. Across the fine-tuned detectors, in-distribution AUROC is near-perfect, but performance drops to 0.68–0.85 AUROC on the contamination-suspect held-out split. By contrast, cross-generator transfer induces an AUROC drop of order 10 − 3 , indicating that content-domain shift is a stronger failure mode than generator-family shift in this benchmark. A controlled multi-generator evaluation across five instruction-tuned families (Appendix C) confirms that this robustness is not specific to a single model pair, while a per-generator decomposition of the SemEval transfer locates the boundaries of generalization at the human-content distribution and the instruction-tuned/base divide.
  • Data-flow structure improves out-of-domain code detection. GraphCodeBERT’s data-flow encoding provides no measurable advantage in-distribution, but yields a 17-point AUROC improvement over CodeBERT-base on the held-out code domain. This suggests that structural code representations generalize better than token-distribution features under domain shift.
  • Legacy and zero-shot baselines behave unexpectedly. A GPT-2-XL log-perplexity threshold reaches 0.87 AUROC on the contamination-suspect held-out split, outperforming every fine-tuned encoder in that setting. In contrast, the pre-2023 OpenAI RoBERTa detector achieves AUROC below 0.5 on Qwen2.5 and Mistral-7B outputs, indicating systematic class inversion rather than merely weak detection performance.
  • Modality routing is bottlenecked by router coverage on mixed-content inputs. On a held-out evaluation set of 997 Jupyter-notebook-style samples that interleave prose and Python code (Mix-Eval), the unified single-encoder achieves AUROC 0.96 , while an explicit AST-parse-based routed pipeline that combines RoBERTa-large and GraphCodeBERT through entropy-weighted fusion achieves only AUROC 0.75 . The gap is explained by router coverage: the parser fails to identify a code block in 22 % of mixed inputs, and the routed pipeline degrades to its weakest branch on those samples. When routing succeeds (the “fused” branch), AUROC reaches 0.86 —much closer to the unified ceiling. The result reframes “modality routing” as a router-quality problem rather than an architecture-choice problem.
The remainder of this paper is organized as follows. Section 2 reviews related work on text and code detection. Section 3 describes our datasets and the construction of the mixed-content evaluation set. Section 5 presents the methodology, including the feature extraction stage, the modality-specific detectors, and the fusion and calibration components. Section 6 reports the experimental setup, model training details, and Section 7 reports the evaluation protocol. Section 8 reports baselines, ablation studies, and cross-generator generalization results. Section 11 concludes this paper and outlines directions for future work.

3. Dataset Curation

We construct a benchmark that pairs human-written and machine-generated samples across two modalities (English text and Python source code) drawn from three public corpora. To enable controlled comparison, we use a paired-prompt design: each machine sample is generated from the same prompt that elicited a human reference, so distributional differences cannot be attributed to a mismatch in input distributions. Table 1 summarizes the composition.
Table 1. Composition of the unified benchmark, after all post-processing (MinHash deduplication, length matching, label balancing). Token counts are computed with the GPT-2 BPE tokenizer for text-modality subsets and the CodeBERT BPE tokenizer for code-modality subsets. The MBPP+HumanEval, Mix-Eval, X-Gen, and SemEval-2026-Task13 Python subsets are evaluation-only and are never used at training time. † highlights evaluation-only subsets. SemEval-2026-Task13 Python is an external benchmark for which we perform no curation; the others were constructed in this work.

3.1. English Text

Human-written text is sampled from the human side of the HC3 corpus [31], which spans five domains: ELI5-style explanations, open-domain QA, computer-science Wikipedia, finance, and medicine. We retain at most one human answer per question, filter by word count to the [ 22 , 298 ] window (the empirical p 10 – p 90 range), and draw 5000 samples stratified by source.
Machine-generated text is produced by prompting Qwen2.5-7B-Instruct [38,39] with the same HC3 questions (see prompt A.1) that elicited each human answer. We apply the model’s chat template with a neutral system message and sample with nucleus parameter p = 0.95 and a maximum of 384 generated tokens. To prevent the detector from latching onto a single decoding mode, each prompt is generated at one of three temperatures τ ∈ { 0.3 , 0.7 , 1.0 } , assigned round-robin across batches so each temperature appears in roughly equal proportion. Appendix E verifies that detection performance is flat across the three sampling temperatures, ruling out a temperature-artifact confound. Representative paired HC3 samples (human and Qwen2.5-7B-Instruct) are provided in Appendix B.

3.2. Python Source Code

We construct two paired code splits with complementary properties. Throughout, code denotes the curated, evaluation-only MBPP+HumanEval split and code2 the CodeSearchNet training split; the numbering reflects construction order rather than a subset relationship.
  • MBPP+HumanEval (curated).
We use the canonical human solutions from MBPP [33] (all 974 problems across the public splits) and HumanEval [34] (164 problems), yielding 1138 paired examples. Because both datasets are likely to have appeared in the pretraining corpus of the code generator, we use this split for evaluation only and never for training.
  • CodeSearchNet (open-domain).
We sample 5000 functions from the Python split of CodeSearchNet [32], filtering to entries whose first-paragraph docstring is between 6 and 40 whitespace-tokens, whose body is between 5 and 30 lines and between 30 and 300 whitespace-tokens, and whose docstring contains no URLs or fenced code blocks. We deduplicate function bodies by exact hash before sampling.
  • Generation.
For both code splits, we prompt Qwen2.5-Coder-7B-Instruct [41]. MBPP problems are presented as a natural-language statement together with one assertion as a signature hint (see prompt A.2); HumanEval problems are presented as the canonical signature plus docstring with a request to return only the function body (see prompt A.3); CodeSearchNet problems are presented as the first paragraph of the docstring (see prompt A.4). We use the same sampling configuration as for text generation ( p = 0.95 , 384 max new tokens, τ ∈ { 0.3 , 0.7 , 1.0 } ). Representative paired code samples for MBPP, HumanEval, and CodeSearchNet are also provided in Appendix B.

3.3. Length Matching and Deduplication

A common pitfall in text-detection benchmarks is that surface length alone becomes a near-perfect feature. We mitigate this by truncating each machine-generated output above the per-modality human p 95 word-count to exactly p 95 tokens, while keeping shorter outputs (subject to a minimum-length floor of three whitespace-tokens to drop degenerate generations). This preserves class balance: every split is 50 / 50 in expectation, with truncation applied only where length exceeds the human distribution.
After length matching, we apply MinHash-LSH near-duplicate detection [50,51] over the union of human and machine samples, using 5-token whitespace shingles, 64 permutations, and a Jaccard threshold of 0.85 , removing later-encountered duplicates. The remaining samples are partitioned into 80 / 10 / 10 train/validation/test splits, stratified by the (label, source) pair so that every domain and source corpus is represented in every split.

3.4. Mixed-Content Set (Mix-Eval)

To evaluate the unified framework on inputs that genuinely interleave prose and code, we construct a mixed-content evaluation set, denoted Mix-Eval, in which each sample contains both natural-language explanation and a Python snippet. Human-side samples are drawn from the corpus (codeparrot/github-jupyter-text-code-pairs) which provides ( markdown , code ) pairs extracted from public Jupyter notebooks; we filter to pairs whose markdown cell is between 30 and 200 whitespace-tokens and whose code cell is between 5 and 30 lines, and we serialize each pair as markdown>\n\ncode> to form a single mixed-content sample. Machine-side counterparts are produced on the same topic prompts using Qwen2.5-7B-Instruct for the prose section and Qwen2.5-Coder-7B-Instruct for the code section (see prompts A.5 and A.6), with the same sampling configuration as the rest of the benchmark. The two sections are concatenated in the same format as their human counterparts. Mix-Eval is used as an evaluation set only, no detector is trained on these samples, and the unified detector is compared against a modality-routed variant that splits each input via an AST-parse-based router (Markdown fences first, then contiguous indented blocks attempted with ast.parse; remaining text is prose) and applies the modality-specific detectors to each component.

3.5. External Evaluation: SemEval-2026 Task 13

For a zero-shot transfer evaluation, we additionally use the publicly available SemEval-2026 Task 13 Subtask A (binary machine-generated code detection) [52,53]. We restrict to the Python subset, yielding 7104 samples (3529 human, 3575 machine) drawn from algorithmic-programming corpora and generated by 21 distinct LLMs spanning the Llama [4], Qwen [38,39,41], Phi, Yi, Granite, CodeLlama, and Mistral [40] families. Unlike the splits in Section 3.1, Section 3.2, Section 3.3 and Section 3.4, we perform no curation on this set: no length-matching, no deduplication, and no paired-prompt construction. The set is used only at evaluation time; no detector in this paper is trained on it. We note one practical issue: the trial parquet swaps the polarity of the label column relative to the official id_to_label.json mapping (in the trial set, 0 = machine, 1 = human). We relabel to our convention (0 = human, 1 = machine) before scoring; results are reported in Section 8.4.

4. Prompt Templates

The prompts are intentionally minimal. For HC3, the system prompt is “You are a helpful assistant” and the user message is the HC3 question verbatim. For MBPP, the user message asks for a Python function that solves the problem and that passes the first assertion in the test_list, and asks the model to return only the function definition. For HumanEval, the user message provides the signature and docstring and asks for the function body only. For CodeSearchNet, the user message asks for a function that does what the first paragraph of the documentation string describes, returning the full definition with no explanation. The complete prompt templates are listed in Appendix A.
For all generated samples, we use each model’s native chat template and decode with nucleus sampling ( p = 0.95 ), a maximum of 384 new tokens, and three temperature settings τ ∈ { 0.3 , 0.7 , 1.0 } assigned round-robin across batches.

5. Methodology

We formulate human-vs.-machine detection as a binary classification problem. Given an input sample x, which may consist of English text, Python source code, or a mixed document containing both, the goal is to predict y ∈ { 0 , 1 } , where 0 denotes a human author and 1 denotes a machine author. We design a modular pipeline that separates representation learning and decision-making into clearly defined stages: (i) modality routing, (ii) feature extraction, (iii) modality-specific detection, (iv) probabilistic fusion, and (v) calibrated thresholding. An overview is given in Figure 1.
Figure 1. The detection pipeline. A rule-based modality router splits the input into text and code components via Markdown-fence extraction followed by ast.parse validation on indented runs. Each non-empty modality is processed by a dedicated feature extractor that concatenates the encoder [CLS] embedding with a vector of hand-engineered features (17-d for text, 14-d for code). Two modality-specific MLP detectors output independent probabilities p T ( x ) , p C ( x ) , which are combined either by entropy-weighted fusion or by a learnt head and then passed through Platt scaling and a validation-tuned threshold to yield the final binary prediction y ^ and the calibrated confidence p cal . The hand-engineered feature path, the probabilistic-fusion stage, and the Platt-scaling/threshold-tuning stage are evaluated as ablations (Section 8.6, Section 8.10, and Section 8.11); the headline detectors reported in the main results use the encoder+MLP path alone.

5.1. Modality Routing

The router decomposes a raw input x into a textual component x T and a code component x C . It is rule-based and does not learn parameters. The algorithm proceeds in two passes:
1.
Markdown-fence extraction. Any region matching the Markdown fenced-code-block pattern ‘‘‘...‘‘‘ (with or without a language tag) is added to x C . The remaining text is the input to pass 2.
2.
AST-parse validation on indented runs. On the residual text, we identify contiguous runs of ≥3 lines whose first non-whitespace character matches a regular expression over Python keywords and operator patterns (def, class, import, from, for, while, if, elif, else, try, except, finally, with, return, @ decorators, and assignment patterns of the form ident =...). For each candidate run, we attempt ast.parse; if parsing succeeds, the run is appended to x C and removed from x T , otherwise it remains in x T .
Tokens not assigned to a code block default to x T . For purely textual or purely code inputs, one of the components is empty, and the corresponding branch of the pipeline is skipped. The router is purely deterministic; closing the routing-coverage gap that we identify in Section 8.5 (where the router fails to detect code in 22 % of mixed inputs) by training a learned per-line classifier is left to future work.

5.2. Feature Extraction

Each non-empty modality is processed by a dedicated feature extractor that produces two complementary representations: a dense transformer embedding that captures distributional regularities, and a vector of hand-engineered features that captures interpretable surface statistics.

5.2.1. English Features

For English text, we use the pooled [CLS] representation of a fine-tuned RoBERTa-large [35] encoder as the dense representation. The hand-engineered feature vector ϕ T ( x T ) ∈ R 17 comprises the following: token-level negative log-likelihood mean/std/max and log-rank mean/max under a frozen GPT-2-XL reference [43]; burstiness defined as the coefficient-of-variation of inter-sentence NLL; type-token ratio (TTR) and the moving-average TTR with window 50 (Covington and McFall); sentence-length mean and variance; punctuation frequency; the proportion of function words from a fixed 100-word list; an n-gram repetition score (maximum 4-gram repetition rate over windows of 200 tokens); three readability indices (Flesch, Gunning Fog, Coleman–Liau); and the average token length in characters. Features are standardized by mean and standard deviation computed on the training split.

5.2.2. Python Features

For code, we use the pooled [CLS] representation of a fine-tuned GraphCodeBERT [36] encoder, which incorporates data-flow information; we additionally report a CodeBERT-base [37] variant as an ablation. The hand-engineered feature vector ϕ C ( x C ) ∈ R 14 captures the following: mean and maximum AST depth, parsed via Python’s ast module; cyclomatic complexity (McCabe) computed via radon; identifier entropy defined as the Shannon entropy of identifier-character 3-grams; comment density (comment lines/total lines) and a docstring presence indicator; indentation regularity, defined as the variance of leading-whitespace counts modulo 4; line-length variance; the ratio of single-letter to multi-letter identifiers; densities of three Python idioms (list comprehensions, with statements, f-strings); blank-line ratio; and built-in call density.

5.3. Modality-Specific Detectors

The English detector f T and the code detector f C share an architectural template: a transformer encoder, the pooled [CLS] embedding optionally concatenated with the hand-engineered feature vector, and a two-layer MLP with GELU activation and dropout ( p = 0.1 ) producing a single logit. We apply the sigmoid function to obtain a probability:
p T ( x ) = σ f T ( x ) , p C ( x ) = σ f C ( x ) .
We report two detector configurations. In the base configuration, the two-layer MLP operates on the [CLS] embedding alone and the encoder is fine-tuned end-to-end. In the handfeat configuration, the encoder is frozen and a fresh two-layer MLP is trained on the concatenation of the [CLS] embedding and the standardized hand-engineered features.
Each detector is trained on its modality’s training split using binary cross-entropy loss, the AdamW optimizer with learning rate 2 × 10 − 5 , weight decay 0.01 , batch size 16 for text and 32 for code, a linear warm-up over 6 % of training steps followed by a linear decay to zero, and bfloat16 mixed precision. We train for 3 epochs and select the checkpoint that maximizes validation AUROC.
To improve robustness, we also report an augmented configuration trained with on-the-fly input perturbations applied at probability 0.2 per training sample: for text, we apply random sentence reordering; for code, we apply Abstract-Syntax-Tree-based local-variable renaming followed by random comment insertion or removal. Augmentations preserve the label (they are applied identically to human and machine samples) and are evaluated separately in Section 8.8.

5.4. Probabilistic Fusion

When both modalities are present in x, we combine the two predictions into a single probability. We compare three fusion rules.
  • Entropy-weighted convex combination.
Let H ( p ) = − p log p − ( 1 − p ) log ( 1 − p ) be the binary entropy. We define modality-specific confidences c T = 1 − H ( p T ) and c C = 1 − H ( p C ) and let
w T = c T c T + c C + ε , w C = c C c T + c C + ε , p ent ( x ) = w T p T ( x ) + w C p C ( x ) ,
with ε = 10 − 6 . The rule is parameter-free, automatically suppresses a missing modality (its detector returns a high-entropy prediction by construction), and reduces to a simple average when both modalities are equally confident.
  • Learned fusion.
We also evaluate two parametric fusion heads. The first is a logistic-regression head over the detector logits, ( logit T , logit C ) . The second is a gradient-boosted tree (GBT) head over the detector probabilities, ( p T , p C ) , using 100 estimators with maximum depth 3. Because no separate fusion-validation split is available for the mixed-content evaluation, both learned heads are trained and reported using 5-fold stratified cross-validation on the routed mixed-content predictions. In our experiments (Section 8.6), the GBT head outperforms entropy weighting in AUROC ( 0.882 vs. 0.861 ), while logistic regression over logits is intermediate.

5.5. Calibration and Decision

Raw fused (or per-modality) probabilities can be over- or under-confident, particularly under domain shift. We apply a Platt scaling [47] step, fitting a single-parameter logistic regression
p cal = σ a · logit ( p ) + b ,
on the validation logits and labels by minimizing negative log-likelihood. The threshold τ ∈ [ 0.05 , 0.95 ] that maximizes macro-F1 on the validation split is selected as the operating point. At inference time, we apply the calibrated probability and the tuned threshold: y ^ = 1 [ p cal ( x ) > τ ] . The system additionally returns p cal as a confidence score, which is used in our experiments to compute expected calibration error. Calibration parameters and validation-tuned thresholds are reported per detector in Section 8.11.
In deployment scenarios that require low false-positive rates, the threshold can instead be selected to bound the false-positive rate at a user-specified level; we report TPR at FPR ∈ { 0.001 , 0.01 , 0.05 } throughout to facilitate this choice.

6. Experiments

6.1. Experimental Setup

All experiments are run on a workstation equipped with 2 × NVIDIA H100 NVL (95 GB) GPUs, using PyTorch and Hugging Face Transformers [54]. We train and evaluate four supervised detectors:
  • RoBERTa-large [35] (355M parameters, 1024 hidden, max length 512), the headline text detector.
  • GraphCodeBERT-base [36] (125M parameters, 768 hidden, max length 512), the headline code detector, with data-flow encoding.
  • CodeBERT-base [37] (125M parameters, 768 hidden, max length 512), a controlled comparison to GraphCodeBERT that shares vocabulary, depth, and tokenizer but lacks the data-flow-graph encoding.
  • Unified RoBERTa-base [35] (125M parameters, 768 hidden, max length 512), trained on the union of the text and code training splits to test whether a single shared encoder is sufficient for both modalities.
    Each detector is trained on a single H100 NVL; all downstream evaluations (cross-generator, mixed-content, adversarial transformations, calibration, and augmentation ablations) reuse the trained checkpoints.

6.2. Training

Both detectors are trained with binary cross-entropy on the train split, the AdamW optimizer (learning rate 2 × 10−5, weight decay 0.01 ), a linear warm-up over 6% of training steps followed by linear decay to zero, three epochs total, and bfloat16 mixed precision on 2 × NVIDIA H100 NVL (95 GB) GPUs. The training batch size is 16 for text and 32 for code. Model selection is by best-AUROC on the val split. All supervised results in this paper are reported as mean ± standard deviation over three random seeds { 42 , 123 , 7 } ; this includes the in-distribution, cross-generator, contamination-suspect held-out, mixed-content, lightweight-transformation, augmentation, hand-feature, calibration, and fusion-rule analyses, as well as the external SemEval-2026-Task 13 evaluation. The two zero-shot baselines (the OpenAI RoBERTa detector and the GPT-2-XL log-perplexity threshold) are deterministic and have no seed dependence. See Section 12.
  • What is not in the headline detector.
We deliberately keep the headline architecture minimal. The headline numbers do not apply Platt scaling, do not concatenate hand-engineered features, and are trained without augmentation, because all three components have negligible head-room when in-distribution AUROC is already ≥0.9999. We separately report Platt scaling and macro-F1-tuned thresholds (Section 8.11), hand-feature concatenation (Section 8.10), and training-time augmentation (Section 8.8) as ablations on the out-of-distribution conditions where they are expected to help, most notably the contamination-suspect MBPP+HumanEval held-out and the mixed-content Mix-Eval set, where augmentation lifts TPR@FPR = 0.01 from 0% to 49.6% on the code branch.

7. Evaluation Protocol

We report classification accuracy (Acc), macro-F1 (F1), area under the ROC curve (AUROC), expected calibration error (ECE), and true-positive rate at fixed false-positive rate (TPR@FPR) for FPR  ∈ { 0.001 , 0.01 , 0.05 } . The TPR@FPR metric is essential because deployment scenarios such as academic-integrity review and editorial moderation require operating at low false-positive rates; reporting accuracy or F1 alone hides large differences between detectors at those operating points.
ECE uses the standard binary-classification convention: confidence is max ( p , 1 − p ) over 10 equal-width bins on [ 0.5 , 1 ] . All supervised results are reported as mean ± standard deviation over three random seeds { 42 , 123 , 7 } ; the OpenAI RoBERTa detector and GPT-2-XL log-perplexity baselines are deterministic and have no seed dependence. Bootstrap 95 % confidence intervals (1000 resamples) for every per-seed metric are released in the project repository; we omit them from the tables for readability.

8. Results

8.1. In-Distribution Performance (RQ1, Part 1)

Table 2 reports performance on the held-out test splits, where the test data shares the human source corpus and the machine generator with the training split.
Table 2. In-distribution performance, mean ± standard deviation over three seeds { 42 , 123 , 7 } .
From Table 2, we make the following observations: (i) Every fine-tuned detector reaches AUROC 1.0000 ± 0.0000 over three random seeds, with accuracy above 99.5 % and TPR at FPR = 0.01 at or near 100 % . The standard deviation on AUROC is below 0.0001 across all four detectors, so the saturation is not a seed artefact: in-distribution detection is essentially solved on this benchmark. (ii) The unified RoBERTa-base matches RoBERTa-large on text ( 99.57 ± 0.06 vs. 99.63 ± 0.21 % accuracy) and GraphCodeBERT on code ( 99.60 ± 0.10 vs. 99.63 ± 0.25 % ); confidence intervals overlap completely on every metric. There is no in-distribution evidence for explicit modality routing, and the comparisons that follow (cross-domain in Section 8.3, mixed-content in Section 8.5) are required to surface architectural differences. (iii) ECE remains below 0.4 % on every split before any Platt-scaling or threshold-tuning step. Section 8.11 shows that this property does not survive distribution shift, which in turn motivates the calibration analysis in Section 8.11.

8.2. Cross-Generator Transfer (RQ1, Part 2)

We hold the detector fixed and replace the test-time generator with a different model family: Mistral-7B-Instruct-v0.3 for text and DeepSeek-Coder-6.7B-Instruct for code. Human-side samples are unchanged.
From Table 3, three observations follow: (i) Across three seeds, AUROC degrades by at most 0.0003 when the test-time generator is swapped to a different model family, RoBERTa-large 1.0000 ± 0.0000 → 0.9998 ± 0.0001 (Qwen-7B → Mistral-7B), GraphCodeBERT 1.0000 ± 0.0000 → 0.9997 ± 0.0003 (Qwen-Coder-7B → DeepSeek-Coder-6.7B). For CodeBERT-base the drop is statistically zero ( 1.0000 ± 0.0000 → 1.0000 ± 0.0000 ). The confidence intervals on the matched-condition and cross-generator AUROCs overlap completely, so cross-generator generalization is not the limiting factor on this benchmark. (ii) Both modality-specific encoders (RoBERTa-large, GraphCodeBERT, CodeBERT-base) and the unified RoBERTa-base behave identically under a generator swap. Calibration also transfers: ECE stays at 0.40 – 0.94 % across detectors, comparable to the in-distribution values in Table 2. The robustness is therefore a property of the data, not of any specific encoder. (iii) A plausible explanation is that paired-prompt generation produces a “polished tutorial” style, structured numbered lists, def/comment patterns, response openers, that is shared across modern instruction-tuned LLMs (Qwen, Mistral, DeepSeek). The detectors latch onto this style rather than onto generator-specific fingerprints, so swapping generators within the same instruction-tuned regime leaves the discriminative signal intact. We return to this interpretation, and to why the same robustness disappears under content-domain shift (Section 8.3), in Section 10.
Table 3. Cross-generator transfer, mean ± standard deviation over three seeds. Each detector is trained on Qwen-generated machine samples; test machine samples come from a different model family.

8.3. Cross-Domain Transfer (RQ2, Part 1)

We evaluate every code detector, trained on CodeSearchNet utility functions, on the held-out MBPP+HumanEval set, which contains algorithmic-puzzle solutions and is contamination-suspect in the generator’s pre-training corpus. The held-out set is never used at training time. Table 4 reports performance on this cross-domain evaluation.
Table 4. Cross-domain transfer to MBPP+HumanEval (n = 228), mean ± std over three seeds. TPR@FPR = 0.01 is highly seed-sensitive on this split: GraphCodeBERT’s std reaches 15 pp.
From Table 4, we make the following observations: (i) Both fine-tuned code detectors collapse on the held-out domain. GraphCodeBERT’s AUROC drops from 1.0000 ± 0.0000 in-distribution to 0.8496 ± 0.0187 on MBPP+HumanEval, and CodeBERT-base’s drops from 1.0000 ± 0.0000 to 0.6704 ± 0.0208 . Default-threshold accuracy collapses to ∼51% for both detectors and ECE exceeds 48 % . The standard deviation on the held-out AUROC is approximately two orders of magnitude larger than on any in-distribution split, but the magnitude of the collapse (≥15 AUROC points for both detectors) is far larger than the seed-induced variability, so the failure mode is robust rather than fragile. (ii) The + 18 -point AUROC gap between GraphCodeBERT ( 0.8496 ± 0.0187 ) and CodeBERT-base ( 0.6704 ± 0.0208 ) is roughly 6 × its joint standard error. This advantage is invisible in-distribution, where both encoders sit at AUROC 1.0 ± 0.0 . Structural code representations generalize better than pure-token encodings under this domain shift; we revisit this claim under a second OOD distribution in Section 8.4, where the ranking flips. (iii) GPT-2-XL log-perplexity reaches AUROC 0.8666 , within the seed-noise band of GraphCodeBERT’s 0.8496 ± 0.0187 . The frozen reference LM is therefore statistically equivalent to our best fine-tuned encoder on this distribution shift, not categorically better; the more honest reading is that under domain shift, fine-tuning to a single code distribution does not gain over a held-fixed reference model. (iv) ECE on this split sits between 44.3 % (after Platt) and 50.2 % (raw) for every supervised detector. The TPR at the strict FPR = 0.01 operating point is also seed-sensitive in the extreme: GraphCodeBERT’s TPR@FPR = 0.01 has mean 10.3 % but standard deviation 14.9 percentage points across seeds, while CodeBERT-base’s is 0.0 ± 0.0 % . Section 8.8 shows that training-time augmentation recovers usable low-FPR performance ( 0 % → 49.6 % ) where post hoc calibration alone cannot.

8.4. External Benchmark: SemEval-2026 Task 13 (RQ2, Part 2)

We additionally evaluate the code branch on the public trial sets of SemEval-2026 Task 13 [52,53], restricted to the Python subset in every subtask. Our detectors are evaluated zero-shot, they have neither been trained on this corpus nor on its content domain (algorithmic Python sources such as Leetcode-style problems). For Subtasks B and C, we collapse the multi-class labels to binary by treating all non-human classes (LLM family in Subtask B; machine, hybrid, and adversarial in Subtask C) as the positive class. We relabel to our convention (0 = human, 1 = machine) before scoring; trial-parquet label polarity is documented in Section 3.5.
From Table 5, we make the following observations: (i) Across Subtasks A, B, and C, AUROC over three seeds stays in [ 0.64 , 0.87 ] , substantially above chance, while accuracy at the default 0.5 threshold collapses to 27– 67 % and ECE explodes to 31– 71 % . The threshold-and-calibration collapse pattern we documented on MBPP+HumanEval (Section 8.3) reproduces on three independent external evaluations. (ii) On MBPP+HumanEval GraphCodeBERT wins by 17.9 AUROC points ( 0.8496 ± 0.0187 vs. 0.6704 ± 0.0208 ). On every SemEval Python subtask the ranking inverts: CodeBERT-base wins by + 15.2 points on Subtask A ( 0.8693 ± 0.0141 vs. 0.7172 ± 0.0579 ), + 7.8 on Subtask B ( 0.7224 ± 0.0118 vs. 0.6446 ± 0.0354 ), and + 4.9 on Subtask C ( 0.7053 ± 0.0152 vs. 0.6568 ± 0.0382 ). All four gaps are several times their joint seed-std, so the inversion is statistically robust rather than seed-driven. The data-flow advantage of GraphCodeBERT is therefore specific to the MBPP+HumanEval style (short, single-function, algorithmic-puzzle solutions) and does not transfer to the broader algorithmic-Python distribution sampled by SemEval-2026 Task 13. (iii) On Subtask C, GraphCodeBERT flags pure-machine samples at 96.85 ± 1.16 % , hybrid samples at 93.59 ± 1.58 % , and adversarial (RLHF-mimicking) samples at 92.92 ± 3.73 % . The pure-machine-to-adversarial gap is 3.9 percentage points across three seeds. The threats anticipated to erode detection most aggressively, Subtask C’s hybrid and adversarial classes, erode it least. (iv) The dominant failure mode is over-confident false positives on human algorithmic Python. GraphCodeBERT classifies 83.35 ± 7.72 % of Subtask C human samples as machine, and CodeBERT-base classifies 72.75 ± 12.02 % . Both false-positive rates are highly seed-sensitive ( σ = 8 –12 percentage points), the largest seed-induced variability in the paper outside the MBPP+HumanEval TPR@FPR = 0.01 point estimate. This is precisely the threshold-collapse mechanism from Section 8.3: short, clean, idiomatic human Python sits inside the detector’s machine class because the detector learned a “polished tutorial” style boundary that does not transfer. Threshold tuning on a domain-matched validation split (Section 8.11) is therefore the operational lever; the discrimination signal needed by the threshold is already present (AUROC ≥ 0.64 across all SemEval subtasks).
Table 5. Zero-shot transfer to SemEval-2026 Task 13, Python subsets. All numbers are mean ± standard deviation over three random seeds { 42 , 123 , 7 } . Trial-parquet label polarity for Task A is documented in Section 3.5; we relabel to our convention (0 = human, 1 = machine) before scoring. Tasks B and C are binary-collapsed (any non-human class → machine).
Table 6 reports the corresponding per-class mean detector probabilities and prediction rates for Subtask C.
Table 6. Per-class mean detector probability p ( machine ) on the Subtask C Python subset, averaged over three seeds. “Pred-as-machine” is the fraction of samples in the class that the detector classifies as machine at the default 0.5 threshold.

8.5. Mixed-Content Generalization (RQ3, Part 1)

We evaluate every method on Mix-Eval: 997 paired samples (497 human + 500 machine) where each input interleaves a Markdown explanation with a Python snippet. Human-side samples are real Jupyter (markdown, code) cell pairs; machine-side counterparts are generated by Qwen2.5-7B (prose) and Qwen2.5-Coder-7B (code) on the same topic. “Naive” detectors apply the modality-specific encoder to the full sample as plain text. “Routed” applies the AST-parse-based router and combines per-modality predictions via entropy-weighted fusion.
From Table 7, we make the following observations: (i) Every method degrades on Mix-Eval relative to its in-distribution numbers. The best fine-tuned AUROC is 0.94 , down from ∼1.0, and accuracy at the default threshold falls below 70 % for every supervised method. (ii) The fused branch (when both modalities are detected) reaches AUROC 0.8612 ± 0.0073 across seeds, much closer to the unified ceiling. The text-only branch (router missed the code) achieves only 0.6668 ± 0.0589 , and its seed-std of nearly 6 AUROC points is the largest seed-induced variability in the paper. The routed pipeline’s overall ceiling is therefore set both by its weakest branch and by that branch’s seed instability. (iii) The cause is router coverage: the AST-parse heuristic does not detect a code block in 216 of 997 samples ( 22 % ). On those samples, the routed pipeline degrades to RoBERTa-large alone, which has never seen training samples that contain Python code (text-only branch AUROC 0.62 ). When routing succeeds, the fused branch reaches AUROC 0.86 , much closer to the unified ceiling. (iv) GPT-2-XL log-perplexity has the best calibration on this set (ECE 7.5 % ) despite low AUROC, illustrating that frozen reference language models produce miscalibration-resistant scores even when discrimination is weak. (v) Pre-2023 supervised detectors remain useless on mixed content (OpenAI RoBERTa: AUROC 0.59 , barely above chance).
Table 7. Mixed-content evaluation (Mix-Eval, n = 997). Supervised detectors and the routed pipeline are reported as mean ± standard deviation over three random seeds { 42 , 123 , 7 } . The GPT-2-XL log-perplexity and OpenAI RoBERTa baselines are deterministic and have no seed dependence.
Figure 2 plots the ROC curves for these conditions; the held-out and Mix-Eval curves are visibly the only ones that bow away from the top-left corner.
Figure 2. ROC curves across modalities and test conditions. Left: text detector. Middle: code detector across in-domain, cross-generator, domain-held-out, and Mix-Eval splits. Right: augmentation effect on out-of-distribution conditions. The held-out (red dashed) and Mix-Eval (purple) curves are the only conditions where AUROC drops noticeably.

8.6. Fusion-Rule Comparison (RQ3, Part 2)

The Mix-Eval result motivates the question: when both modalities are present, what fusion rule should we use? We compare the parameter-free entropy-weighted rule (Equation (2)) against two learnt fusion heads on the routed Mix-Eval predictions, restricted to the 781 samples for which the router identified both a text and a code component (the fused branch). Because Mix-Eval has no separate fusion-validation split, the learnt heads are trained and evaluated via 5-fold stratified cross-validation.
From Table 8, we make the following observations: (i) A learnt fusion head outperforms parameter-free entropy-weighting on Mix-Eval across all three seeds. The gradient-boosted-trees variant achieves AUROC 0.8817 ± 0.0071 versus 0.8610 ± 0.0072 for entropy-weighting, a + 0.021 AUROC gap that holds individually on every seed. (ii) The naive logistic regression over probabilities achieves higher accuracy but lower AUROC than entropy-weighting, suggesting a non-monotonic calibration in the per-modality probabilities that a tree-based head models better. (iii) Entropy-weighting remains useful in deployment when no fusion-validation data is available, since it requires no fitting. When fusion-validation data is available, the gradient-boosted-trees head gives ∼+10 percentage points of accuracy at substantially lower seed variance (Acc std 0.13 vs. 6.77 ). The learnt head’s robustness to underlying-detector seed variability is, in our experiments, a more compelling argument for it than its raw accuracy gain.
Table 8. Fusion rules on the Mix-Eval fused branch (n = 781), mean ± standard deviation over three random seeds { 42 , 123 , 7 } . Entropy-weighted is parameter-free; learnt heads are evaluated via 5-fold stratified cross-validation on each seed’s routed predictions.

8.7. Robustness to Lightweight Transformations (RQ4, Part 1)

We apply two lightweight attacks to the machine half of the test sets. For text, we use Qwen2.5-7B-Instruct as a same-family paraphraser. For code, we apply AST-based local-variable renaming ( x → v 1 , y → v 2 , …) followed by comment stripping. Human-side samples are unchanged.
From Table 9, we make the following observations: (i) Both attacks leave detection performance essentially unchanged. AUROC, accuracy, and TPR@FPR all match the no-attack in-distribution baseline. (ii) Two caveats are worth declaring up front. First, the text paraphraser is the same model family as the generator, which preserves the stylistic regularities the detector relies on; a cross-family paraphraser (e.g., DIPPER, Pegasus) is the standard stronger attack. Second, AST-rename with comment stripping preserves AST structure and identifier-distribution-conditional features, so structural-feature detectors are insensitive to it by design. (iii) In Section 8.8, we show that on-the-fly training-time augmentation provides additional robustness gains on the out-of-distribution conditions (MBPP+HumanEval held-out and Mix-Eval), which test-time attacks alone do not surface.
Table 9. Robustness to lightweight post-generation transformations (headline detectors, no augmentation training).

8.8. Training-Time Augmentation (RQ4, Part 2)

We retrain each headline detector with on-the-fly input augmentation at probability p aug = 0.2 . For text, augmentation is random sentence reordering. For code, AST-based local-variable renaming followed by random comment insertion or removal. Augmentation is applied identically to human and machine samples and preserves the label.
From Table 10, we make the following observations: (i) Across three seeds the augmented detectors tie or improve AUROC on every same-modality condition, drop ECE on every such condition (e.g., RoBERTa xgen ECE 0.94 → 0.67 % ; GraphCodeBERT xgen ECE 0.40 → 0.21 % ), and reach TPR@FPR = 0.01 of 100 % on every in-distribution and cross-generator condition for both detectors. The single exception is GraphCodeBERT on the MBPP+HumanEval held-out, where the AUROC mean dips slightly ( 0.8496 ± 0.0187 → 0.8299 ± 0.0481 ) while the TPR@FPR = 0.01 mean roughly doubles (see (ii)); the AUROC confidence intervals overlap, so the effect on ranking is statistically zero. (ii) GraphCodeBERT’s mean TPR@FPR = 0.01 improves from 10.3 ± 14.9 % to 24.8 ± 22.6 % , more than doubling on average. The metric is the most seed-sensitive number in the paper outside the routed text-only branch, standard deviations on both conditions exceed 15 percentage points, so we report it with explicit ± std rather than as a single-point estimate. Augmentation does not repair the calibration collapse on this split (ECE remains ∼ 48 % in both conditions); it repairs only the low-FPR usability of the detector under domain shift, and even that gain is large in expectation but variable across seeds. (iii) RoBERTa-aug improves AUROC 0.7906 ± 0.0484 → 0.8124 ± 0.0208 and TPR@FPR = 0.01 0.87 ± 0.50 % → 1.80 ± 1.71 % , with no material ECE change ( 37.17 % → 41.58 % , within seed noise). GraphCodeBERT-aug shows the same AUROC improvement ( 0.7917 ± 0.0230 → 0.8234 ± 0.0078 , with an order-of-magnitude lower std), a modest ECE reduction ( 41.05 % → 39.06 % ), and a much larger TPR@FPR = 0.01 gain ( 0.33 ± 0.58 % → 4.80 ± 3.17 % ).
Table 10. Augmentation ablation, mean ± standard deviation over three random seeds { 42 , 123 , 7 } . Encoder, optimizer, and all other hyperparameters are unchanged; only the augmentation policy differs.
Overall, Augmentation is therefore a partial substitute for in-domain mixed-content training data, particularly on the code branch, where all three of AUROC, ECE, and TPR@FPR = 0.01 improve. On the text branch, the AUROC and TPR gains hold, while ECE is statistically unchanged.

8.9. Comparison with Baselines (RQ5)

We compare against two zero-shot baselines on text test sets: the OpenAI RoBERTa detector [23] (a pre-2023 supervised detector originally fine-tuned on GPT-2) and a GPT-2-XL log-perplexity threshold [43].
From Table 11, we make the following observations: (i) The OpenAI RoBERTa detector achieves AUROC of 0.298 on Qwen-7B outputs and 0.069 on Mistral-7B outputs, both well below the chance level of 0.5 . This pattern indicates systematic class inversion rather than random performance: higher machine-likelihood scores are assigned to human samples than to machine samples, and 1 − AUROC would recover most of the discriminative signal. Reporting AUROC alongside accuracy is therefore essential to distinguish inversion (correctable by flipping the predicted labels) from genuine inability to discriminate, which a 34.7 % or 15.5 % accuracy figure alone would conflate. (ii) The GPT-2-XL log-perplexity baseline reaches AUROC 0.984 on Qwen outputs and 0.995 on Mistral outputs, substantially higher than the OpenAI detector but ∼ 0.02 below the fine-tuned detector. Its default-threshold accuracy is lower ( 73.2 % on Qwen, 82.2 % on Mistral) because a fixed perplexity threshold does not transfer cleanly across the two generator distributions; the AUROC–accuracy gap quantifies the threshold-transfer cost of using a zero-shot signal at deployment. (iii) Section 8.3 re-examines GPT-2-XL log-perplexity under content-domain shift, where it reaches AUROC 0.8666 on the MBPP+HumanEval held-out and exceeds the AUROC of every supervised detector evaluated on that split. The frozen reference language model is consequently less accurate at the default threshold but more domain-transferable in ranking; the supervised detectors exhibit the opposite trade-off, retaining tight calibration on matched distributions while collapsing under content-domain shift. (iv) The fine-tuned RoBERTa-large detector exceeds both baselines on every reported metric. AUROC improves by approximately 0.7 over the OpenAI detector and by ∼0.016 over the GPT-2-XL threshold, while default-threshold accuracy reaches 99.63 % and 99.03 % on the two test sets compared with 34.70 % / 15.50 % and 73.20 % / 82.20 % for the respective baselines.
Table 11. Comparison with zero-shot baselines on text test sets. “Ours” is the headline RoBERTa-large detector fine-tuned on text_train.

8.10. Component-Contribution Ablations: Hand-Engineered Features (RQ6, Part 1)

We compare a head trained on the [CLS] embedding alone (cls_only) against a head trained on [ CLS ∥ ϕ ( x ) ] (cls+hand), where ϕ ( x ) is the standardized hand-engineered feature vector from Section 5.2 (17-d for text, 14-d for code). The encoder is frozen for both configurations; only the two-layer MLP head is trained.
From Table 12, we make the following observations: (i) Text hand features yield a small but consistent improvement ( + 0.001 AUROC across every text test, + 0.01 on Mix-Eval). The features are anchored on a frozen reference language model (GPT-2-XL perplexity, log-rank, burstiness) plus distribution-invariant style statistics (MATTR, readability indices), which appear to transfer. (ii) Code hand features do not help in distribution and actively hurt on the contamination-suspect MBPP+HumanEval held-out (AUROC 0.86 → 0.80 ). The hand-engineered code features (AST depth, comment density, idiom counts) overfit to the CodeSearchNet utility-function distribution and fail to generalize to algorithmic puzzles. (iii) The gap suggests that a more transferable code-feature design, one anchored on a frozen reference code language model rather than on training-domain syntactic counts, is an open problem.
Table 12. Hand-feature ablation, mean ± standard deviation over three random seeds { 42 , 123 , 7 } . Both rows for each test set share a frozen encoder; only the head input differs.

8.11. Calibration and Threshold Tuning (RQ6, Part 2)

For each detector, we fit a single-parameter Platt scaling step (Equation (3)) on validation logits and labels, and select the threshold τ ∈ [ 0.05 , 0.95 ] that maximizes macro-F1 on the validation split. Both fitting steps use only validation data; test data is unseen.
From Table 13, we make the following observations: (i) Platt scaling reduces but does not repair calibration under heavy distribution shift. On the MBPP+HumanEval held-out, Platt scaling lowers GraphCodeBERT’s ECE from 48.54 ± 1.65 % to 44.78 ± 0.66 % —a statistically robust 3.8 -point reduction that is nonetheless small relative to the magnitude of the calibration collapse. ECE on Mix-Eval for the same detector drops from 41.05 ± 10.21 % to 26.36 ± 9.31 % under Platt scaling; the larger improvement on Mix-Eval reflects a less severe distribution shift relative to MBPP+HumanEval, not a property of the scaling step itself. (ii) Threshold tuning on a domain-matched validation split is a substantially larger lever than Platt scaling when the test distribution shifts. Replacing the default 0.5 threshold with the macro-F1-maximising τ improves GraphCodeBERT’s accuracy on Mix-Eval from 56.34 ± 7.43 % to 70.61 ± 5.69 % and on MBPP+HumanEval from 50.73 ± 1.34 % to 54.82 ± 0.44 % . The intervention requires no retraining and no modification of the encoder; only a single threshold parameter is fitted on validation data. (iii) In-distribution detectors do not benefit from either intervention. ECE is below 0.5 % before any post hoc step ( 0.36 ± 0.21 % for RoBERTa-large on the text test split; 0.36 ± 0.19 % for GraphCodeBERT on the code2 test split), and threshold tuning leaves in-distribution accuracy essentially unchanged ( 99.63 → 99.63 % for RoBERTa-large; 99.63 → 99.83 % for GraphCodeBERT). The calibration machinery is consequential only when distribution shift breaks the score distribution; under matched conditions, the raw logits are already well-calibrated and the default threshold is already near-optimal.
Table 13. Effect of Platt scaling and macro-F1 threshold tuning, mean ± standard deviation over three random seeds { 42 , 123 , 7 } . “raw” columns: raw σ ( logit ) at threshold 0.5 ; “+Platt” columns: fitted Platt scaling; “tuned acc” uses p cal at the val-tuned τ .
Figure 3 shows the corresponding reliability diagrams, near-diagonal in-distribution, severely bowed on the contamination-suspect held-out and Mix-Eval splits, and Figure 4 shows the underlying score distributions that explain the collapse.
Figure 3. Reliability diagrams. Bars: per-bin accuracy. Red line: per-bin mean confidence. Dotted: perfect calibration. The detector is well calibrated in-distribution (left, ECE 0.6 % ), badly miscalibrated on the contamination-suspect held-out (centre, ECE 48.4 % ), and on Mix-Eval (right, ECE 29.3 % ).
Figure 4. Score distributions p ( machine ) . Human samples are shown in green, machine in red. In-distribution scores cluster tightly at the extremes; on the held-out and Mix-Eval splits, the two distributions overlap heavily near the threshold, explaining the ECE collapse and the threshold-tuning gains in Section 8.11.

9. Qualitative Analysis

What Does the Detector Latch onto?

Table 14 shows a curated subset of representative detector outputs; a larger set spanning every test condition, including true/false positives and negatives on the contamination-suspect held-out and Mix-Eval splits, is provided in Appendix B. Confidently detected machine samples consistently exhibit polished-tutorial markers: explicit Markdown structure (### headings, numbered lists), step-by-step inline comments in code, and an explanatory tone. Confidently identified human samples on HC3 show informal Reddit-style hedging (“plenty of room”, citation links, hyphenated qualifications); on CodeSearchNet, they show idiosyncratic docstring conventions (:param/:returns) and dense business-logic implementations rather than clean toy examples. The most diagnostic failures are the false positives: clean encyclopedic human prose and short idiomatic human Python both look “too neat” and trip the machine class. This is consistent with our broader finding that fine-tuned detectors classify on style polish rather than on generation provenance directly, and explains why training-time augmentation, which forces the encoder to ignore some of the polish markers, is the most effective intervention we have for transfer to out-of-distribution domains (Section 8.8).
Table 14. Representative detector outputs across modalities and test conditions. TP = correctly detected machine-generated; TN = correctly identified human; FP = human misclassified as machine; FN = machine misclassified as human. Each row shows the detector probability p ( machine ) . The extended set is provided in Appendix B.

10. Discussion

Across our evaluation axes, a consistent picture emerges: detectors that appear nearly perfect in-distribution can fail in very different ways once the test setting changes. Generator-family changes have little measurable effect in our benchmark, whereas content-domain shifts and mixed-content inputs expose substantial weaknesses. Importantly, these failures are not only failures of discrimination. In several settings, AUROC partially survives while calibration and threshold-based usability collapse. Thus, the central lesson is that AI-generated-content detection should not be evaluated only by in-distribution accuracy or AUROC; it must also be tested under domain shift, mixed-modality inputs, low-false-positive operating points, and calibration-sensitive deployment conditions.
  • Domain shift is more limiting than generator shift.
The strongest empirical pattern is that changing the test-time generator family has little effect, while changing the content domain substantially degrades performance. Detectors trained on Qwen-generated samples transfer almost unchanged to Mistral or DeepSeek-Coder outputs, suggesting that modern instruction-tuned models share detectable stylistic regularities under the paired-prompt setup. By contrast, transferring from CodeSearchNet utility functions to MBPP+HumanEval algorithmic problems causes large drops for every fine-tuned code detector. This indicates that the detector is not simply learning a universal “machine-code” signature; it is also learning domain-specific regularities of the training corpus. For benchmark design, this means that generator-held-out evaluation is necessary but not sufficient. A single domain-held-out split can reveal failure modes that cross-generator tests alone would miss.
  • The discriminative signal is instruction-tuned surface style.
Three revision-stage analyses converge on this interpretation. First, a format-only classifier restricted to shallow surface features (length, whitespace, punctuation, docstring/markdown markers) already separates the in-distribution classes at AUROC 0.994 (code)/ 0.998 (text), and an identical surface canonicalization applied to both classes drops the unchanged code detector from 1.0000 to 0.8151 ± 0.069 (Appendix D), so roughly a fifth of the in-distribution code margin is carried by surface formatting, while substantial non-surface signal remains. Second, per-generator decomposition of the SemEval transfer (Appendix C) shows the detector transfers across instruction-tuned families (AUROC 0.806 ± 0.047 ) but degrades sharply on base/pretrained models ( 0.561 ± 0.049 ), with model size uncorrelated with detectability; base-model output lacks the instruction-tuned formatting polish. Third, 84 % of SemEval’s curated, competition-style human code is flagged as machine at the default threshold, clean human code falls on the machine side of a style-based boundary. Notably, the post-canonicalization AUROC ( 0.815 ) closely matches the cross-domain held-out AUROC ( 0.850 ): both estimate the signal that remains once surface cues stop being informative. The detector should therefore be understood as identifying format-and-style-typical instruction-tuned output rather than generation provenance per se, consistent with the qualitative analysis of Section 8.
  • Structural code representations matter under domain shift.
The comparison between CodeBERT and GraphCodeBERT shows that architectural differences may be invisible in-distribution but important out of domain. Both encoders perform similarly on matched and cross-generator test sets, where performance is already near ceiling. However, on the held-out MBPP+HumanEval split, GraphCodeBERT substantially outperforms CodeBERT. This suggests that data-flow-aware representations provide signals that transfer better than purely token-distributional cues when the code domain changes. The result also cautions against choosing code detectors based only on in-distribution performance: when AUROC is already saturated, architectural advantages may only appear under more realistic deployment stress tests.
  • Adversarial detection is not the bottleneck; threshold is.
On SemEval-2026 Task C Python (Table 6), GraphCodeBERT flags pure-machine samples as machine 95.8 % of the time, hybrid samples (partially completed by LLMs) 92.2 % , and adversarial samples (RLHF-tuned to mimic humans) 88.9 % . The adversarial threat reduces the flagging rate by only ∼7 percentage points relative to pure machine—much smaller than the 74.6 % false-positive rate the same detector exhibits on human algorithmic Python in the same evaluation. Across our entire study the dominant deployment risk is therefore not adversarial evasion but threshold mis-transfer under content-domain shift; the same discrimination signal is present, but the operating point is wrong. This reinforces the Section 8.11 finding that threshold tuning, not architecture, is the practical lever.
  • Mixed-content detection is limited by routing coverage.
A natural expectation is that a routed pipeline with separate text and code detectors should outperform a single shared encoder on mixed inputs. Our results complicate this expectation. On Mix-Eval, the unified RoBERTa-base detector outperforms the routed pipeline, largely because the router fails to identify code regions in a non-trivial fraction of mixed documents. When routing succeeds, fusion performs much better; when routing fails, the system effectively falls back to a text-only detector that was not trained on code-containing inputs. This suggests that mixed-content detection is not only a question of detector architecture, but also a router-quality problem. A learned line- or span-level modality router is therefore a natural next step.
  • Frozen reference-model scores can be surprisingly robust.
Although fine-tuned detectors dominate zero-shot baselines in most matched settings, the GPT-2-XL log-perplexity baseline remains competitive under the strongest domain shift. On the contamination-suspect held-out split, it outperforms the fine-tuned encoders in AUROC. One interpretation is that fine-tuning improves sensitivity to the training distribution, but also increases dependence on domain-specific artifacts. A frozen reference language model, by contrast, provides a more generic likelihood signal that may transfer better when the test domain changes. This does not make perplexity a stronger detector overall, but it shows that simple reference LM baselines remain important sanity checks for deployment-oriented evaluation. Two properties of the held-out split make the frozen reference particularly competitive there. First, fine-tuning to CodeSearchNet utility functions ties the learned decision boundary to domain-specific artifacts: docstring conventions, identifier styles, and function length that do not transfer to short algorithmic-puzzle solutions, whereas the frozen model’s likelihood signal is independent of any training distribution. Second, short, single-function algorithmic solutions exhibit strong statistical regularities under a reference LM (constrained vocabulary, canonical implementations), which favors likelihood-based ranking in exactly this domain. This reading is consistent with the per-class analysis of Table 6: the fine-tuned detectors’ dominant failure on this distribution is over-confident false positives on clean idiomatic human code, a domain-transfer failure of the learned decision boundary, not of the underlying discriminative signal.
  • Calibration and low-FPR usability require separate treatment.
Our results also separate ranking performance from deployable decision quality. In-distribution ECE is below 1% for the fine-tuned detectors, but under domain shift and mixed-content evaluation, ECE rises sharply. In these settings, a detector can retain reasonable AUROC while becoming unreliable at the default threshold. Platt scaling helps in some cases, but threshold tuning on a domain-matched validation set is often more directly useful for improving accuracy and low-FPR behavior. This is especially important for applications such as academic-integrity review, where false positives are costly and a detector must be operated at conservative thresholds.
  • Augmentation improves robustness more than post hoc repair.
Among the interventions we evaluate, training-time augmentation provides the clearest improvement under deployment-relevant shifts. Code augmentation through variable renaming and comment insertion/removal substantially improves TPR at low FPR on the held-out code domain while preserving in-distribution performance. Text augmentation produces analogous gains for the language branch. This suggests that robustness is better encouraged during training than repaired after the fact. By forcing the model to ignore superficial perturbations, augmentation appears to encourage reliance on signals that transfer better across domains.
  • Hand-engineered features are useful only when they transfer.
The hand-feature results are modality-asymmetric. For text, reference-LM and stylometric features provide small but consistent improvements, suggesting that likelihood, repetition, and readability statistics capture signals that are not fully absorbed by the transformer embedding. For code, however, simple syntactic and AST-count features do not reliably improve out-of-domain performance and can even hurt. This suggests that raw syntactic counts may overfit to the training domain. A more promising direction is to design code features that are anchored in a frozen reference code model, analogous to perplexity and log-rank features for natural language.
  • Practical implications.
For practitioners, the main recommendation is to treat in-distribution performance as only a first diagnostic. A detector that performs well on matched data should still be evaluated on at least one content-domain held-out split, at least one generator-held-out split, and at low false-positive operating points. Training-time augmentation should be used by default when robustness to paraphrasing or code rewriting is expected. For mixed text–code inputs, router coverage should be measured explicitly, because routing failures can dominate fusion performance. Finally, calibration and threshold selection should be performed on data that matches the intended deployment domain whenever possible. Together, these steps provide a more realistic estimate of detector reliability than headline in-distribution accuracy alone.

11. Conclusions and Future Work

We have presented a paired-prompt benchmark and an empirical study of text-level AI-content detection across English natural language and Python source code. Modality-specific transformer detectors (RoBERTa-large for text, GraphCodeBERT for code) achieve near-perfect in-distribution performance and generalize almost without loss to a different generator family at test time—contradicting the common worry that supervised detectors overfit narrow model-specific surface cues. The same detectors, however, collapse on a domain-held-out, contamination-suspect set, losing 49 accuracy points and an order of magnitude in calibration error. A widely cited zero-shot baseline (the OpenAI RoBERTa detector) scores below random AUROC on outputs from current LLMs, while a GPT-2-XL log-perplexity threshold remains a strong if blunt baseline. We argue that benchmarks for AI-content detection should explicitly include domain-held-out and contamination-suspect splits, that zero-shot legacy detectors should be reported with AUROC alongside accuracy to avoid misleading “bad detector” interpretations, and that robustness claims should be qualified by the family relationship between attacker and generator.

Future Work

The natural next steps are as follows: (i) multi-family training and evaluation; (ii) stronger attacks, DIPPER cross-family paraphrase, and structural code obfuscation; (iii) Layer-2 ablation that concatenates hand-engineered linguistic and structural features into the MLP head and quantifies their value on out-of-distribution sets; (iv) Platt scaling on a domain-matched validation split, with reliability diagrams reported at deployment-relevant operating points; (v) probabilistic fusion of the text and code detectors for mixed-content inputs such as Jupyter notebooks and technical-tutorial documents; and (vi) replacing the rule-based modality router with a learned per-line or per-token modality classifier, closing the 22% routing-coverage gap identified in Section 8.5 that currently bottlenecks the routed pipeline on mixed-content inputs.

12. Limitations

  • Single generator family per modality for the main training runs. Cross-generator robustness was evaluated on a single alternative family per modality (Mistral for text, DeepSeek-Coder for code). A multi-family training distribution and a multi-family evaluation matrix is the natural next step.
  • Limited code training distribution. Real-world Python is considerably more diverse than CodeSearchNet utility functions. Notebook code, scripts, tests, and competitive-programming submissions are not represented in training, and the code-set collapse suggests these would all be out-of-distribution.
  • No hand-engineered features in the headline numbers. With AUROC already ≥0.9999 in-distribution, there is no head-room for hand features to demonstrate value at the headline operating point. Their natural place is on out-of-distribution and domain-shift evaluations, where the present results suggest they would help; the hand-feature extractors are implemented and ready to be wired into the MLP head as [ CLS ⊕ scaled hand features ] in follow-up work.
  • No fusion across modalities. The architecture is intentionally minimal: two independent modality-specific detectors. Probabilistic fusion of the two detectors on mixed text-and-code inputs (e.g., Jupyter notebooks, Stack-Overflow-style answers) is a natural extension and is discussed in Section 11.
  • Boundaries of generator generalization. Generalization is bounded in two ways our controlled setting does not probe. (i) Under human-distribution shift, e.g., the SemEval-2026 transfer, whose human code is curated, competition-style, overall AUROC falls to 0.72 because human code is itself flagged as machine (Appendix C). (ii) The detector transfers across instruction-tuned generators but degrades sharply on base/pre-trained models (AUROC 0.81 vs. 0.56 ), consistent with keying on instruction-tuned stylistic regularities. Training on multiple generator families and on base-model output is future work.
  • Response-format confound on the text side. Human and machine responses are matched on the prompt/question but not on response format. A format-only classifier reaches AUROC ≈ 0.998 in-distribution, and an identical surface normalization applied to both classes moves the neural detector from 1.000 to 0.815 on code (AST canonicalization removing docstrings, comments, and indentation variance) but leaves text essentially unchanged, because text-side cues (length, verbosity, punctuation density) are entangled with content and cannot be reformatted away (Appendix D). Our detector should therefore be understood as detecting format-and-style-typical instruction-tuned output; robustly detecting machine text deliberately format-matched to human conventions remains future work, as the human responses cannot be re-collected under a matched template.
  • Python-only code scope. All code experiments use Python exclusively. AST structure, naming conventions, and formatting norms differ substantially across programming languages, and generalization to Java, C++, JavaScript, or other languages is untested.
  • Attack strength is a lower bound. The tested transformations (same-family paraphrase; AST variable renaming with comment stripping) constitute a lower bound on adversarial pressure. The robustness results should not be read as resistance to determined evasion such as cross-family rewriting, control-flow flattening, or dead-code insertion, which are listed as future work.
  • Standard decoding only. Our machine samples span three decoding temperatures ( 0.3 / 0.7 / 1.0 ), and Appendix E shows detection AUROC is flat across them in-domain, out-of-domain, and on Mix-Eval. All samples are nonetheless produced with standard temperature/nucleus sampling from instruction-tuned models; we do not evaluate adversarial decoding strategies designed specifically to evade detection (e.g., logit steering), which we leave to future work.

Author Contributions

Conceptualization, N.A., P.S.V.G. and H.I.; methodology, N.A. and H.I.; software, N.A.; validation, N.A., P.S.V.G. and H.I.; formal analysis, N.A.; investigation, N.A.; resources, P.S.V.G. and H.I.; data curation, N.A.; writing: original draft preparation, N.A.; writing; review and editing, P.S.V.G. and H.I.; visualization, N.A.; supervision, P.S.V.G. and H.I.; project administration, H.I. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Data Availability Statement

The datasets analyzed in this study are publicly available from their original sources, including HC3 (https://huggingface.co/datasets/Hello-SimpleAI/HC3, accessed on 22 December 2025), CodeSearchNet (https://huggingface.co/datasets/sentence-transformers/codesearchnet, accessed on 22 December 2025), MBPP (https://github.com/google-research/google-research/tree/master/mbpp, accessed on 22 December 2025), HumanEval (https://deepeval.com/docs/benchmarks-human-eval, accessed on 22 December 2025), and the Jupyter notebook text, code pair corpus used for the mixed-content evaluation. The external SemEval-2026 Task 13 Python subset is publicly available through the corresponding task release.

Acknowledgments

During the preparation of this manuscript, the authors used Claude Opus 4.8 and ChatGPT-5.4 for assistance with manuscript formatting and grammar correction. The tool was not used for study design, data collection, experimental analysis, or interpretation of results. The authors have reviewed and edited all outputs and take full responsibility for the content of this publication.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
AccAccuracy
ASTAbstract syntax tree
AUROCArea under the receiver operating characteristic curve
BPEByte-pair encoding
CLSClassification token
ECEExpected calibration error
ELI5Explain Like I am Five
HC3Human ChatGPT Comparison Corpus
IDIn-distribution
LLMLarge language model
LSHLocality-sensitive hashing
MBPPMostly Basic Python Problems
MBPP+HEMostly Basic Python Problems plus HumanEval
MLPMultilayer perceptron
NLLNegative log-likelihood
OODOut-of-distribution
OSSOpen-source software
RQResearch question
TTRType–token ratio

Appendix A. Prompt Template

The prompts are intentionally minimal. For HC3, the system prompt is “You are a helpful assistant” and the user message is the HC3 question verbatim. For MBPP, the user message asks for a Python function that solves the problem and that passes the first assertion in the test_list, and asks the model to return only the function definition. For HumanEval, the user message provides the signature and docstring and asks for the function body only. For CodeSearchNet, the user message asks for a function that does what the first paragraph of the documentation string describes, returning the full definition with no explanation.
In implementation, prompts are formatted using the Hugging Face apply_chat_template function with add_generation_prompt=True.
Ai 07 00319 i001

Appendix B. Representative Paired Samples and Extended Detection Examples

Following reviewer feedback, the representative paired-sample tables (Table A1, Table A2 and Table A3), previously in Section 3, are provided here alongside the extended detection examples.
Table A1. Paired text examples from HC3 with machine generations by Qwen2.5-7B-Instruct.
Table A2. Paired code examples from MBPP and HumanEval, with machine generations produced by Qwen2.5-Coder-7B-Instruct. Markdown fences are stripped during post-processing.
Table A3. Paired code examples from CodeSearchNet, with machine generations produced by Qwen2.5-Coder-7B-Instruct.
Table A4 provides the extended detector outputs referenced in the main qualitative analysis.
Table A4. Extended set of detector outputs across all test conditions. A curated subset appears in Table 14. TP = correctly detected machine-generated; TN = correctly identified human; FP = human misclassified as machine; FN = machine misclassified as human. Each row shows the detector probability p ( machine ) .

Appendix C. Controlled Multi-Generator Evaluation

To verify that the negligible cross-generator degradation reported in the main results is not an idiosyncrasy of a single model pair, we generate the machine half of the same test problems with five generators for code and three for text, spanning five instruction-tuned families and 3.8 B–7B parameters, and score each against the identical human negative pool with the unchanged detectors. Only the generator varies, so this evaluation isolates the generator variable; results are in Table A5. The AUROC range across generators is 0.0002 per modality: with the human and problem distribution held fixed, generator identity has no measurable effect across the instruction-tuned families tested.
Table A5. Controlled multi-generator evaluation: AUROC of the unchanged detectors against the shared human negative pool, varying only the generator. Range across generators: 0.0002 per modality.
We additionally decompose the SemEval-2026 Task 13 Python transfer (Section 3.5) per generator. The overall drop to AUROC ≈ 0.72 is dominated by a shift in the human distribution rather than by any generator: SemEval’s curated, competition-style human code receives mean P ( machine ) of 0.83 and is flagged as machine for 84 % of samples at the default threshold (versus 1.1 % in-domain), the surface-style mechanism documented in the qualitative analysis. Holding the human pool fixed, the only systematic generator effect is the instruction-tuned/base divide (Table A6): the detector transfers across instruction-tuned families but not to base/pretrained models, whose output lacks the instruction-tuned formatting polish; model size is uncorrelated with detectability (Spearman ρ = − 0.06 , p = 0.76 ).
Table A6. Per-generator-class AUROC on the SemEval-2026 Task 13 Python transfer, human pool held fixed, mean ± std over three seeds.

Appendix D. Surface-Feature Analysis and Canonicalization Ablation

Near-perfect in-distribution performance raises the question of whether the detectors exploit trivial surface-level differences between the classes introduced by the data-construction pipeline. We test this directly. A classifier restricted to shallow format-only features such as length, whitespace, indentation, punctuation, casing, and comment/markdown/docstring markers, with no lexical content, embeddings, or perplexity, separates the in-distribution classes at AUROC 0.994 (code) and 0.998 (text); the single strongest code cue is docstring presence. We then apply an identical surface normalization to both classes and re-score the unchanged neural detector. For code, the normalization is AST canonicalization: docstring and comment stripping with uniform indentation via ast.unparse. Table A7 reports the results over three seeds.
Table A7. Surface-feature analysis and canonicalization ablation, in-distribution, three seeds. Code canonicalization strips docstrings/comments and enforces uniform indentation, applied identically to both classes. A formatting-only normalization does not surface-match text, because the dominant text cues (length, verbosity, punctuation density) are entangled with content.
Roughly a fifth of the in-distribution code AUROC is therefore carried by surface formatting, while the detector retains substantial non-surface signal (identifier naming, control-flow structure, library idioms). Two observations argue against train/test leakage as an alternative explanation: the benchmark is deduplicated via MinHash-LSH across the union of human and machine samples, and the same detectors collapse under domain shift, which leaked or memorized artifacts would not produce. Notably, the post-canonicalization AUROC ( 0.815 ) closely matches the cross-domain held-out AUROC ( 0.850 ): both estimate the signal that remains once surface cues stop being informative. For text, format-only normalization cannot remove the confound; this is stated as a limitation in Section 12.

Appendix E. Per-Temperature Evaluation

Machine samples are generated at three temperatures τ ∈ { 0.3 , 0.7 , 1.0 } assigned round-robin (Section 3.1). A potential confound is that the detector might learn temperature-specific decoding artifacts (e.g., the more templated, lower-entropy style of τ = 0.3 ) rather than generation provenance. To test this, we slice the existing test predictions by generation temperature and recompute AUROC per slice, scoring each temperature’s machine samples against the full shared human negative pool of the evaluation set; no model is retrained. Because the human side is shared, the three per- τ AUROCs on a given evaluation set are not independent, but each answers the relevant question: how separable is that temperature’s machine slice from the same human distribution. Per-seed overall AUROCs computed under this join reproduce the headline results exactly, confirming the correctness of the slicing. Table A8 reports the resulting per-temperature AUROC values.
Table A8. Per-temperature AUROC, mean over three seeds { 42 , 123 , 7 } . Each cell scores the machine samples generated at the given τ against the full shared human negative pool of that evaluation set; the human pool is shared across columns, so per- τ values within a row are not independent.
Detection is essentially flat across temperature in every regime. In-domain and cross-generator conditions are at ceiling for all three temperatures—and the cross-generator condition uses generator families never seen in training, so the flatness cannot be attributed to in-distribution saturation. On Mix-Eval, the only condition with meaningful headroom, the per-temperature slices differ by at most 3.3 AUROC points, within seed-level variability. A temperature–artifact shortcut would predict a marked advantage on the most templated, low-temperature samples; we instead observe a mild, non-significant decrease only at τ = 1.0 , in the direction expected from genuinely more diverse outputs. We conclude the detectors are not exploiting a temperature-specific decoding artifact.

Appendix F. Extended Calibration Analysis

Extending the calibration analysis of the main results, Table A9 reports raw and Platt-scaled ECE across validation, in-domain, cross-generator, held-out, and mixed-content conditions for both modalities. Platt parameters are fit on the in-domain validation split only; every OOD set is unseen by the calibrator. Three regimes emerge. Where the model is miscalibrated but its errors are affine-correctable, the code OOD conditions, Platt scaling helps substantially (code Mix-Eval: 41.05 % → 26.36 % ; held-out MBPP+HE: 48.54 % → 44.78 % ). On near-ceiling conditions, there is nothing to correct (raw ECE ≤ 1 % ). And on text Mix-Eval, the detector is confidently wrong across the confidence range, which a single global affine map cannot repair (ECE essentially unchanged, 37.17 % → 36.34 % ); this is the threshold-collapse phenomenon that motivates domain-matched threshold tuning as the stronger operational lever.
Table A9. Extended calibration analysis. Platt parameters are fit on the in-domain validation split only; every OOD set is unseen by the calibrator. Mean over three seeds; ECE convention of Section 7. Reliability diagrams for the in-distribution, held-out, and Mix-Eval settings appear in the main results.

Appendix G. Consolidated Training Hyperparameters

Table A10 consolidates all training hyperparameters for reproducibility.
Table A10. Consolidated training hyperparameters, shared across all supervised detectors unless noted.

References

  1. Brown, T.; Mann, B.; Ryder, N.; Subbiah, M.; Kaplan, J.D.; Dhariwal, P.; Neelakantan, A.; Shyam, P.; Sastry, G.; Askell, A.; et al. Language models are few-shot learners. Adv. Neural Inf. Process. Syst. 2020, 33, 1877–1901. [Google Scholar]
  2. Achiam, J.; Adler, S.; Agarwal, S.; Ahmad, L.; Akkaya, I.; Aleman, F.L.; Almeida, D.; Altenschmidt, J.; Altman, S.; Anadkat, S.; et al. Gpt-4 technical report. arXiv 2023, arXiv:2303.08774. [Google Scholar]
  3. Bai, Y.; Kadavath, S.; Kundu, S.; Askell, A.; Kernion, J.; Jones, A.; Chen, A.; Goldie, A.; Mirhoseini, A.; McKinnon, C.; et al. Constitutional ai: Harmlessness from ai feedback. arXiv 2022, arXiv:2212.08073. [Google Scholar]
  4. Touvron, H.; Martin, L.; Stone, K.; Albert, P.; Almahairi, A.; Babaei, Y.; Bashlykov, N.; Batra, S.; Bhargava, P.; Bhosale, S.; et al. Llama 2: Open foundation and fine-tuned chat models. arXiv 2023, arXiv:2307.09288. [Google Scholar]
  5. Li, R.; Allal, L.B.; Zi, Y.; Muennighoff, N.; Kocetkov, D.; Mou, C.; Marone, M.; Akiki, C.; Li, J.; Chim, J.; et al. Starcoder: May the source be with you! arXiv 2023, arXiv:2305.06161. [Google Scholar]
  6. Wu, J.; Yang, S.; Zhan, R.; Yuan, Y.; Chao, L.S.; Wong, D.F. A survey on llm-generated text detection: Necessity, methods, and future directions. Comput. Linguist. 2025, 51, 275–338. [Google Scholar] [CrossRef] [Scilit]
  7. Clark, E.; August, T.; Serrano, S.; Haduong, N.; Gururangan, S.; Smith, N.A. All that’s ‘human’is not gold: Evaluating human evaluation of generated text. In Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing (Volume 1: Long Papers), Virtual, 1–6 August 2021; pp. 7282–7296. [Google Scholar]
  8. Jakesch, M.; Hancock, J.T.; Naaman, M. Human heuristics for AI-generated language are flawed. Proc. Natl. Acad. Sci. USA 2023, 120, e2208839120. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  9. Liang, W.; Izzo, Z.; Zhang, Y.; Lepp, H.; Cao, H.; Zhao, X.; Chen, L.; Ye, H.; Liu, S.; Huang, Z.; et al. Monitoring ai-modified content at scale: A case study on the impact of chatgpt on ai conference peer reviews. arXiv 2024, arXiv:2403.07183. [Google Scholar]
  10. Hanley, H.W.; Durumeric, Z. Machine-made media: Monitoring the mobilization of machine-generated articles on misinformation and mainstream news websites Version 1. arXiv 2023, arXiv:2305. 09820. [Google Scholar]
  11. Cotton, D.R.; Cotton, P.A.; Shipway, J.R. Chatting and cheating: Ensuring academic integrity in the era of ChatGPT. Innov. Educ. Teach. Int. 2024, 61, 228–239. [Google Scholar] [CrossRef] [Scilit]
  12. Sullivan, M.; Kelly, A.; McLaughlan, P. ChatGPT in higher education: Considerations for academic integrity and student learning. J. Appl. Learn. Teach. 2023, 6, 31–40. [Google Scholar] [CrossRef] [Scilit]
  13. Goldstein, J.A.; Sastry, G.; Musser, M.; DiResta, R.; Gentzel, M.; Sedova, K. Generative language models and automated influence operations: Emerging threats and potential mitigations. arXiv 2023, arXiv:2301.04246. [Google Scholar]
  14. Spitale, G.; Biller-Andorno, N.; Germani, F. AI model GPT-3 (dis) informs us better than humans. Sci. Adv. 2023, 9, eadh1850. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  15. Chen, C.; Shu, K. Combating misinformation in the age of llms: Opportunities and challenges. AI Mag. 2024, 45, 354–368. [Google Scholar] [CrossRef] [Scilit]
  16. Noy, S.; Zhang, W. Experimental evidence on the productivity effects of generative artificial intelligence. Science 2023, 381, 187–192. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  17. Peng, S.; Kalliamvakou, E.; Cihon, P.; Demirer, M. The impact of ai on developer productivity: Evidence from github copilot. arXiv 2023, arXiv:2302.06590. [Google Scholar]
  18. Pearce, H.; Ahmad, B.; Tan, B.; Dolan-Gavitt, B.; Karri, R. Asleep at the keyboard? assessing the security of github copilot’s code contributions. Commun. ACM 2025, 68, 96–105. [Google Scholar] [CrossRef] [Scilit]
  19. Sandoval, G.; Pearce, H.; Nys, T.; Karri, R.; Garg, S.; Dolan-Gavitt, B. Lost at c: A user study on the security implications of large language model code assistants. In Proceedings of the 32nd USENIX Security Symposium (USENIX Security 23), Anaheim, CA, USA, 9–11 August 2023; pp. 2205–2222. [Google Scholar]
  20. Gehrmann, S.; Strobelt, H.; Rush, A.M. Gltr: Statistical detection and visualization of generated text. In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics: System Demonstrations, Florence, Italy, 28 July–2 August 2019; pp. 111–116. [Google Scholar]
  21. Mitchell, E.; Lee, Y.; Khazatsky, A.; Manning, C.D.; Finn, C. Detectgpt: Zero-shot machine-generated text detection using probability curvature. In Proceedings of the International Conference on Machine Learning, PMLR, Honolulu, HI, USA, 23–29 July 2023; pp. 24950–24962. [Google Scholar]
  22. Hans, A.; Schwarzschild, A.; Cherepanova, V.; Kazemi, H.; Saha, A.; Goldblum, M.; Geiping, J.; Goldstein, T. Spotting llms with binoculars: Zero-shot detection of machine-generated text. arXiv 2024, arXiv:2401.12070. [Google Scholar]
  23. Solaiman, I.; Brundage, M.; Clark, J.; Askell, A.; Herbert-Voss, A.; Wu, J.; Radford, A.; Krueger, G.; Kim, J.W.; Kreps, S.; et al. Release strategies and the social impacts of language models. arXiv 2019, arXiv:1908.09203. [Google Scholar]
  24. Verma, V.; Fleisig, E.; Tomlin, N.; Klein, D. Ghostbuster: Detecting text ghostwritten by large language models. In Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers); Association for Computational Linguistics: Mexico City, Mexico, 2024; pp. 1702–1717. [Google Scholar]
  25. Nguyen, P.T.; Di Rocco, J.; Di Sipio, C.; Rubei, R.; Di Ruscio, D.; Di Penta, M. GPTSniffer: A CodeBERT-based classifier to detect source code written by ChatGPT. J. Syst. Softw. 2024, 214, 112059. [Google Scholar] [CrossRef] [Scilit]
  26. Kirchenbauer, J.; Geiping, J.; Wen, Y.; Katz, J.; Miers, I.; Goldstein, T. A watermark for large language models. In Proceedings of the International Conference on Machine Learning, PMLR, Honolulu, HI, USA, 23–29 July 2023; pp. 17061–17084. [Google Scholar]
  27. Liu, A.; Pan, L.; Lu, Y.; Li, J.; Hu, X.; Zhang, X.; Wen, L.; King, I.; Xiong, H.; Yu, P. A survey of text watermarking in the era of large language models. ACM Comput. Surv. 2024, 57, 1–36. [Google Scholar] [CrossRef] [Scilit]
  28. Krishna, K.; Song, Y.; Karpinska, M.; Wieting, J.; Iyyer, M. Paraphrasing evades detectors of ai-generated text, but retrieval is an effective defense. Adv. Neural Inf. Process. Syst. 2023, 36, 27469–27500. [Google Scholar] [CrossRef] [Scilit]
  29. Bhattacharjee, A.; Moraffah, R.; Garland, J.; Liu, H. Eagle: A domain generalization framework for ai-generated text detection. arXiv 2024, arXiv:2403.15690. [Google Scholar]
  30. Borile, C.; Abrate, C. How to Generalize the Detection of AI-Generated Text: Confounding Neurons. In Proceedings of the Findings of the Association for Computational Linguistics: EMNLP 2025, Suzhou, China, 4–9 November 2025; pp. 25461–25476. [Google Scholar]
  31. Guo, B.; Zhang, X.; Wang, Z.; Jiang, M.; Nie, J.; Ding, Y.; Yue, J.; Wu, Y. How close is chatgpt to human experts? Comparison corpus, evaluation, and detection. arXiv 2023, arXiv:2301.07597. [Google Scholar]
  32. Husain, H.; Wu, H.H.; Gazit, T.; Allamanis, M.; Brockschmidt, M. Codesearchnet challenge: Evaluating the state of semantic code search. arXiv 2019, arXiv:1909.09436. [Google Scholar]
  33. Austin, J.; Odena, A.; Nye, M.; Bosma, M.; Michalewski, H.; Dohan, D.; Jiang, E.; Cai, C.; Terry, M.; Le, Q.; et al. Program synthesis with large language models. arXiv 2021, arXiv:2108.07732. [Google Scholar]
  34. Chen, M.; Tworek, J.; Jun, H.; Yuan, Q.; Pinto, H.P.D.O.; Kaplan, J.; Edwards, H.; Burda, Y.; Joseph, N.; Brockman, G.; et al. Evaluating large language models trained on code. arXiv 2021, arXiv:2107.03374. [Google Scholar]
  35. Liu, Y.; Ott, M.; Goyal, N.; Du, J.; Joshi, M.; Chen, D.; Levy, O.; Lewis, M.; Zettlemoyer, L.; Stoyanov, V. Roberta: A robustly optimized bert pretraining approach. arXiv 2019, arXiv:1907.11692. [Google Scholar]
  36. Guo, D.; Ren, S.; Lu, S.; Feng, Z.; Tang, D.; Liu, S.; Zhou, L.; Duan, N.; Svyatkovskiy, A.; Fu, S.; et al. Graphcodebert: Pre-training code representations with data flow. arXiv 2020, arXiv:2009.08366. [Google Scholar]
  37. Feng, Z.; Guo, D.; Tang, D.; Duan, N.; Feng, X.; Gong, M.; Shou, L.; Qin, B.; Liu, T.; Jiang, D.; et al. Codebert: A pre-trained model for programming and natural languages. In Proceedings of the Findings of the Association for Computational Linguistics: EMNLP 2020, Punta Cana, Dominican Republic, 8–12 November 2020; pp. 1536–1547. [Google Scholar]
  38. Yang, A.; Yang, B.; Zhang, B.; Hui, B.; Zheng, B.; Yu, B.; Li, C.; Liu, D.; Huang, F.; Wei, H.; et al. Qwen2.5 technical report. arXiv 2025, arXiv:2412.15115. [Google Scholar]
  39. Yang, A.; Zhang, B.; Hui, B.; Gao, B.; Yu, B.; Li, C.; Liu, D.; Tu, J.; Zhou, J.; Lin, J.; et al. Qwen2.5-math technical report: Toward mathematical expert model via self-improvement. arXiv 2024, arXiv:2409.12122. [Google Scholar]
  40. Jiang, A.Q.; Sablayrolles, A.; Roux, A.; Mensch, A.; Savary, B.; Bamford, C.; Chaplot, D.S.; Casas, D.d.l.; Hanna, E.B.; Bressand, F.; et al. Mixtral of experts. arXiv 2024, arXiv:2401.04088. [Google Scholar]
  41. Hui, B.; Yang, J.; Cui, Z.; Yang, J.; Liu, D.; Zhang, L.; Liu, T.; Zhang, J.; Yu, B.; Lu, K.; et al. Qwen2.5-Coder Technical Report. arXiv 2024, arXiv:2409.12186. [Google Scholar]
  42. Guo, D.; Zhu, Q.; Yang, D.; Xie, Z.; Dong, K.; Zhang, W.; Chen, G.; Bi, X.; Wu, Y.; Li, Y.; et al. DeepSeek-Coder: When the large language model meets programming–the rise of code intelligence. arXiv 2024, arXiv:2401.14196. [Google Scholar]
  43. Radford, A.; Wu, J.; Child, R.; Luan, D.; Amodei, D.; Sutskever, I. Language Models are Unsupervised Multitask Learners; OpenAI: San Francisco, CA, USA, 2019. [Google Scholar]
  44. Bao, G.; Zhao, Y.; Teng, Z.; Yang, L.; Zhang, Y. Fast-detectgpt: Efficient zero-shot detection of machine-generated text via conditional probability curvature. In Proceedings of the International Conference on Learning Representations, Vienna, Austria, 7–11 May 2024; Volume 2024, pp. 24814–24836. [Google Scholar]
  45. Oedingen, M.; Engelhardt, R.C.; Denz, R.; Hammer, M.; Konen, W. Chatgpt code detection: Techniques for uncovering the source of code. AI 2024, 5, 1066–1094. [Google Scholar] [CrossRef] [Scilit]
  46. Caliskan, A.; Yamaguchi, F.; Dauber, E.; Harang, R.; Rieck, K.; Greenstadt, R.; Narayanan, A. When coding style survives compilation: De-anonymizing programmers from executable binaries. arXiv 2015, arXiv:1512.08546. [Google Scholar]
  47. Platt, J.C. Probabilistic Outputs for Support Vector Machines and Comparisons to Regularized Likelihood Methods. In Advances in Large Margin Classifiers; MIT Press: Cambridge, MA, USA, 1999; pp. 61–74. [Google Scholar]
  48. Guo, C.; Pleiss, G.; Sun, Y.; Weinberger, K.Q. On Calibration of Modern Neural Networks. In Proceedings of the 34th International Conference on Machine Learning, PMLR, Sydney, Australia, 6–11 August 2017; Volume 70, pp. 1321–1330. [Google Scholar]
  49. OpenAI. GPT-2: 1.5B Release and Detection Tools. 2019. Available online: https://github.com/openai/gpt-2-output-dataset (accessed on 25 December 2025).
  50. Broder, A.Z. On the resemblance and containment of documents. In Proceedings of the Proceedings, Compression and Complexity of SEQUENCES 1997 (Cat. No. 97TB100171); IEEE: New York, NY, USA, 1997; pp. 21–29. [Google Scholar]
  51. Zhu, E.; Markovtsev, V. Datasketch: Big Data Looks Small; GitHub Repository; GitHub: San Francisco, CA, USA, 2018. [Google Scholar]
  52. Orel, D.; Azizov, D.; Nakov, P. CoDet-M4: Detecting Machine-Generated Code in Multi-Lingual, Multi-Generator and Multi-Domain Settings. In Proceedings of the Findings of the Association for Computational Linguistics: ACL 2025; Che, W., Nabende, J., Shutova, E., Pilehvar, M.T., Eds.; Association for Computational Linguistics: Vienna, Austria, 2025; pp. 10570–10593. [Google Scholar]
  53. Orel, D.; Paul, I.; Gurevych, I.; Nakov, P. Droid: A resource suite for ai-generated code detection. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, Suzhou, China, 4–9 November 2025; pp. 31251–31277. [Google Scholar]
  54. Wolf, T.; Debut, L.; Sanh, V.; Chaumond, J.; Delangue, C.; Moi, A.; Cistac, P.; Rault, T.; Louf, R.; Funtowicz, M.; et al. Transformers: State-of-the-Art Natural Language Processing. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations, Online, 16–20 November 2020; pp. 38–45. [Google Scholar]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Article Metrics

Citations

Article Access Statistics

Multiple requests from the same IP address are counted as one view.