Skip to content
programasweightsPublic

About

Detect and type PII locally with one ProgramAsWeights neural program.

Topics

Resources

Stars

34 stars

Watchers

0 watching

Forks

Repository files navigation

PII detection with ProgramAsWeights

Detect and type personally identifiable information locally with one compiled ProgramAsWeights neural program.

Try the live demo

Python

pip install programasweights --extra-index-url https://pypi.programasweights.com/simple/
import json
import programasweights as paw

detect_pii = paw.function("73a0e38b8bbe3427cd1d")

text = "Name: Ada Lovelace\nEmail: ada@example.com\nPIN: 4821"
print(json.loads(detect_pii(text)))
[['Ada Lovelace', 'private_person'], ['ada@example.com', 'private_email'], ['4821', 'secret']]

The program downloads once and then runs locally. See example.py for the complete runnable example.

Output

The function returns a JSON array of [text, type] pairs. Each text is copied exactly from the input, and each type is one of:

private_person  private_email  private_phone  private_address  private_url
private_date    account_number secret         other_pii

Compile it yourself

The public program was compiled from the English specification in spec.txt. compile.py contains the complete compilation script:

from pathlib import Path
import programasweights as paw

program = paw.compile(
    Path("spec.txt").read_text().strip(),
    compiler="paw-ft-bs48",
    public=True,
)

print(program.id)

The published compilation used by this repository is:

73a0e38b8bbe3427cd1d

Compiling requires a PAW account and API key. Loading the published program by ID does not require recompiling it.

Results

On an untouched multilingual set of 512 AI4Privacy documents, the published program reached:

  • 0.8464 typed-character F1
  • 0.9085 label-agnostic extraction F1
  • 93.9% type accuracy on characters where the prediction and annotation overlap

We compared compact JSON, reversed JSON, JSON objects, and TSV outputs on a separate 497-document search set, froze the finalists, and selected the published program on another 522 documents before opening the sealed set. All source groups are disjoint. The original compact [text, type] JSON interface won; simplifying its specification did not generalize.

See RESULTS.md for every specification, compiled program, failed run, and benchmark result.

Reproduce the benchmark

The benchmark implementation is under scripts/, the parser and metrics are under src/paw_pii/, and tests are under tests/. Downloaded datasets, model checkpoints, and generated prediction files are intentionally excluded from Git.

PYTHONPATH=src python -m pytest -q

Citation

If you use this PII program in research, cite Program-as-Weights for the programming paradigm and Compile by Training for the training compiler used to build it.

Program-as-Weights: A Programming Paradigm for Fuzzy Functions

NeurIPS 2026 · Preprint

@inproceedings{zhang2026programasweights,
  title = {{Program-as-Weights: A Programming Paradigm for Fuzzy Functions}},
  author = {Zhang, Wentao and Hotsko, Liliana and Kim, Woojeong and Nie, Pengyu and Shieber, Stuart and Deng, Yuntian},
  booktitle = {The Fortieth Annual Conference on Neural Information Processing Systems},
  year = {2026},
  url = {https://arxiv.org/abs/2607.02512}
}

Compile by Training: Turning Natural-Language Specifications into Local Neural Functions

EMNLP 2026 System Demonstrations · Preprint

@inproceedings{deng-etal-2026-compile,
  title = {{Compile by Training: Turning Natural-Language Specifications into Local Neural Functions}},
  author = {Deng, Yuntian and Nie, Pengyu and Shieber, Stuart},
  editor = {Agrawal, Sweta and Abad, Alberto},
  booktitle = {Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing: System Demonstrations},
  month = oct,
  year = {2026},
  address = {Budapest, Hungary},
  publisher = {Association for Computational Linguistics},
  url = {https://aclanthology.org/2026.emnlp-demos.78/},
  doi = {10.18653/2026.emnlp-demos.78},
  pages = {830--839},
  ISBN = {979-8-89176-461-3}
}

About

Detect and type PII locally with one ProgramAsWeights neural program.

Topics

Resources

Stars

34 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages