Core ML conversion and Swift package for
nationaldesignstudio/rampart,
a local PII token-classification model.
License: CC BY 4.0. See NOTICE.md for upstream Rampart model attribution and a summary of local changes.
rampart-ios-demo.mp4
The model is published as a GitHub Release asset instead of committed to Git. Swift package users can let the package download and cache it on first use:
let classifier = try await RampartCoreMLClassifier.downloaded()For repo-local workflows, download the same Core ML package, vocabulary, and config files before running the full test suite:
scripts/download_model.shThis writes:
artifacts/RampartTokenClassifier.mlpackage
artifacts/rampart-hf/vocab.txt
artifacts/rampart-hf/config.json
These files are ignored by Git.
To reproduce the Core ML package from the upstream ONNX model instead, run the converter:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements-convert.txt
python3 scripts/convert_rampart_to_coreml.pyThe converter downloads the upstream Rampart ONNX/tokenizer/config files into
artifacts/rampart-hf/ and writes the Core ML package to
artifacts/RampartTokenClassifier.mlpackage.
The RampartCoreML package provides a
WordPiece tokenizer,
the BERT-style subword tokenizer Rampart expects, plus a Core ML inference
wrapper and deterministic SSN recognizer.
import RampartCoreML
let classifier = try await RampartCoreMLClassifier.downloaded()
let result = try classifier.classify("Alex Rivera lives at 221B Baker Street.")
let piiTokens = result.predictions.filter { $0.label != "O" }
let deterministicMatches = result.deterministicDetectionsRun the Swift package checks with:
swift testTests that need local model artifacts skip until
scripts/download_model.sh or scripts/convert_rampart_to_coreml.py has been
run.
Run an ad hoc classification with:
swift run RampartCLI -- "my name is nick and my ssn is 111-111-1111"
swift run RampartCLI -- --all "my name is nick and my ssn is 111-111-1111"The CLI downloads the model artifacts on first run when the default local artifact paths are missing. It prints deterministic matches separately from model token predictions.
An example SwiftUI app lives at:
Examples/RampartExampleiOS/RampartExampleiOS.xcodeprojOpen the project and run the app. The example downloads and caches the model on first launch, then shows a text input, redacted-text preview, and structured detections.
After running the converter, compare ONNX and Core ML predictions with:
python3 scripts/validate_coreml_parity.pyThis repository is released under the Creative Commons Attribution 4.0
International license (CC-BY-4.0) to match the upstream Rampart model.