Research notes · Legal NLP

Can Transformers Reliably Anonymize Legal Documents?

What we learned building LegNER, a legal-domain BERT model for named entity recognition — and why a 99% F1 score is where the anonymization question starts, not where it ends.

TL;DR

We adapted BERT-base to legal language — 1,245 added legal vocabulary terms, masked-language-model pre-training on EUR-Lex text, and span-aligned token classification — and trained it on 1,542 EUR-Lex judgments annotated for six entity types.

On 232 held-out judgments, LegNER reached 99.4% entity-level F1 (precision 99.5%, recall 99.3%). The strongest baseline, Legal-BERT, reached 93.6% on the same split. In a manual review of 12 anonymized documents, repeated mentions were replaced consistently 98.7% of the time, and legal experts rated readability 4.8 / 5.

What this does not show: that the model is safe to deploy for redaction. The scores come from one source, one language and single training runs, the anonymization review is small, and mention-level F1 does not measure whether a whole document still identifies someone. High recognition accuracy is necessary for reliable anonymization, but it is not sufficient.

Contents
  1. Why legal text breaks general NER
  2. Building the corpus
  3. Adapting BERT to legal language
  4. Does domain adaptation help?
  5. How fast are boundaries learned?
  6. Which entities are hardest?
  7. Is the anonymized text usable?
  8. Does 99% F1 mean safe redaction?
  9. Where it is likely to fail
  10. What we learned
  11. Limitations and open questions
  12. Paper, citation and credits

Courts publish their decisions so that the law can be read, cited and criticized. Those same decisions name the people involved: litigants, witnesses, lawyers, sometimes children. Before a judgment can be released, someone has to find every identifying mention and replace it, without destroying the legal reasoning around it.

That sounds like a solved problem. Named entity recognition (NER) models have tagged people, organizations and places in news text for two decades [5]. But a judgment is not a news article. Here is a typical sentence from EU legal text, with the entities our model is asked to find:

Regulation (EU) 2023/1234 of the European Parliament and of the Council of 12 July 2023 on digital identity standards within the European Union, repealing Directive 95/46/EC.

Figure 1. Entity tagging in a legal sentence: statute references (LAW), institutions (ORG) and a date (DATE). None of these should be masked, but all of them have to be recognized, so that a system can tell legal structure apart from personal data. Recreated as text from Figure 1 of Karamitsos et al. (2025), CC BY 4.0; colours changed.

Most of the entities in that sentence are not private at all. They are the legal content. An anonymization system therefore has two jobs: recognize everything, then mask only what identifies a person. If the first step fails on a name, the document leaks. If it confuses a regulation with an organization, the masking policy can no longer be trusted.

In this post I go through LegNER, a model my coauthors and I built for this problem [1], organized around two questions:

  1. Does adapting a transformer to legal language improve legal entity recognition over existing general-purpose and legal-domain models?
  2. Does high recognition accuracy translate into reliable redaction?

The short answers: the first is a clear yes in our setting, and the second is “not automatically”, for reasons that are worth spelling out.

Why legal text breaks general-purpose NER

Standard NER benchmarks such as CoNLL-2003 define four entity types: person, organization, location and miscellaneous [5]. Legal text needs more. A judgment refers to statutes (“Article 6(1) of Regulation 2016/679”), to other cases (“C-123/20”), to institutions with long compositional names, and to the same party under several roles (“the applicant”, “the claimant”, “Ms Thompson”). Sentences run for many clauses, and entities nest inside one another: “the Court of Justice of the European Union” contains “the European Union”.

There is also a quieter problem at the level of the vocabulary. BERT splits text into WordPiece units drawn from a fixed vocabulary [2]. Legal identifiers are rarely in that vocabulary, so they arrive at the model already broken into fragments:

GDPRgdp##r
Regulation (EU) 2023/1234regulation(eu)202##3/123##4
C-123/20c-123/20
pseudonymisationpseudonym##isation
Court of Justice of the European Unioncourtofjusticeoftheeuropeanunion
Figure 2. How the general-domain bert-base-uncased WordPiece vocabulary (30,522 entries, the vocabulary LegNER starts from) splits legal strings. Dashed pieces continue the previous word. “GDPR” becomes “gdp” + “##r”, a case number becomes five unrelated symbols, and a seven-token court name must be labelled as one entity. Our illustration for this post, produced with the public tokenizer vocabulary. LegNER’s added legal terms are not public, so this shows the problem the vocabulary extension targets, not LegNER’s own tokenization.

A model can still learn to recognize “c - 123 / 20” as a case reference, but it has to learn it from context, using a vocabulary built for Wikipedia and books. That is the gap domain adaptation is meant to close.

Building a corpus where entities carry legal meaning

We built the dataset from EUR-Lex, the EU’s official legal database [4]. We queried court decisions published between 2015 and 2023 on data protection, administrative law and competition policy. We kept only documents with stable identifiers, complete rulings and machine-readable XML, then removed duplicates and purely procedural notes. That left 1,542 full-text judgments, used in their English versions.

Each judgment was annotated for six entity types: PERSON, ORGANIZATION, LOCATION, DATE, LAW and CASE_REFERENCE. Annotation ran in two stages. About 600 documents (39%) were annotated in full by trained legal experts. The remaining 942 were pre-labelled automatically, using legal lexicons, regular expressions and weak NER baselines, and every suggestion was then manually checked and corrected. The corpus contains roughly 34,000 sentences, 1.2 million tokens and 287,000 entity mentions:

Annotated mentions per entity type

Annotated mentions per entity type in the LegNER corpus Bar chart. PERSON 72,400; DATE 64,900; ORGANIZATION 51,800; LOCATION 42,300; LAW 33,500; CASE_REFERENCE 22,100. PERSON: 72,400 mentions PERSON 72,400 DATE: 64,900 mentions DATE 64,900 ORGANIZATION: 51,800 mentions ORGANIZATION 51,800 LOCATION: 42,300 mentions LOCATION 42,300 LAW: 33,500 mentions LAW 33,500 CASE_REFERENCE: 22,100 mentions CASE_REFERENCE 22,100 Annotated mentions per entity type in the LegNER corpus Bar chart. PERSON 72,400; DATE 64,900; ORGANIZATION 51,800; LOCATION 42,300; LAW 33,500; CASE_REFERENCE 22,100. PERSON: 72,400 mentions PERSON 72,400 DATE: 64,900 mentions DATE 64,900 ORGANIZATION: 51,800 mentions ORGANIZATION 51,800 LOCATION: 42,300 mentions LOCATION 42,300 LAW: 33,500 mentions LAW 33,500 CASE_REFERENCE: 22,100 mentions CASE_REFERENCE 22,100
Figure 3. Entity mentions in the LegNER corpus. People and dates are the most frequent; case references the least. Every entity type has at least 22,000 examples. Plotted from Table 1 of Karamitsos et al. (2025).

Annotations are stored as character-offset spans rather than word labels. This matters later, when the text is cut into subword tokens whose boundaries rarely match word boundaries:

{ "text": "On March 15, 2023, Judge Alice Thompson ruled in favor of the European Commission in case C-123/20 concerning GDPR compliance in Berlin.",
  "entities": [
    { "type": "DATE",           "text": "March 15, 2023" },
    { "type": "PERSON",         "text": "Alice Thompson" },
    { "type": "ORGANIZATION",   "text": "European Commission" },
    { "type": "CASE_REFERENCE", "text": "C-123/20" },
    { "type": "LAW",            "text": "GDPR" },
    { "type": "LOCATION",       "text": "Berlin" } ] }

The illustrative annotation from the paper, shortened here: each entity also stores its start and end character offsets.

We split the judgments by document, stratified so that every entity type appears in proportion: 1,079 for training, 231 for validation (early stopping and tuning) and 232 for the final test. Splitting by document rather than by sentence keeps sentences from the same case out of both training and test.

Adapting BERT to legal language

LegNER starts from BERT-base: 12 encoder layers, a hidden size of 768, 12 attention heads and about 110 million parameters [2]. Domain adaptation enters at three points.

  • Vocabulary. The 30,522-entry vocabulary was extended with 1,245 legal terms taken from EUR-Lex and curated legal dictionaries. This targets the fragmentation shown in Figure 2.
  • Pre-training. Masked language modelling on unannotated EUR-Lex text teaches the encoder how statutes, citations and institutions tend to co-occur before it sees a single label.
  • Span-aligned fine-tuning. The model is trained as a token classifier with BIO tags. When a word is split into several subword pieces, the first piece inherits the word’s tag and the rest are marked as continuations, so an entity boundary never falls inside a word.

Under BIO tagging, “Judge Alice Thompson” contributes B-PERSON I-PERSON I-PERSON if the title is part of the span, and every other token is O. The whole system sits inside the loop shown in Figure 4. Documents flow into pre-training, models are fine-tuned on the corrected annotations, and their errors are fed back into the annotation guidelines when performance is not yet acceptable.

Setup
  • Backbone: BERT-base, 12 layers, hidden size 768, 12 heads (~110M parameters)
  • Vocabulary: 30,522 WordPiece entries + 1,245 legal terms
  • Objective: token classification over BIO tags, cross-entropy loss
  • Optimizer: AdamW, learning rate 3×10−5 with linear decay, weight decay 0.01
  • Training: batch size 16, 8 epochs, early stopping on validation F1, max sequence length 512
  • Hardware: one NVIDIA A100 (Google Colab Pro)
Flow diagram. Top: documents from the EUR-Lex database feed a set of pre-trained models (Legal-BERT, RoBERTa-Legal, ContractNLI, SpanBERT-Legal, LegalNER.pt and the proposed legal NER model), whose outputs go to performance evaluation by accuracy, recall, precision and F1. A decision diamond asks whether the results are acceptable: if yes, legal documents are labelled; if no, a feedback arrow returns to the transfer-learning process. Bottom: the transfer-learning process creates NER labels, corrects the dataset according to the entity definitions, and fine-tunes the same set of models before evaluation.
Figure 4. The LegNER pipeline. The upper band is the one-way data flow: corpus, pre-training, evaluation. The lower band is the feedback loop: labelling, correction and fine-tuning, repeated until evaluation results are accepted. Every baseline goes through the same pipeline as the proposed model. Figure 2 from Karamitsos et al. (2025), Frontiers in Artificial Intelligence, reproduced under CC BY 4.0.

We evaluate with strict span matching: a prediction counts only if both its boundaries and its type are correct. A model that tags “Court of Justice” but misses “of the European Union” gets no credit for that entity. Precision, recall and F1 are computed over entities:

$$P=\frac{TP}{TP+FP},\qquad R=\frac{TP}{TP+FN},\qquad F_1=\frac{2PR}{P+R}.$$

For anonymization, recall is the number that matters most. A false positive masks a word that did not need masking. A false negative leaves a name in a published judgment.

What the experiments show

Question 1

Does domain adaptation beat existing legal language models?

The first thing to establish was whether all this adaptation buys anything over models that are already legal-domain. We compared LegNER with five baselines that each represent a different design choice: Legal-BERT, pre-trained on legal corpora [3]; a legal RoBERTa, with byte-pair tokenization [8]; SpanBERT, with span-level pre-training [7]; a ContractNLI model trained on contracts [6]; and LegalNER.pt, a BERT model trained on Portuguese legal text. Every model was fine-tuned on the same 1,079 training judgments and scored on the same 232 test judgments.

Setup
  • Test set: 232 held-out judgments, never used for training or tuning
  • Metric: entity-level F1 under strict span matching
  • Baselines: fine-tuned on the same split; optimizer settings follow Table 2 of the paper and differ by model (learning rates 1×10−5–2×10−5, batch sizes 16–32)
  • Runs: one reported result per model, without repeated seeds or confidence intervals
Entity-level F1 on the LegNER test set, by model Dot plot. LegNER 99.4; Legal-BERT 93.6; RoBERTa-Legal 93.1; SpanBERT-Legal 91.9; ContractNLI 90.8; LegalNER.pt 89.3. Axis from 85 to 100 percent. 86 88 90 92 94 96 98 100 Entity-level F1 (%) LegNER: F1 99.4% (precision 99.5%, recall 99.3%) LegNER 99.4 Legal-BERT: F1 93.6% (precision 94.2%, recall 93.1%) Legal-BERT 93.6 RoBERTa-Legal: F1 93.1% (precision 93.8%, recall 92.4%) RoBERTa-Legal 93.1 SpanBERT-Legal: F1 91.9% (precision 92.5%, recall 91.3%) SpanBERT-Legal 91.9 ContractNLI: F1 90.8% (precision 91.1%, recall 90.5%) ContractNLI 90.8 LegalNER.pt: F1 89.3% (precision 89.8%, recall 88.9%) LegalNER.pt 89.3 Entity-level F1 on the LegNER test set, by model Dot plot. LegNER 99.4; Legal-BERT 93.6; RoBERTa-Legal 93.1; SpanBERT-Legal 91.9; ContractNLI 90.8; LegalNER.pt 89.3. Axis from 85 to 100 percent. 85 90 95 100 Entity-level F1 (%) LegNER: F1 99.4% (precision 99.5%, recall 99.3%) LegNER 99.4 Legal-BERT: F1 93.6% (precision 94.2%, recall 93.1%) Legal-BERT 93.6 RoBERTa-Legal: F1 93.1% (precision 93.8%, recall 92.4%) RoBERTa-Legal 93.1 SpanBERT-Legal: F1 91.9% (precision 92.5%, recall 91.3%) SpanBERT-Legal 91.9 ContractNLI: F1 90.8% (precision 91.1%, recall 90.5%) ContractNLI 90.8 LegalNER.pt: F1 89.3% (precision 89.8%, recall 88.9%) LegalNER.pt 89.3
Figure 5. Entity-level F1 on the test set. LegNER leads Legal-BERT, the next-best model, by 5.8 points. The Portuguese-trained LegalNER.pt trails by about 10 points. The axis starts at 85%. Plotted from Table 3 of Karamitsos et al. (2025).
Table 1. Comparative evaluation on the test set (Table 3 of the paper). Speed is documents per second.
ModelAccuracyPrecisionRecallF1Docs/sParams
LegNER99.999.599.399.412.3110M
Legal-BERT97.894.293.193.610.1110M
RoBERTa-Legal97.593.892.493.19.8125M
SpanBERT-Legal96.992.591.391.98.9125M
ContractNLI96.291.190.590.88.6110M
LegalNER.pt95.489.888.989.311.4110M

What we observed. LegNER had the highest precision, recall and F1, with precision and recall balanced (99.5 vs 99.3). It was also the fastest model in this setup, at 12.3 documents per second against 8.6–11.4 for the baselines, at a comparable parameter count. Among the baselines, the two models pre-trained on legal corpora, Legal-BERT and RoBERTa-Legal, came first, and the Portuguese model came last.

How we read it. Two things seem to matter. Vocabulary and pre-training close to the target documents help, and the Portuguese model’s 10-point gap suggests that “legal” is not one domain: legal language from another jurisdiction and language transfers only partly. The accuracy column, by contrast, says little. Most tokens in a judgment are outside any entity, so token-level accuracy sits above 95% for every model and hides the differences F1 exposes.

What this does not establish

The paper has no ablation, so we cannot say how much of the 5.8-point gain comes from the vocabulary, the pre-training or the span alignment. Each model has one reported run, and baseline hyperparameters were not tuned identically, so small differences between baselines should not be over-read. The throughput protocol (hardware, batch size, document length) is not described in detail, so the speed figures compare models within this setup only.

Question 2

How quickly does the model learn where legal entities begin and end?

A final score does not show whether training was stable, so we also looked at how the metrics moved from epoch to epoch. The interesting part is the first two epochs, where precision and recall move in opposite directions.

Evaluation metrics after each epoch (%)

Precision, recall and F1 after each of eight training epochs Line chart. Precision: 85.2, 98.5, then 99.5 from epoch 3 (99.6 at epoch 8). Recall: 99.5, 92.3, then 99.3 from epoch 3 (99.7 at epoch 8). F1: 91.8, 95.3, then 99.4 from epoch 3 onward. 84 88 92 96 100 1 2 3 4 5 6 7 8 Epoch Epoch 1 — Precision: 85.2% Epoch 2 — Precision: 98.5% Epoch 3 — Precision: 99.5% Epoch 4 — Precision: 99.5% Epoch 5 — Precision: 99.5% Epoch 6 — Precision: 99.5% Epoch 7 — Precision: 99.5% Epoch 8 — Precision: 99.6% Epoch 1 — Recall: 99.5% Epoch 2 — Recall: 92.3% Epoch 3 — Recall: 99.3% Epoch 4 — Recall: 99.3% Epoch 5 — Recall: 99.3% Epoch 6 — Recall: 99.3% Epoch 7 — Recall: 99.3% Epoch 8 — Recall: 99.7% Epoch 1 — F1: 91.8% Epoch 2 — F1: 95.3% Epoch 3 — F1: 99.4% Epoch 4 — F1: 99.4% Epoch 5 — F1: 99.4% Epoch 6 — F1: 99.4% Epoch 7 — F1: 99.4% Epoch 8 — F1: 99.4% Precision 85.2 Recall 92.3 F1 91.8 ≈ 99.4 Precision, recall and F1 after each of eight training epochs Line chart. Precision: 85.2, 98.5, then 99.5 from epoch 3 (99.6 at epoch 8). Recall: 99.5, 92.3, then 99.3 from epoch 3 (99.7 at epoch 8). F1: 91.8, 95.3, then 99.4 from epoch 3 onward. 84 88 92 96 100 1 2 3 4 5 6 7 8 Epoch Epoch 1 — Precision: 85.2% Epoch 2 — Precision: 98.5% Epoch 3 — Precision: 99.5% Epoch 4 — Precision: 99.5% Epoch 5 — Precision: 99.5% Epoch 6 — Precision: 99.5% Epoch 7 — Precision: 99.5% Epoch 8 — Precision: 99.6% Epoch 1 — Recall: 99.5% Epoch 2 — Recall: 92.3% Epoch 3 — Recall: 99.3% Epoch 4 — Recall: 99.3% Epoch 5 — Recall: 99.3% Epoch 6 — Recall: 99.3% Epoch 7 — Recall: 99.3% Epoch 8 — Recall: 99.7% Epoch 1 — F1: 91.8% Epoch 2 — F1: 95.3% Epoch 3 — F1: 99.4% Epoch 4 — F1: 99.4% Epoch 5 — F1: 99.4% Epoch 6 — F1: 99.4% Epoch 7 — F1: 99.4% Epoch 8 — F1: 99.4% P 85.2 R 92.3 F1 91.8 99.4
Show data
EpochAccuracyPrecisionRecallF1Loss
199.385.299.591.80.022
299.998.592.395.30.001
399.999.599.399.40.0005
499.999.599.399.40.0005
599.899.599.399.40.0002
699.499.599.399.40.0005
799.999.599.399.40.0009
899.999.699.799.40.0006
Figure 6. Evaluation metrics after each of eight training epochs. Epoch 1 over-predicts entities (high recall, low precision). Epoch 2 over-corrects (precision up, recall down). From epoch 3 on, all three settle near 99.4%. Plotted from Table 4 of Karamitsos et al. (2025), all values as published.

What we observed. Precision rose from 85.2% to 98.5% between the first and second epochs while recall fell from 99.5% to 92.3%. By epoch 3 both had recovered to 99.5% and 99.3%, and F1 stayed at 99.4% for the remaining epochs. The loss fell from 0.022 to 0.001 after the second epoch and stayed below 0.001.

How we read it. The pattern is what boundary learning should look like. Early on the model marks too much as entities, then becomes conservative, then finds where spans start and stop. The flat curves after epoch 3 suggest that eight epochs were more than enough, which fits early stopping on validation F1. What the curves cannot tell us is how the model behaves on documents unlike the training distribution. A plateau at 99.4% on in-distribution data is a statement about this corpus.

Question 3

Which legal entities are hardest to recognize?

An aggregate score can hide a weak class, and for anonymization the classes are not equally important. Missing a date is a nuisance. Missing a name is a disclosure. So we broke the test results down by entity type.

Table 2. Entity-wise results on the test set (Table 5 of the paper), sorted by F1.
Entity typePrecisionRecallF1Role in anonymization
DATE99.499.699.5often masked (quasi-identifier)
CASE_REFERENCE98.999.299.0usually kept (legal structure)
PERSON98.799.198.9masked (direct identifier)
LOCATION98.397.998.1often masked (quasi-identifier)
LAW97.898.398.0kept (legal structure)
ORGANIZATION97.596.897.1depends on the organization

What we observed. Dates were the easiest class (99.5% F1), followed by case references (99.0%) and people (98.9%). Organizations (97.1%) and statutes (98.0%) were the hardest. Organization recall, at 96.8%, is the lowest single number in the table.

How we read it. The hard classes are the long, compositional ones. “European Commission Directorate-General for Competition” can be cut in several plausible places, and statutes are cited in many formats (“Directive 95/46/EC”, “Article 6(1)(f)”, “the GDPR”). Under strict matching, a boundary error is a full miss. Dates and case numbers follow regular patterns, which is presumably why they are easiest. The last column is ours, not the paper’s. It is a reminder that what gets masked is a policy decision made after recognition. For an organization, it depends on whether it identifies a private party or is an institution like the Commission.

Reading the two tables together

The per-entity precisions here range from 97.5% to 99.4%, while the aggregate precision in Table 1 is 99.5%. A pooled (micro-averaged) precision over the same set of predictions would fall inside the per-entity range, so the two tables were presumably computed under different aggregation or matching settings. The paper does not specify which. We report both as published and would not compare them digit by digit.

Question 4

Does accurate recognition produce usable anonymized text?

Recognition is only the first half of anonymization. The second half replaces each sensitive span with a placeholder, and two things can go wrong there that F1 does not measure. The same person can get different placeholders in different paragraphs, which makes the judgment unreadable. Or the replacement can damage the sentence enough that the legal reasoning no longer comes through. We therefore defined two anonymization-specific measures. The consistency rate is the share of replacements that agree with the placeholder already assigned to the same entity:

$$\text{Consistency rate}=\frac{\text{consistent replacements}}{\text{total replacements}}.$$

The second is readability: legal experts scored the anonymized documents on a five-point Likert scale, from 1 (incoherent) to 5 (fully coherent).

Original

On March 15, 2022, the plaintiff John Smith filed a complaint against Acme Corporation in the District Court of Brussels, represented by attorney Sarah Johnson from Legal Partners LLP.

Anonymized

On [DATE-1], the plaintiff [PERSON-1] filed a complaint against [ORGANIZATION-1] in the District Court of [LOCATION-1], represented by attorney [PERSON-2] from [ORGANIZATION-2].
Figure 7. The illustrative anonymization example from the paper. Six spans are replaced with numbered, type-preserving placeholders. The roles (“plaintiff”, “attorney”) and the court type stay, so the procedural story is still readable. Example text from Karamitsos et al. (2025), Section 6.5; entity highlighting added.

What we observed. In a manual review of 12 anonymized case documents, LegNER reached a consistency rate of 98.7%. Legal experts gave the anonymized documents an average readability score of 4.8 out of 5.

How we read it. Numbered, typed placeholders are a good compromise. “[PERSON-1] v [ORGANIZATION-1]” keeps the structure of an argument that bare black bars would destroy. But note what the example also shows: roles, the court type and the procedural posture all survive. That is deliberate, and it is also exactly the information that can re-identify a party in a small jurisdiction or a well-reported case.

What this does not establish

Twelve documents is a small sample. The paper does not report how many experts took part, how much they agreed, or a confidence interval for either number. Readability and consistency show that the output is usable. They do not show that it is anonymous.

Question 5 · our analysis

Does a 99% F1 score mean a document is safely redacted?

This last question goes beyond the paper, but it is the one a court or a data-protection officer would ask. NER metrics count mentions. A redaction succeeds or fails per document, and one surviving name is enough for it to fail.

A rough calculation shows why the distinction matters. Take the reported PERSON recall of 99.1%, so a miss rate of \(m = 0.009\) per mention. If a judgment contains \(n\) person mentions and misses were independent, the probability that at least one survives is

$$\Pr[\text{at least one name left unmasked}] \;=\; 1-(1-m)^{n}.$$
10 mentions8.6%
25 mentions20.2%
50 mentions36.4%
100 mentions59.5%
Figure 8. Probability that a document keeps at least one unmasked person mention, at a per-mention recall of 99.1% and assuming independent misses. This is a thought experiment, not a measured result: the paper does not report document-level leakage.

The independence assumption is wrong in both directions. Misses cluster: an unusual foreign name, an OCR-damaged paragraph or a name in a footnote tends to be missed every time it appears, so real documents fail less often than the formula says. But when they fail, they fail more completely. Consistent replacement also cuts both ways. It spreads a correct detection to every repetition of a name, and it can spread a miss just as easily. What the calculation does show is that mention-level recall in the high nineties does not imply document-level safety. The number that would settle the question is the share of test documents with no residual identifiers, a metric we did not report.

A second gap is conceptual. Masking names, organizations, places and dates removes direct identifiers. It does not remove quasi-identifiers, combinations of facts that point to one person. Under the GDPR, data that can still be attributed to a person using additional information is pseudonymised, not anonymous, and remains personal data [11]. Work on text anonymization makes the same point empirically: NER-based de-identification and anonymization are different tasks, and evaluating the latter needs annotations of what actually discloses identity in context [9][10].

Where the approach is likely to fail

The paper names a few recurring failure types. Most were identified through the feedback loop of Figure 4.

  • Very long, clause-heavy sentences. The remaining errors concentrate there. Sentence structure, more than vocabulary, seems to drive the difficulty.
  • Nested and compositional entities. “Court of Justice of the European Union” inside a longer reference, or multi-part directorate names, where a boundary error turns into a full miss under strict matching.
  • Ambiguous abbreviations that can name a court, a party or a statute depending on context.
  • Formatting noise. OCR artifacts, repeated headers and footers were filtered out during corpus construction. Scanned archives would bring them back.

Two further limits come from the evaluation design rather than from the model. All documents come from one source (EUR-Lex) in one language (English), so performance on national courts, other languages, contracts or scanned historical archives is untested. And 61% of the corpus was pre-labelled by lexicons, regular expressions and weak models before human correction. Human review limits the risk, but a model trained and tested on such labels can be partly rewarded for reproducing the pre-labellers’ conventions. Scoring the expert-only documents separately would show how large that effect is.

What we learned

  1. Domain adaptation helped, and “legal” is not one domain. Under the same split and the same strict metric, the adapted model beat every legal-domain baseline. The model trained on another jurisdiction’s language was furthest behind.
  2. The hard cases are long, compositional entities. Organizations and statutes, not names, set the floor of the per-entity results.
  3. Recognition and redaction are different questions. High mention-level F1 is necessary for safe anonymization but does not guarantee it. Document-level leakage and quasi-identifiers need their own evaluation.
  4. What to mask is a policy decision. The same recognizer serves privacy (persons, places, dates) and legal structure (statutes, case references). Separating the two decisions makes both easier to audit.

Limitations and open questions

  • Generalization. How does LegNER perform on national court decisions, other EU languages, and OCR-scanned documents?
  • Attribution of gains. How much of the improvement comes from the vocabulary extension, the domain pre-training and the span alignment individually? An ablation would answer this.
  • Variance. Repeated runs with different seeds, and confidence intervals on the test metrics, would show which differences between models are stable.
  • Annotation quality. The paper reports no inter-annotator agreement and no separate results for expert-annotated versus semi-automatically annotated documents.
  • Document-level privacy. What fraction of test documents is left with no direct identifier at all? How often do the remaining roles, dates and facts allow re-identification? Benchmarks built for text anonymization, such as TAB [10], are designed to measure this.
  • Deployment. Nothing here certifies GDPR compliance or production readiness. Any real redaction pipeline would need human review, especially for judgments involving minors or other vulnerable parties.

The paper

LegNER: a domain-adapted transformer for legal named entity recognition and text anonymization

Ioannis Karamitsos, Nikolaos Roufas, Khalil Al-Hussaeni, Andreas Kanavos

Frontiers in Artificial Intelligence, vol. 8, article 1638971. Published 6 November 2025. Open access, CC BY 4.0.

Code and data

No public code repository accompanies the paper. The source judgments are publicly available on EUR-Lex. The annotated corpus is not distributed with the article, whose data availability statement directs further inquiries to the corresponding author.

Credits

The research was carried out with Ioannis Karamitsos (Rochester Institute of Technology, Dubai), Khalil Al-Hussaeni (Rochester Institute of Technology, Dubai) and Andreas Kanavos (Ionian University, corresponding author). This post is my own account of the work. The interpretation in Question 5, the tokenization example and any errors of reading are mine.

Cite the paper

@article{karamitsos2025legner,
  title   = {{LegNER}: A Domain-Adapted Transformer for Legal Named
             Entity Recognition and Text Anonymization},
  author  = {Karamitsos, Ioannis and Roufas, Nikolaos and
             Al-Hussaeni, Khalil and Kanavos, Andreas},
  journal = {Frontiers in Artificial Intelligence},
  volume  = {8},
  pages   = {1638971},
  year    = {2025},
  doi     = {10.3389/frai.2025.1638971}
}

References

  1. I. Karamitsos, N. Roufas, K. Al-Hussaeni, A. Kanavos. LegNER: a domain-adapted transformer for legal named entity recognition and text anonymization. Frontiers in Artificial Intelligence 8:1638971, 2025. doi:10.3389/frai.2025.1638971
  2. J. Devlin, M.-W. Chang, K. Lee, K. Toutanova. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. NAACL-HLT, 2019. ACL Anthology
  3. I. Chalkidis, M. Fergadiotis, P. Malakasiotis, N. Aletras, I. Androutsopoulos. LEGAL-BERT: The Muppets straight out of Law School. Findings of EMNLP, 2020. ACL Anthology
  4. EUR-Lex: access to European Union law. eur-lex.europa.eu
  5. E. F. Tjong Kim Sang, F. De Meulder. Introduction to the CoNLL-2003 Shared Task: Language-Independent Named Entity Recognition. CoNLL, 2003. ACL Anthology
  6. Y. Koreeda, C. D. Manning. ContractNLI: A Dataset for Document-level Natural Language Inference for Contracts. Findings of EMNLP, 2021. ACL Anthology
  7. M. Joshi, D. Chen, Y. Liu, D. S. Weld, L. Zettlemoyer, O. Levy. SpanBERT: Improving Pre-training by Representing and Predicting Spans. TACL 8, 2020. ACL Anthology
  8. Y. Liu et al. RoBERTa: A Robustly Optimized BERT Pretraining Approach. arXiv:1907.11692, 2019. arXiv
  9. P. Lison, I. Pilán, D. Sánchez, M. Batet, L. Øvrelid. Anonymisation Models for Text Data: State of the art, Challenges and Future Directions. ACL, 2021. ACL Anthology
  10. I. Pilán, P. Lison, L. Øvrelid, A. Papadopoulou, D. Sánchez, M. Batet. The Text Anonymization Benchmark (TAB): A Dedicated Corpus and Evaluation Framework for Text Anonymization. Computational Linguistics 48(4), 2022. ACL Anthology
  11. Regulation (EU) 2016/679 (General Data Protection Regulation), Art. 4(5) and Recital 26. EUR-Lex