You may install the package via Composer:
composer require directorytree/privacy-filter-classifierCreate a classifier using the local binary and model paths:
use DirectoryTree\PrivacyFilterClassifier\Classifier;
$classifier = new Classifier(
binaryPath: '/path/to/privacy-filter',
modelPath: '/path/to/privacy-filter-f16.gguf',
timeout: 60,
);
$entities = $classifier->entities('Contact John Doe at jdoe@example.com.');You may provide a classification threshold at runtime. The threshold is the minimum confidence score an entity must meet before it is returned. Increasing the threshold returns fewer, higher-confidence entities, while decreasing it may return more entities with lower confidence:
$entities = $classifier->entities(
text: 'Contact John Doe at jdoe@example.com.',
threshold: 0.75,
);The entities method returns an array of DirectoryTree\PrivacyFilterClassifier\Entity instances:
/** @var \DirectoryTree\PrivacyFilterClassifier\Entity $entity */
foreach ($entities as $entity) {
$entity->type; // private_email
$entity->text; // jdoe@example.com
$entity->start; // 20
$entity->end; // 36
$entity->score; // 0.98
}