@ai4privacy/ai4privacy
v0.1.0
Published
PII detection and masking using AI4Privacy transformer models
Maintainers
Readme
ai4privacy JavaScript module
A JavaScript/Node.js package for state-of-the-art PII detection and masking using AI4Privacy transformer models.
Features
- Protect Mode: Anonymize text by replacing detected PII with placeholders.
- Observe Mode: Get statistics and a detailed privacy mask of found PII without altering the original text.
- Reidentify: Restore original values from masked text using the replacements list.
- Multiple Models: English-specific, multilingual, and categorical detection.
- Tunable Sensitivity: Adjustable
scoreThresholdto balance detection accuracy.
Installation
npm install @ai4privacy/ai4privacyQuick Start
import { protect } from "@ai4privacy/ai4privacy";
const maskedText = await protect("Email me at [email protected] or call me at +41763223001.");
console.log(maskedText);
// Expected: Email me at [PII_1] or call me at [PII_2]Advanced Usage
Multilingual Support
import { protect } from "@ai4privacy/ai4privacy";
const masked = await protect("Je m'appelle Pierre et j'habite a Paris.", {
multilingual: true,
});
console.log(masked);
// Expected: Je m'appelle [PII_1] et j'habite a [PII_2]Categorical PII Detection
import { protect } from "@ai4privacy/ai4privacy";
const details = await protect("Senden Sie es an Eva Schmidt.", {
classifyPii: true,
verbose: true,
});
console.log(details.replacements.map((r) => r.label));
// Expected: ['GIVENNAME', 'SURNAME']Observe Mode
import { observe } from "@ai4privacy/ai4privacy";
const report = await observe("My name is Alice and I live in Berlin.", {
classifyPii: true,
});
console.log(JSON.stringify(report, null, 2));Reidentify
import { protect, reidentify } from "@ai4privacy/ai4privacy";
const result = await protect("Contact John at [email protected]", { verbose: true });
const original = reidentify(result.maskedText, result.replacements);
console.log(original);
// Expected: Contact John at [email protected]Adjusting Sensitivity
import { protect } from "@ai4privacy/ai4privacy";
// High precision
const highPrec = await protect("Maybe this is a name. Contact John.", {
scoreThreshold: 0.5,
});
// High sensitivity
const highSens = await protect("Maybe this is a name. Contact John.", {
scoreThreshold: 0.001,
});Disclaimer
AI4Privacy is trained on the world's largest open-source privacy dataset. For production use, please evaluate results carefully on your own datasets. For assistance, contact us at https://ai4privacy.com or email [email protected].
