File size: 4,867 Bytes
3e7258a
99fb72f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e7258a
99fb72f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32d1551
 
 
 
 
 
 
 
 
99fb72f
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
license: mit
language:
  - en
  - zh
  - ja
pipeline_tag: text-classification
library_name: generic
tags:
  - ai-detection
  - machine-generated-text
  - stylometry
  - webassembly
  - rust
  - lightgbm
  - treeshap
---

# ProseGuard-ML

**ProseGuard-ML** is a zero-dependency Rust and WebAssembly engine for client-side AI-generated text detection and sentence-level attribution across English, Simplified Chinese, Traditional Chinese, and Japanese.

The entire compiled binary and quantized statistical parameters fit in **679 KiB** (`prose_guard_wasm.wasm`, **389 KiB** gzipped) and execute locally in **2.5 to 6.8 ms** per document with zero network uploads.

* **Live Demo**: [https://aidetect.rist.edu.rs](https://aidetect.rist.edu.rs)
* **Technical Report**: Ryan Kung, *AIDetect: Sub-Megabyte Client-Side AI Text Detection via Hashed Statistical Models, Calibrated Gradient Boosted Trees, and Exact TreeSHAP in WebAssembly* (`RIST-CS-AI-2026-03`).
* **Neural Companion Models**: [`ElderRyan/ProseGuard-mmBERT-small`](https://huggingface.co/ElderRyan/ProseGuard-mmBERT-small) (distilled 22-layer multilingual encoder, `51.8 MB` Web Q4) and [`ElderRyan/ProseGuard-mmBERT-base`](https://huggingface.co/ElderRyan/ProseGuard-mmBERT-base) (`295.9 MB` INT8 ONNX).

## Architecture

`ProseGuard-ML` maps each input UTF-8 document onto a 28-dimensional feature vector backed by two immutable binary tables (`weights/ml_tables.bin` at `320 KiB` and `weights/gbdt_forest.bin` at `154 KiB`):

1. **Dual-Distribution Hashed PPM (`Dual-PPM`)**: Orders 1 to 3 hashed Markov transition log-likelihood ratios with empirical Bayes shrinkage and conditional Shannon surprisal estimation.
2. **Concave Distributional Mixture MLE**: Estimates the document AI mixture fraction $\hat{\alpha} \in [0, 1]$ via damped Newton-Raphson iteration over smoothed unigram and bigram likelihoods.
3. **Surprisal Rhythm & Hurst Exponent**: 9D conditional surprisal derivatives paired with a Rescaled-Range ($R/S$) Hurst exponent.
4. **Word Co-occurrence Network Topology**: Local clustering coefficient and degree assortativity on sliding lexical graphs.
5. **Formatting-Invariant Signed Feature-Hashed NBSVM**: 65,536-bucket Rademacher-signed sublinear TF n-gram linear scorer with zero-byte Traditional-to-Simplified CJK folding and Japanese Kana hash-salt isolation (`0x4A41_0000`).
6. **Out-of-Fold LightGBM + Exact Stack-Allocated TreeSHAP**: A 115-tree calibrated gradient-boosted forest trained on disjoint folds with Isotonic + Platt tail calibration and exact path-dependent Shapley attributions in WebAssembly.

## Repository Contents

* `prose_guard_wasm.wasm`: Compiled `wasm32-unknown-unknown` release module (`679 KiB`).
* `wasm-loader.js`: Self-contained ES/CommonJS loader with SHA-256 and IEEE 802.3 CRC32 verification.
* `weights/ml_tables.bin`: Packed 65,536-bucket Dual-PPM, Mixture MLE, and NBSVM table (`320 KiB`).
* `weights/gbdt_forest.bin`: Calibrated 115-tree LightGBM forest with node cover statistics (`154 KiB`).
* `rust_src/`: Complete zero-dependency Rust source crate (`[dependencies]` in `Cargo.toml` is empty).

## Quick Start (Node.js / Browser)

```javascript
import './wasm-loader.js';

const ProseGuard = globalThis.ProseGuardWasm;
await ProseGuard.initWasmEngine();

const report = ProseGuard.analyzeArticle(
  'Paste any English, Chinese, or Japanese article here for local inspection.',
  { genreCode: 0, sensitivityCode: 1 }
);

console.log({
  aiPct: report.aiPct,
  verdict: report.verdict,
  mleAlphaPct: report.mleAlphaPct,
  sentences: report.sentences,
});
```

## Benchmark

![OOD-2026 Modern same-split comparison](./assets/benchmark_hero.png)

On OOD-2026 Modern (338 human vs 56 AI passages, 2026 generators), `ProseGuard-ML` reaches 0.864 ROC-AUC and **39.3%** TPR@1%FPR (95% CI 21 to 52%). That is below `Oxidane/TMR` (50.0%) and above `e5-small-lora` (25.0%). It misses all 12 Claude Opus 5 passages at 1% FPR. At a 0.5 threshold it flags 3.8% (7/183) of non-native PubMed papers.

Held-out splits (N=1,400, TPR@1%FPR): NLPCC-2025 Chinese 58.3%, C-ReD 97.1%, AnxForever 79.8%, RAID+MAGE 44.5%.

Use it as a 2 to 7 ms first pass and send borderline text to `mmbert-small` or `mmbert-base`. Commercial APIs (GPTZero, Originality.ai, Pangram, ZeroGPT) have not been tested on this split. Full caveats: [main Model Card](https://huggingface.co/ElderRyan/proseguard).

## Limitations

Without deep transformer representations, sub-megabyte n-gram and rhythm models miss unseen frontier generators that deliberately suppress standard transition templates and vary sentence cadence (such as `Claude Opus 5` in `OOD-2026`). For high-stakes verification against frontier models, pair `ProseGuard-ML` as a fast first-pass filter with `ProseGuard-mmBERT-small` or `ProseGuard-mmBERT-base`.

## License

Released under the [MIT License](LICENSE).