Skip to main content
Version: Next

PrivacyFilterModule

TypeScript API implementation of the usePrivacyFilter hook.

API Reference

High Level Overview

import { models, PrivacyFilterModule } from 'react-native-executorch';
const model = await PrivacyFilterModule.fromModelName(
models.privacy_filter.openai(),
(progress) => console.log(progress)
);

const entities = await model.generate('My name is Sarah Chen.');

Methods

All methods of PrivacyFilterModule are explained in details here: PrivacyFilterModule API Reference

Loading the model

To create a ready-to-use instance for a built-in preset, call the static fromModelName factory with the following parameters:

  • namedSources — Object containing:

    • modelName — Built-in preset identifier ('privacy-filter-openai' or 'privacy-filter-nemotron'). The runner resolves the matching BIOES label list from this value.
    • modelSource — Location of the .pte model binary.
    • tokenizerSource — Location of the tokenizer.json file.
  • onDownloadProgress — Optional callback to track download progress (value between 0 and 1).

The factory returns a promise that resolves to a loaded PrivacyFilterModule instance.

For custom-exported models with a non-standard label space, use fromCustomModel instead. It takes modelSource, tokenizerSource, and a labelNames array (BIOES; index 0 must be "O", the rest must follow the model's id2label mapping exactly), plus an optional options object with viterbiBiases (six-field bias struct that shifts the decoder's precision/recall tradeoff; defaults to neutral validity-only Viterbi) and onDownloadProgress.

For more information on loading resources, take a look at loading models page.

Running the model

To run the model, call the generate method on the module object with the text you want to scan. The method returns a promise that resolves to an array of detected PII entity spans. Long inputs are processed in sliding windows with 50% overlap (window size derived from the model's exported forward input shape); no truncation.

Managing memory

The module is a regular JavaScript object, and as such its lifespan will be managed by the garbage collector. In most cases this should be enough, and you should not worry about freeing the memory of the module yourself, but in some cases you may want to release the memory occupied by the module before the garbage collector steps in. In this case use the method delete on the module object you will no longer use, and want to remove from the memory. Note that you cannot use generate after delete unless you load the module again.