kirschbaum-development / redactor-onnx
In-process named entity recognition for kirschbaum-development/redactor, running an ONNX model through TransformersPHP with no sidecar.
Package info
github.com/kirschbaum-development/redactor-onnx
pkg:composer/kirschbaum-development/redactor-onnx
Requires
- php: ^8.3|^8.4|^8.5
- ext-ffi: *
- codewithkyrian/transformers: ^0.6
- illuminate/support: ^12.0|^13.0
- kirschbaum-development/redactor: ^1.0
Requires (Dev)
- driftingly/rector-laravel: ^2.5
- larastan/larastan: ^3.4
- laravel/pint: ^1.22
- orchestra/testbench: ^10.3|^11.0
- pestphp/pest: ^3.8
- rector/rector: ^2.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Redactor ONNX gives Kirschbaum Redactor an in-process named entity recogniser. It runs a token classification model through TransformersPHP inside the PHP worker, so the redactor can find names, places and organisations in prose with no sidecar to deploy and no network call to wait for.
The recogniser registers as the onnx driver. Everything else stays the redactor's: the gates that keep JSON and stack traces away from the model, the offset check, the circuit breaker, batching, operators and profiles.
Quick Start
Install the package, then download and load the model once so no job pays for it:
composer require kirschbaum-development/redactor-onnx php artisan redactor:onnx:warm
Select the driver in any profile's recognition block in config/redactor.php:
'recognition' => [ 'enabled' => true, 'driver' => 'onnx', 'entities' => ['PERSON', 'LOCATION', 'ORGANIZATION'], ],
Then redact as usual:
use Kirschbaum\Redactor\Facades\Redactor; Redactor::redact('Please call John Smith in Berlin about the invoice', 'exports'); // 'Please call [REDACTED] in [REDACTED] about the invoice'
How It Works
The model labels tokens, and the runtime reports no character offsets, so the recogniser finds each decoded token in the original text and folds the model's BIO labels into spans with exact offsets. Long texts are cut at whitespace into windows the model can hold in full, and every prose value the redactor gathers from a payload goes through the model in one batched call. Model labels such as PER are mapped to the names the redactor's profiles already use, such as PERSON.
The model loads on the first call and stays in memory, so the driver belongs in queue workers, Octane, exports and redactor:scan, where a process lives long enough to amortise the load.
Documentation
The full documentation lives in docs/:
| Page | What it covers |
|---|---|
| Getting Started | Requirements, installation, selecting the driver, warming the model, and where to run it. |
| Configuration | Every key in config/redactor-onnx.php with its type, default and environment variable. |
| How It Works | Alignment of tokens to characters, windows, batching, labels and failures. |
| Models | Choosing a model, tokenizer marks, memory and speed. |
| Testing | Faking the classifier in your suite, the opt-in real-model test, the package's own conventions. |
Requirements
- PHP 8.3, 8.4 or 8.5 with the
ffiextension - Laravel 12.x or 13.x
kirschbaum-development/redactor
Testing
composer test # full suite, no model needed composer test-coverage # with the coverage floor enforced composer lint # Pint, Rector, PHPStan (level 10, no baseline) composer preflight # everything CI runs
See Testing for the opt-in test that downloads and runs the real model.
Changelog
See CHANGELOG.md.
License
MIT License. See LICENSE.md for details.