Compressed a RoBERTa AI-text detector from ~500 MB to ~97 MB so it runs client-side in the browser, plus a 26 MB image detector [P]
Mirrored from r/MachineLearning for archival readability. Support the source by reading on the original site.
I wanted an AI text and image detector that doesn't need you to upload anything, so I took two existing open detectors and got them running fully client-side with ONNX Runtime Web.
Demo: https://tinydetect.ritabratamaiti.com/
Code and scripts: https://github.com/ritabratamaiti/tinydetect
I didn't train new detectors. The base models are fakespot-ai/roberta-base-ai-text-detection-v1 (Apache-2.0) and Community Forensics (commfor-model-384, MIT). My work was the tuning, the compression and the browser runtime.
Text model (about 500 MB in fp32, 97 MB after compression)
- I fine-tuned it lightly on a mix of human and AI text (HC3, GPT-wiki-intro, HAP-E, WildChat, Gutenberg and some text I generated locally with Gemma-3-1B). Then I used WiSE-FT, which interpolates between the original and tuned weights, so the model doesn't drift too far from the original.
- The word embedding matrix is taken out of the ONNX graph and stored as int4 with fp16 per-row scales (about 19 MB plus 2 MB). It's dequantized in JS and passed to the transformer body.
- The transformer body uses mixed-precision quantization and comes to about 75 MB.
- The byte-level BPE tokenizer and Fakespot's
clean_textpreprocessing are reimplemented in JS.
Image model (about 26 MB)
- This is a quantized Community Forensics ViT with calibrated output scores. Resizing, center cropping and normalization all happen locally before inference.
Runtime
- It uses ONNX Runtime Web 1.30, with the WebGPU build if there's a GPU adapter and threaded WASM otherwise.
- A service worker adds COOP/COEP headers so threaded WASM works on GitHub Pages. It also caches the model and runtime files.
- A warm-up run compiles the GPU shaders before the first real check. After that, a text check of about 100 tokens takes around 60 ms on my laptop, and an image takes around 200 ms.
Limitations
A high score doesn't prove who wrote something. Short or casual text, paraphrasing, heavy editing, screenshots, crops and newer generators all make both models less accurate. The first load is also a big download, especially on phones.
Everything in training/ runs on a single laptop, including the candidate benchmarks, tuning, WiSE alpha selection, export, quantization sweeps and evaluation. I'd like feedback on the quantization choices and on where it fails with your own text.
[link] [comments]
More from r/MachineLearning
-
I turned my dog Jackies Brain into a working AI [P]
Oct 14
-
Event2Vec: additive event embeddings where a linear score on a history decomposes exactly into per-event terms [P]
Oct 14
-
Binary noise classification using CRNN mean teacher algo [R]
Oct 14
-
Localized Neural learning vs backpropagation [D]
Oct 14
Discussion (0)
Sign in to join the discussion. Free account, 30 seconds — email code or GitHub.
Sign in →No comments yet. Sign in and be the first to say something.