作者把 RoBERTa AI 文本检测器从约 500 MB 压缩到约 97 MB,可在浏览器端运行
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]
作者将两个开源检测器改造成完全在浏览器端运行的版本,文本模型从 fp32 的约 500 MB 压缩到约 97 MB,图像模型约 26 MB,基于 ONNX Runtime Web 实现,无需上传数据。
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.
submitted by /u/Alternative_Detail31
[link] [留言]
来源:r/MachineLearning · reddit.com