Skip to main content

newmean_pii 1.2.0 copy "newmean_pii: ^1.2.0" to clipboard
newmean_pii: ^1.2.0 copied to clipboard

Detect and mask personal information (PII) in text on the device, in 54 languages, with the newmean-pii models (dart:ffi over a small C engine; nothing is sent anywhere).

English | 한국어

newmean_pii #

Detect and mask personal information in text on the device, in Flutter and Dart apps. A small multilingual token-classification model (54 languages) runs in a C engine through dart:ffi; nothing is sent anywhere. Same models, options and spans as the npm package @newmean-ai/pii.

dependencies:
  newmean_pii: ^1.2.0
import 'package:newmean_pii/newmean_pii.dart';

final pii = await NewmeanPii.create(size: 'medium');
final r = await pii.redact('제 메일은 kim@example.com, 전화는 010-1234-5678입니다');
// r.text: "제 메일은 [EMAIL], 전화는 [PHONE]입니다"

Android (arm64-v8a, armeabi-v7a, x86_64), iOS (device and simulator), macOS, Linux and Windows. Needs Flutter 3.38 or Dart 3.10 or later: the package's build hook compiles the engine for each target with the platform's C compiler (Xcode, the Android NDK, clang or gcc, MSVC), so there is no prebuilt binary and no plugin setup. For the web, use the npm package.

Models #

size file notes
nano 2.6 MB one shared layer applied 4 times, rank-32 embeddings
small 7.1 MB 4 layers, rank-64 embeddings
medium (default) 11.3 MB 6 layers, rank-192 embeddings
large 15.5 MB 6 layers, full (pruned-vocabulary) embeddings

Plus a 0.8 MB tokenizer shared by all sizes. Every file is checked against the size and SHA-256 pinned in the package before use, wherever it comes from:

  • Downloaded once (default) from Hugging Face (newmean-ai/pii-<size>, tag v1.1.0) into cacheDir. The default is ~/Library/Caches/newmean-pii on iOS and macOS, ~/.cache/newmean-pii on Linux, %LOCALAPPDATA%\newmean-pii on Windows and the app's temporary directory on Android; pass cacheDir (for example getApplicationSupportDirectory() of path_provider) to keep the files elsewhere. modelUrl points at a self-hosted copy of the model folder. Android apps need the INTERNET permission for the download.

  • Bundled as Flutter assets, read with readFile:

    flutter:
      assets:
        - assets/pii-nano/tokenizer.web.json
        - assets/pii-nano/onnx/model_q4.onnx
    
    import 'package:flutter/services.dart' show rootBundle;
    
    final pii = await NewmeanPii.create(
      size: 'nano',
      readFile: (path) async => (await rootBundle.load('assets/pii-nano/$path')).buffer.asUint8List(),
    );
    
  • A local folder with the Hugging Face layout (modelDir), or bytes you already hold (NewmeanPii.fromBytes).

No model finds every piece of personal information. The technical report lists miss and over-masking rates per language and dataset; treat the output as a strong first pass, not a guarantee.

Labels #

PERSON, EMAIL, PHONE, ADDRESS, ID_NUMBER, FINANCIAL, ORG, USERNAME, URL, DATE_OF_BIRTH, SECRET, and two level 2 labels for indirect identifiers: PERSON_L2 (a surname with a title, a nickname, initials) and URL_L2 (public profile or page URLs). Pass labels: level1Labels to leave level 2 visible.

API #

NewmeanPii.create({
  String size = 'medium',      // nano, small, medium, large
  String? variant,             // 'q4' or 'q4e'; default q4e for large/medium, q4 for small/nano
  double sensitivity = 0,      // > 0 masks more, < 0 masks less (about −1..1)
  Iterable<String>? labels,    // labels to mask; default all (piiLabels)
  bool regex = false,          // also mask a few patterns (email, URL, card/account, phone, Korean resident number);
                               // default false (model only): almost no extra coverage, double the over-masking
  bool keepEmoji = false,      // true: the model also reads emoji (1.1 behaviour); default: never read or masked
  String? modelDir,            // local folder: tokenizer.web.json, onnx/model_<variant>.onnx
  Future<Uint8List> Function(String path)? readFile,  // e.g. Flutter assets
  Uri? modelUrl,               // self-hosted model folder (ending with "/"); default Hugging Face
  String? cacheDir,            // where downloads are kept
  bool cache = true,           // keep downloaded files
  bool verify = true,          // check size and SHA-256 of every file
  void Function(PiiProgress)? onProgress,
}) → Future<NewmeanPii>
NewmeanPii.fromBytes(onnx: ..., tokenizer: ..., size: ..., variant: ...) → Future<NewmeanPii>

pii.detect(text)              // → Future<List<PiiSpan>> {start, end, label, source}, sorted, non-overlapping
pii.redact(text, mode: RedactMode.tag)  // tag → [EMAIL], mask → *****, blank → removed; or replace: (span, original) => ...
                                        // → Future<PiiRedaction> {text, spans}
pii.detectSync(text), pii.redactSync(text)  // the same on the calling isolate
pii.detectTable(text), pii.redactTable(text) // table mode (see Tables); detectTableSync, redactTableSync
pii.sensitivity = 0.3          // or setSensitivity(0.3); no reload
pii.dispose()

regexSpans(text), applyRedaction(text, spans, mode: ...)  // the pattern layer and the redaction modes on their own
modelFile(size, file)          // published path, size and SHA-256 of 'q4', 'q4e' or 'tokenizer'
  • Offsets are UTF-16 code units, the indices of Dart's String: text.substring(span.start, span.end). Spans are widened to whole grapheme clusters, so an emoji, flag or combining sequence is masked whole or kept whole. source is "model", "regex", "model+regex" or "table". mask writes one mask character per code point.
  • Emoji: by default emoji are taken out of the text the model reads, so the model does not read them as PII; offsets still refer to the input, and an emoji inside a span splits it in two. keepEmoji: true gives the model the text as given (1.1 behaviour).
  • Isolates: detect and redact run the model in a background isolate (Isolate.run), so the UI never blocks; the overhead is about 0.5 ms per call. One loaded model is shared by all calls and calls may overlap: several detect calls at once run in parallel on different cores. Inside your own background isolate, detectSync avoids the hop.
  • Memory: a loaded model takes about the size of its file plus the tokenizer; dispose() frees it after running calls finish (otherwise it is freed when the object is garbage collected).

Tables #

pii.detectTable(String text, {String delimiter = 'auto', bool header = true, bool vote = true,
    String context = 'none'})
    → Future<List<PiiSpan>>
pii.redactTable(String text, {String delimiter = 'auto', bool header = true, bool vote = true, String context = 'none',
    RedactMode mode = RedactMode.tag, String maskChar = '*', String Function(PiiSpan span, String original)? replace})
    → Future<PiiRedaction>
pii.detectTableSync(...), pii.redactTableSync(...)  // the same on the calling isolate

Table mode reads a CSV, TSV, semicolon-separated or markdown pipe table as one text and clips every span to a cell value: delimiters, quotes and line breaks are never masked, so the output is still a valid table. delimiter is 'auto' (detected), ',', '\t', ';' or 'markdown' (anything else throws ArgumentError); quoted fields follow RFC 4180. With vote, a column of short values is masked whole when the model finds names, emails, phone numbers or usernames in at least 80% of its non-empty cells (and at least 4; columns with fewer than 5 non-empty cells do not vote); those spans have source "table". Free-text columns (median value over 40 characters or 4 words) do not vote, placeholders (N/A, -, none, null, 없음) are skipped, an email column needs @ and a phone column 6 or more digits. With header, the first row is masked where the model finds PII but never voted on. With context: 'header' (default 'none'; anything else throws ArgumentError) and a header row, each non-empty data cell of a column whose non-empty values are at least 80% distinct is also read on its own as "

0
likes
0
points
1.37k
downloads

Publisher

verified publishernewmean.ai

Weekly Downloads

Detect and mask personal information (PII) in text on the device, in 54 languages, with the newmean-pii models (dart:ffi over a small C engine; nothing is sent anywhere).

Homepage
Repository (GitHub)
View/report issues

Topics

#privacy #pii #nlp #ffi #redaction

License

unknown (license)

Dependencies

code_assets, crypto, ffi, hooks, logging, native_toolchain_c

More

Packages that depend on newmean_pii