123 lines
4.9 KiB
Markdown
123 lines
4.9 KiB
Markdown
# firaid-moz
|
|
|
|
> [!NOTE]
|
|
> This software is provided under terms of BUSL 1.1 license in most permissive mode,
|
|
> with exceptions for some automation.
|
|
> Please, consult the [LICENSE](LICENSE.md) if you're about to perform AI-assisted analysis
|
|
|
|
---
|
|
|
|
**Disclaimer:**
|
|
|
|
The software provided as-is, without warranty of any kind, express or implied.
|
|
This project is an educational proof-of-concept experiment.
|
|
|
|
To clarify:
|
|
|
|
- I am not responsible for your judgement on content origin (AI/human/assisted)
|
|
- I am not responsible for your attitude towards AI/human/assisted content
|
|
- I am not responsible for any consequences of such a judgement
|
|
|
|
Classifications performed by this extension are not based on private or social opinions. This extension does not rely on reputations, lists, filters, etc.
|
|
|
|
The only method used by this extension to determine origin of content is a bunch of linear algebra in a black-box, aka "ML model", which decisions may or may not be biased - depending on training dataset, which is out of scope of this project.
|
|
|
|
---
|
|
|
|
A simple local webextension, which can run a bunch of small ML models to infer some properties of DOM content, such as:
|
|
|
|
- Probability of text being AI/Human created
|
|
- Probability of image being AI/Human created
|
|
|
|
## AI/Human classification
|
|
|
|
> **NONE** of ML/AI/whatever models is 100% accurate by the very fundamental design. Every "AI" simply *pretends* to posess some information. So this extension *pretends* to know which content is AI-generated and which is not - with a certain degree of accuracy.
|
|
>
|
|
> If you don't trust the "AI slop" - you should not completely trust this extension also!
|
|
>
|
|
> False-positives - Possible
|
|
>
|
|
> False-negatives - Probably
|
|
>
|
|
> User discretion - Highly advised
|
|
|
|
I hate the *slop* - when the entire "technical guide" article is nothing more then a bunch of AI ejacuation. But how do I know that slop is a slop?
|
|
|
|
Yeah.. I have to read it. And I had _enough_ of reading. So I want to see a warning badge like "its AI" - to help me navigate through text/image content.
|
|
|
|
AI/Human classification can be done in three modes:
|
|
|
|
1. _(lite)_: Lightweight model
|
|
2. _(mixed)_: Lightweight model runs first, but when its decision is weak - heavier model takes the task. This is usually faster, but requires both lite and heavy models to be loaded thus eating lots of RAM
|
|
3. _(hard)_: Heavier and more accurate model takes all tasks, lightweight model is disabled
|
|
|
|
The _lite_ mode requires ~80Mb of RAM for text classification
|
|
|
|
The _mixed_ mode requires ~380Mb of RAM for text classification
|
|
|
|
The _hard_ mode requires ~300Mb of RAM for text classification
|
|
|
|
## Installation
|
|
|
|
### Building from source
|
|
|
|
This webextension can be built from source. The following instrumentation is required:
|
|
|
|
- `cargo` + `cargo-make` + `wasm-pack` (cargo-make will install it automatically)
|
|
- `pnpm`
|
|
|
|
To build both firefox and chrome release versions, run the `release` task:
|
|
|
|
```bash
|
|
cargo make -p production release
|
|
```
|
|
|
|
If you do not have `wasm-pack` (cargo) installed, cargo-make will install it for you.
|
|
|
|
#### Models
|
|
|
|
To only build models, clone the repo, and run `models` task within `production` environment:
|
|
|
|
```bash
|
|
cargo make -p production models
|
|
```
|
|
|
|
This will compile all implemented models into WASM packages, which are later used by webextension.
|
|
|
|
NPM-ready packages for both ai-text models will be located under `<repo>/wasm/pkg` directory
|
|
|
|
##### Using different models for inference
|
|
|
|
You can build the [text classification](./wasm/model-ai-text) with any ONNX model from huggingface.
|
|
|
|
Following env variables are required:
|
|
|
|
- `_MK_MODEL_AI_TEXT`: name of the huggingface repository (e.g. "onnx-community/text-ai-detection")
|
|
- `_MK_MODEL_AI_TEXT_ONNX`: name of the onnx model file under the repository (e.g. "onnx/model.onnx")
|
|
|
|
Following env variables are optional:
|
|
|
|
- `_MK_MODEL_AI_TEXT_ATTENTION`: set to `yes` or `1` if your model uses attention mask
|
|
- `_MK_MODEL_AI_TEXT_TYPES`: set to `yes` or `1` if your model uses token types tensor
|
|
|
|
Not every model will work, and not every model which works will compute valid results.
|
|
Major constraints are:
|
|
|
|
- FP32 or FP16 weights (quantizations, int8, etc will be available when implemented by burn/burn-onnx)
|
|
- Sane size, 500Mb is your soft ceiling (browsers would likely refuse to load enormous WASM)
|
|
- Two label classification, where label `[0]` is Human and `[1]` is AI
|
|
- Output is `[0, 2]` sized tensor of *logits*
|
|
|
|
If you encounter compilation error, and compiler complains about invalid `forward` function arguments,
|
|
most likely you set the wrong `_MK_MODEL_AI_TEXT_ATTENTION` and `_MK_MODEL_AI_TEXT_TYPES` values.
|
|
|
|
#### Extension
|
|
|
|
> You must build models before running this
|
|
|
|
To only build the extension, clone the repo, build models, then you can run following tasks:
|
|
|
|
- `extension`: build and zip firefox and chrome extensions
|
|
- `extension_moz`: only build firefox extension
|
|
- `extension_chro`: only build chrome extension
|
|
- `dev`: run wxt dev server (chrome variant)
|