Skip to main content

DEMNE

Adaptive selection of the named-entity extraction method for frugal clinical NLP in oncology

CI License: MIT Python 3.10+

Paper (in preparation) · Quick start · How it works · Results

Not every entity in a French clinical report needs a transformer or an LLM. DEMNE measures each entity type in an annotated corpus with five metrics, then routes it to the least costly extraction tier predicted to be good enough: deterministic rules, a transformer-based model (TBM), or an LLM as a last resort. It addresses the performance, explainability and frugality trilemma by matching method complexity to measured extraction difficulty.

99.5 % 0.941 vs 0.358 0.866 59 · 92
of mentions routed to rules on an unseen AP-HP cohort (411/413) mean F1, rules vs fine-tuned DrBERT, same entities routing concordance on an unseen corpus (leave-one-corpus-out) oncology entity types · entity-corpus pairs

How it works

DEMNE routing decision graph

  1. Characterize. Five metrics are computed per entity type from BRAT annotations: templateability, lexical homogeneity, TF-IDF extractability, contextual risk (negation, uncertainty, contradiction), and a derived NER feasibility score.
  2. Route. A deterministic decision graph with four nodes and calibrated thresholds assigns a tier. Rules are chosen only on positive evidence and a safe context; otherwise the entity escalates to a transformer when enough labelled examples exist, and to an LLM as a last resort.
  3. Calibrate. The 17 free parameters are optimized with Optuna (NSGA-II) on routing concordance and an asymmetric cost that penalizes under-escalation twice as much as over-escalation. The calibration was first run by Akram Redjal; the resulting values ship in src/demne/data/demne_params.json, with a frozen copy in Results/demne_params_published.json. You can recalibrate on your own corpora with python main.py optimize_params (see Recalibration).

Every decision traces back to explicit metric values and thresholds, which makes the routing auditable (EU AI Act, Art. 12 and 14).

Results

Setting Concordance Notes
In-domain, 59 oncology entities (Protocol B) 0.954 cost-score 0.947, pooled accuracy 0.915 (54/59), no over-escalation
Leave-one-corpus-out 0.866 expected performance on an unseen corpus of the same domain
Best fixed-tier baseline (always RULES) 0.729 always-LLM reaches 0.148
Across domains (oncology, Quaero, MACCROBAT) 0.45 to 0.73 recalibrate for a new domain or language

External validation on 300 AP-HP CT-scan reports (colorectal and head-and-neck cancers), frozen configuration, no retuning: 6 of 7 tumour-response entities routed to rules (F1 0.892 to 0.972, mean 0.941), 1 to the LLM tier. A fine-tuned DrBERT trained on five of these entities reaches a mean F1 of 0.358.

RESULTS_CA_300

Limitations. The reference standard is small (92 entity types, 59 in oncology), the LLM tier was not evaluated end to end on the external cohort, and the contextual-risk gate did not bind on the evaluated corpora.

Quick start

git clone https://github.com/longeacc/DEMNE-Determination-of-Extraction-Methode-for-Named-Entity.git
cd DEMNE-Determination-of-Extraction-Methode-for-Named-Entity
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev,ner]"

# sanity check: environment + entities discovered
python main.py info

# run metrics + decision tree on a BRAT corpus (clinical data not distributed — supply your own)
python main.py evaluate --gs_dir <path-to-BRAT-corpus>

The REST annotation interface is available as a notebook via python main.py notebook (serves src/demne/REST_interface/REST.ipynb).

Recalibration

To retune the thresholds and weights on your own annotated corpora, place them under data/ in the working directory and run:

pip install -e ".[optimize]"
python main.py optimize_params --in_domain     # target-domain corpora only
python main.py optimize_params --all_corpora   # also include data/OFF_DOMAIN_CORPORA

data/OPT_CORPORA/ and data/TEST_CORPORA/ each hold one folder per corpus: BRAT .ann/.txt pairs plus a *_routing.csv with the expected tier (RULES/TBM/LLM) per entity type. The run reports concordance and cost-score before and after, then updates demne_params.json, which the CLI and the dashboard read. The previous file is backed up in Results/. To reproduce the published figures, restore Results/demne_params_published.json. Folder layout, CSV format and outputs: docs/OPTIMIZE_PARAMS.md.

Repository layout

Path Content
src/demne/ the package, see the module table below
main.py command line (metrics, evaluate, dashboard, optimize_params, …)
scripts/ maintenance scripts (manifest PDF)
dashboard/ Streamlit dashboard
tests/ unit tests (run by CI)
docs/ documentation

Modules of src/demne/

Module Role
templatability.py, homogeneity.py, frequency.py, risk_context.py, ner_feasibility.py the five per-entity scorers (Te, He, Freq, R, Feas), each a standalone class with compute_all()
tfidf_coverage.py TF-IDF extractability: coverage-F1 of the top-X keywords of an entity
routing.py the decision graph, implemented once (route()) and used by the CLI and the dashboard
decision_tree_builder.py applies the graph to the metrics, writes decision_config.json and the report
params.py thresholds and weights from demne_params.json, risk lexicons, derived presets
optimize_params.py Optuna recalibration of demne_params.json on your corpora
_brat.py the single BRAT .ann parser used everywhere
_tracking.py optional energy tracking with eco2ai (pip install "demne[energy]"); a no-op without it
_table.py, visualize_decision_tree.py terminal tables and the decision figure

Data and ethics

The AP-HP data used for external validation are pseudonymized, were processed under the applicable institutional framework (AP-HP Health Data Warehouse, CSE-EDS approval CSE-220024) and are not distributed in this repository.

Citation

@misc{demne2026,
  title  = {DEMNE: Adaptive Selection of Named Entity Extraction Method for Frugal Clinical NLP in Oncology},
  author = {Longeac, Clément and others},
  year   = {2026},
  note   = {Manuscript in preparation},
  url    = {https://github.com/longeacc/DEMNE-Determination-of-Extraction-Methode-for-Named-Entity}
}

See also CITATION.cff. DEMNE builds on the REST tool (Rapid Entity Selection Tool) and on the DuraXELL project at the AP-HP Clinical Data Warehouse.

Contributing and license

Issues and pull requests are welcome, see CONTRIBUTING.md. Released under the MIT license.

Metadata

Release files for DEMNE 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for DEMNE 1.3.0
File Size Uploaded Provenance Actions
demne-1.3.0.tar.gz 212.4 kB Without provenance Details for demne-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for DEMNE 1.3.0
File Interpreter ABI Platform Actions
demne-1.3.0-py3-none-any.whl Python 3 none any Details for demne-1.3.0-py3-none-any.whl

Total release size: 343.8 kB

Release files / demne-1.3.0.tar.gz

Download URL demne-1.3.0.tar.gz
Size 212.4 kB
Tags Source
SHA-256 checksum
How to use checksums
464d5a85f4045408206369cb908b675a987c94cfec59a82546ead048a1c28c77
BLAKE2b-256 checksum
How to use checksums
1aa31b5acc033a5604c36f75396af55e66c16728ed41224875cd804371354212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / demne-1.3.0-py3-none-any.whl

Download URL demne-1.3.0-py3-none-any.whl
Size 131.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbf046a9a35224cbee8d828c15d70778213ad45b7cee60209fe883cb9506e98e
BLAKE2b-256 checksum
How to use checksums
6cc7d7524ae57def5f47f68883040ae05c7abe65649fdf156e8df3cfc432d013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for DEMNE 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page