Skip to content

narner/Rampart-CoreML

Repository files navigation

Rampart Core ML

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.

Demo

rampart-ios-demo.mp4

Model Artifacts

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.sh

This 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.py

The converter downloads the upstream Rampart ONNX/tokenizer/config files into artifacts/rampart-hf/ and writes the Core ML package to artifacts/RampartTokenClassifier.mlpackage.

Swift Package

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.deterministicDetections

Run the Swift package checks with:

swift test

Tests that need local model artifacts skip until scripts/download_model.sh or scripts/convert_rampart_to_coreml.py has been run.

CLI

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.

iOS Example

An example SwiftUI app lives at:

Examples/RampartExampleiOS/RampartExampleiOS.xcodeproj

Open 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.

Validation

After running the converter, compare ONNX and Core ML predictions with:

python3 scripts/validate_coreml_parity.py

License

This repository is released under the Creative Commons Attribution 4.0 International license (CC-BY-4.0) to match the upstream Rampart model.

About

No description, website, or topics provided.

Resources

License

Stars

8 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors