PhEye ships four English person-name models, pii_en_xsmall, pii_en_small, pii_en_medium, and pii_en_large. A larger model costs more time and memory per request, and each has its own default confidence threshold. Which size and threshold suit you depends on your text, so this guide shows how to measure them on labeled samples of your own and what one such measurement looked like.
The numbers below were measured on one machine with a 30-sentence invented test set. They show the method and the kind of differences to look for. They are not benchmarks, and your results on your own hardware and text will differ.
The four sizes
PHEYE_MODEL | Image | Base model | Default threshold |
|---|---|---|---|
pii_en_xsmall | philterd/ph-eye:1.3.0-pii_en_xsmall | microsoft/deberta-v3-xsmall | 0.50 |
pii_en_small | philterd/ph-eye:1.3.0-pii_en_small | urchade/gliner_small-v2.1 | 0.90 |
pii_en_medium | philterd/ph-eye:1.3.0-pii_en_medium | urchade/gliner_medium-v2.1 | 0.70 |
pii_en_large | philterd/ph-eye:1.3.0-pii_en_large | urchade/gliner_large-v2.1 | 0.95 |
All four detect the label name. pii_en_small is the default image (philterd/ph-eye:latest). The base models are listed on each Hugging Face model card. The default thresholds differ because the models calibrate their scores differently, so a score of 0.9 from one size does not mean the same as 0.9 from another.
The published scores for these models, in Building the PhEye name models, come from the synthetic data they were trained on and are a ceiling. That post also notes that the xsmall model trades real-text recall for its size. Your own text is the test that counts.
Label a sample of your text
Write a JSON Lines file, one sentence or passage per line, with the names it contains in the order they appear. Include sentences with no names, and words that look like names but are not, since those are where false positives come from. Use real samples of your own text in a secure environment, or invented text that resembles it. The run below used 30 invented sentences with 27 names, seven of them with no names at all:
{"text": "Please forward the invoice to Toni Levine and copy Maria Gonzalez.", "names": ["Toni Levine", "Maria Gonzalez"]}
{"text": "Jordan said the Jordan account was closed last spring.", "names": ["Jordan"]}
{"text": "Our Ford pickup was towed to the shop on Elm Street.", "names": []}
{"text": "Dana Ford signed the release form at intake.", "names": ["Dana Ford"]}
{"text": "The intake form lists the referring provider as S. Kowalski.", "names": ["S. Kowalski"]}
For a larger labeled set and per-entity reports against a full redaction policy, use Philter Scope.
Run the four models
Start one container per size:
docker run -d --name pheye-xsmall -p 5001:5000 philterd/ph-eye:1.3.0-pii_en_xsmall
docker run -d --name pheye-small -p 5002:5000 philterd/ph-eye:1.3.0-pii_en_small
docker run -d --name pheye-medium -p 5003:5000 philterd/ph-eye:1.3.0-pii_en_medium
docker run -d --name pheye-large -p 5004:5000 philterd/ph-eye:1.3.0-pii_en_large
for port in 5001 5002 5003 5004; do
until curl -sf http://localhost:$port/status > /dev/null; do sleep 2; done
done
Each container keeps its model in memory. On this machine they used about 1.2, 1.6, 1.8, and 2.7 GiB (docker stats).
Measure detections at each threshold
This script, which uses only the Python standard library, sends every sentence to every model at five thresholds. It counts a name as found when a returned span overlaps it, and counts a returned span that overlaps no labeled name as an extra:
import json
import os
import statistics
import sys
import time
import urllib.request
# One PhEye container per model size, on these ports.
MODELS = {"xsmall": 5001, "small": 5002, "medium": 5003, "large": 5004}
THRESHOLDS = [0.3, 0.5, 0.7, 0.9, 0.95]
HOST = os.environ.get("PHEYE_HOST", "http://localhost")
def find(port, text, threshold):
body = json.dumps({"text": text, "threshold": threshold}).encode("utf-8")
request = urllib.request.Request(f"{HOST}:{port}/find", data=body,
headers={"Content-Type": "application/json"})
started = time.perf_counter()
with urllib.request.urlopen(request) as response:
entities = json.load(response)
return entities, (time.perf_counter() - started) * 1000
def overlaps(a, b):
return a[0] < b[1] and b[0] < a[1]
# Each line is {"text": ..., "names": [...]}, with the names in the order they appear.
rows = [json.loads(line) for line in open(sys.argv[1]) if line.strip()]
for row in rows:
row["gold"], position = [], 0
for name in row["names"]:
start = row["text"].index(name, position)
row["gold"].append((start, start + len(name)))
position = start + len(name)
print(f"{'model':8}{'threshold':>10}{'recall':>8}{'precision':>11}{'extra':>7}{'median ms':>11} missed")
for model, port in MODELS.items():
for row in rows[:3]:
find(port, row["text"], 0.5) # warm up
for threshold in THRESHOLDS:
found = names = predicted = extra = 0
times, missed = [], []
for row in rows:
entities, ms = find(port, row["text"], threshold)
times.append(ms)
spans = [(e["start"], e["end"]) for e in entities]
names += len(row["gold"])
predicted += len(spans)
for gold in row["gold"]:
if any(overlaps(gold, span) for span in spans):
found += 1
else:
missed.append(row["text"][gold[0]:gold[1]])
extra += sum(1 for span in spans if not any(overlaps(span, g) for g in row["gold"]))
precision = (predicted - extra) / predicted if predicted else 1.0
print(f"{model:8}{threshold:>10}{found / names:>8.2f}{precision:>11.2f}{extra:>7}"
f"{statistics.median(times):>11.0f} {', '.join(missed)}")
python3 measure.py labeled.jsonl
model threshold recall precision extra median ms missed
xsmall 0.3 1.00 0.97 1 35
xsmall 0.5 1.00 0.97 1 35
xsmall 0.7 1.00 0.97 1 34
xsmall 0.9 1.00 0.97 1 35
xsmall 0.95 1.00 0.97 1 35
small 0.3 1.00 0.93 2 58
small 0.5 1.00 0.97 1 54
small 0.7 1.00 0.97 1 53
small 0.9 1.00 0.97 1 52
small 0.95 0.96 0.96 1 52 S. Kowalski
medium 0.3 1.00 0.85 5 91
medium 0.5 1.00 0.90 3 95
medium 0.7 1.00 0.90 3 103
medium 0.9 0.96 0.93 2 129 S. Kowalski
medium 0.95 0.96 0.96 1 149 S. Kowalski
large 0.3 1.00 0.82 6 359
large 0.5 1.00 0.88 4 365
large 0.7 0.96 0.93 2 398 S. Kowalski
large 0.9 0.96 0.93 2 352 S. Kowalski
large 0.95 0.89 0.96 1 364 Sam, Thomas J. Mercer, S. Kowalski
Recall is the share of labeled names found, and precision the share of returned spans that overlap a labeled name.
Reading this run
- Every size found all 27 names at its default threshold except
large, which missed three at 0.95: a lone first name, a name with a middle initial, and an initial with a surname. - The second “Jordan” in “the Jordan account” came back from every model at every threshold. Some words are hard to tell from names without more context than one sentence gives.
- At low thresholds,
mediumandlargereturned place names such as “Lincoln Elementary” and “Victoria Station” as names. Raising the threshold removed most of them, and at the top of the range it began to cost names. - With 27 names, one name is about four points of recall. Differences this small cannot rank the models; they show where to look. A labeled set of a few hundred passages from your own text is what separates them.
Measure speed on realistic text
The sentences above are short. Time a passage closer to what you will send. This script sends the first 400 words of a file to each model 11 times and reports the median of the last 10:
import json
import re
import statistics
import sys
import time
import urllib.request
MODELS = {"xsmall": 5001, "small": 5002, "medium": 5003, "large": 5004}
WORD = re.compile(r"\w+(?:[-_]\w+)*|\S")
text = open(sys.argv[1]).read()
words = [m.span() for m in WORD.finditer(text)]
text = text[:words[399][1]] # the first 400 words
body = json.dumps({"text": text}).encode("utf-8")
for model, port in MODELS.items():
times = []
for _ in range(11):
request = urllib.request.Request(f"http://localhost:{port}/find", data=body,
headers={"Content-Type": "application/json"})
started = time.perf_counter()
urllib.request.urlopen(request).read()
times.append((time.perf_counter() - started) * 1000)
print(f"{model:8}{statistics.median(times[1:]):>8.0f} ms") # the first call is a warm-up
xsmall 220 ms
small 344 ms
medium 537 ms
large 1426 ms
This ran on an 11th Gen Intel Core i5-11400 (6 cores, 12 threads) using the CPU images, with other work running. Repeated runs differed by up to about 20 percent. Run it on the hardware you will deploy on, with your own text. PhEye also publishes -gpu images for each size.
Choosing
- Start from
pii_en_small, the default image and the model in Philter’s default policy, and its default threshold, then let your measurement move you. The model-building post recommendsmediumfor most uses, so measure both on your text. - Choose
xsmallwhere time or memory is tight, after checking its recall on your text, since its training notes say it gives up some real-text recall for its size. - Choose a larger size only when your measurement shows it finds names the smaller ones miss, and the time per request fits your volume.
- Choose the threshold for recall first. In redaction, a missed name is a leak, while an extra span is over-redaction that a reviewer can see. Pick the lowest threshold whose extras you can accept, and re-measure whenever your text or the model changes.
Set the threshold per request with the threshold field, as in Calling PhEye’s API directly. When Philter 4.0.1 or Phileas 4.5.0 calls a PhEye service, the request carries no threshold, so the service’s model default applies, and the policy’s phEyeConfiguration.threshold is ignored for a remote service. A policy’s per-label thresholds only drop spans below a higher value after they come back, so through a policy you can raise the cutoff above the model default but not lower it. To use a lower threshold, call PhEye directly, or use a model image whose default suits you.
Where to go next
- Calling PhEye’s API directly covers the request, the response, and text longer than the model reads.
- Self-hosted PII detection on your own hardware compares PhEye with running the model inside Phileas.
- Measure redaction accuracy with Philter Scope scores a whole redaction policy against your labeled documents.