A RU Habr author (NullPilot)·Practitioner post·

Discounts, deals and secrets: fine-tuning NER models to mask commercial terms (Скидки, сделки и секреты: как я дообучал NER-модели для маскирования)

A · Strong evidence Single-author Habr experiment with a fixed train/dev/test protocol, eleven systems compared on quality, masking errors, latency and memory, and data, configs and weights published; synthetic data only.

Summary based on the full text·Original: about 18 minutes to read

One of the Library's top reads

In short

A Habr post (17 November 2026) by NullPilot on teaching a small recogniser to mask non-public commercial terms in CRM notes and emails: negotiated prices, individual discounts, payment schedules and internal deal limits. The difficulty is context: "a 12% discount for all buyers" stays visible, "a 12% discount agreed with the client, non-public" must be masked. The author fine-tuned GLiNER2.5 (about 287M parameters, mDeBERTa encoder) on 6,500 synthetic texts and compared full fine-tuning, LoRA, DoRA, rsLoRA, QLoRA, training on labels from a large model, Qwen and Gemma with NER heads, and prompted instruction models. Code does the masking; the model only finds type and span.

Key numbers

  • 22.51% to 94.13%exact F1 of GLiNER2.5 (about 287M parameters) before and after full fine-tuning
  • 368 to 8 of 575public mentions wrongly masked, base model versus fine-tuned
  • 95.62%F1 after full fine-tuning on DeepSeek V4.1 Flash labels instead of the author's labels
  • 536 of 1,000prompted Gemma answers with invalid JSON
  • 93.78% vs 85.60%F1 on 8K-token documents with windowed versus whole-document processing

As reported by the source.

Read the original on habr.com

Russian·Web page·opens habr.com

What it reports

  • Full fine-tuning: exact F1 from 22.51% to 94.13%; fully hidden secrets from 504 to 1,171 of 1,275; false masks on public mentions from 368 to 8 of 575. Precision 97.24%, recall 91.22%.
  • LoRA trained 589,824 parameters (about 0.21% of the model), scored 3.44 points below full fine-tuning and hid 1,124 secrets with 4 public errors; three epochs took about 14 minutes at 3.64 GiB peak against 16.68 minutes and 7.04 GiB for full fine-tuning on an RTX 3090.
  • DoRA kept all 575 public mentions unmasked but hid 32 fewer secrets than full fine-tuning.
  • Training on DeepSeek V4.1 Flash labels (hard labels, train set only) gave F1 95.62% and 1,210 hidden secrets with 6 public errors. The first labelling instruction failed on repeated public values and was stopped after 1,096 answers.
  • Qwen3.5-4B and Gemma 4 E2B with NER heads reached 79.48% and 67.89% F1. Prompted instruction versions did worse: Gemma returned invalid JSON in 536 of 1,000 cases and fully hid 201 secrets; Qwen hid 782.
  • Median latency on an RTX 5090: about 17-19 ms for GLiNER variants, 32 ms for QLoRA, about 42 and 54 ms for Gemma and Qwen with NER heads.
  • On 1,000 long documents (1K to 8K tokens), windowed GLiNER on DeepSeek labels hid 471 of 480 secrets with 13 of 480 public errors. At 8K, windows gave 93.78% F1, about 405 ms and 1.49 GiB against 85.60%, 1,015 ms and 16.96 GiB for the whole document.

How they got it

The labelling policy (six entity types and span rules) was fixed before generating the corpus: 5,000 train, 500 dev and 1,000 test texts built by a compositional generator from 336 components, with families split across parts before assembly and duplicates checked. A quarter of documents contain no secrets, and contrast pairs show the same value as private and public. Checkpoints and thresholds were chosen on dev only. Masking quality is reported alongside strict F1: full coverage of each secret and any overlap with public mentions.

Limits

  • All data is synthetic and agent-written; no independent expert labelling and no real documents.
  • One hyperparameter set per method and one seed; the short test set was reused as variants were added.
  • The long-document set contains dependent variants of 40 families; the drop for Qwen and Gemma there mixes length and new texts.

Why it matters for companies

Before sending CRM or contract text to an external model, firms need to strip confidential terms that dictionaries and regular expressions cannot catch. The post shows that a small model, fine-tuned on a few thousand well-specified synthetic examples, can run in milliseconds on one GPU and beat prompted LLMs that break the output format. The design choices that matter are written policy first, separate counting of missed secrets and over-masked public text, and windowing for long documents.

Key passages in translation

Russian original

Фразы "Скидка 12% действует для всех покупателей" и "Согласовали с клиентом скидку 12%, условия непубличные" содержат одно значение, но маскировать его нужно только во втором случае.

English translation

The phrases "A 12% discount applies to all buyers" and "We agreed a 12% discount with the client, terms non-public" contain the same value, but it must be masked only in the second case.

Russian original

Таким образом, модель отвечает за поиск типа и границ, а JSON и итоговый текст с квадратными скобками формирует код.

English translation

So the model is responsible for finding the type and the boundaries, while the JSON and the final text with square brackets are produced by code.

Russian original

Это технические проверки генератора; независимой экспертной разметки в эксперименте не было.

English translation

These are technical checks of the generator; there was no independent expert labelling in the experiment.

Summary based on the full text. Read the original for the full argument and data.Read the original on habr.com

Tags

Same week

All of Week 47