Legal operations and knowledge teams
People preparing confidential matter text for review, analysis or an external language model.
01 · NLP · Privacy engineering
A RoBERTa-based system for detecting sensitive facts in legal text, choosing the right privacy treatment, and keeping reversible identity mappings inside the user’s trust boundary.
Problem
Legal teams can use language models to summarise files or build chronologies, but those files contain names, case references and contextual details that may identify a person when combined. The system therefore has two jobs: detect direct identifiers reliably, and make the remaining re-identification risk visible.
People preparing confidential matter text for review, analysis or an external language model.
Recall is important because a missed direct identifier can defeat the privacy treatment; false positives still damage readability and utility.
In reversible mode, the mapping between real entities and stable labels never needs to leave the organisation.
Data
The project uses the Text Anonymization Benchmark: 1,268 annotated European Court of Human Rights judgments. Its annotations distinguish entity types such as people, organisations and case codes, and whether an item is a direct identifier, quasi-identifier or does not require masking.
The held-out evaluation contains 555 annotator-document rows covering 127 unique judgments. That distinction matters: presenting those 555 rows as 555 independent judgments would overstate the breadth of the test data.
Approach
I put each detector behind the same span interface, measured a general-purpose baseline, and fine-tuned RoBERTa on the legal labels. Detection feeds three distinct product modes:
Replace names, organisations, dates, IDs and case codes when direct disclosure is the immediate risk.
Broaden ages, locations and dates until the combination is less distinctive within the reference corpus.
Map entities to stable tokens so a model can follow who did what, then restore names locally if authorised.
Redaction removes visible identifiers. Anonymisation tries to reduce the chance that remaining information can single someone out. Pseudonymisation is reversible and therefore still personal data; it protects the external processing step, not every downstream use.
System architecture
Evaluation method
Detection: entity spans are scored with partial-match and exact-match precision, recall and F1 on the held-out annotations. Bootstrap confidence intervals quantify uncertainty. Partial matching gives credit when the right entity is found with an imperfect boundary; exact matching exposes those boundary errors.
Mosaic risk: after masking direct identifiers, the analysis selects increasingly many quasi-identifiers and asks when a record becomes unique within this corpus. This is a controlled corpus-uniqueness study, not a real-world re-identification probability.
Results
| Measure | Result | Interpretation |
|---|---|---|
| RoBERTa partial-match F1 | 0.8510 | Selected trained inference configuration |
| RoBERTa exact-match F1 | 0.7842 | More stringent span-boundary score |
| Unique after one selected quasi fact | 81.2% | Within this corpus only |
| Unique after three selected quasi facts | 96.5% | Within this corpus only |
| Never unique in the tested sequence | 0.9% | 12 of 1,268 judgments |
Failure cases & trade-offs
A union-style three-model ensemble scored 0.553 F1 because weak organisation predictions from one member polluted every vote. Diversity is not useful when one member is systematically poor on a label.
LegalBERT reached 0.849 F1, effectively tied with RoBERTa at 0.851. Legal-domain pretraining did not justify extra complexity for this task.
A post-processor intended to recover shorthand mentions changed macro recall by only 0.0001 because the detector already captured most cases where the rule could help.
Generalising more detail reduces uniqueness but can remove facts a summariser needs. The right threshold depends on the use case, adversary and review process.
Corpus uniqueness is evidence of mosaic risk, not proof of real-world identification. External data availability and attacker knowledge were not modelled.
What I would improve next
Demo & source
The hosted Hugging Face demo lets you compare transformation modes on supplied or synthetic text. Do not paste confidential information into a public demo.
The external application is loaded only after this panel is opened.