Skip to main content

biosenter - Sentence splitting for biomedical text

biosenter is a small spaCy sentence-boundary model plus markup-aware pre/post-processing, trained and evaluated specifically against PMC full text and PubMed abstracts with LLM-annotated sentence boundaries.

Why?: Generic sentence splitters break constantly on biomedical text: Fig. 1, et al.. They also don't deal nicely with citations (that often get attached to the wrong sentence)

Install

pip install biosenter

A trained model ships with the package, so split_into_sentences works out of the box with no extra configuration. It integrates directly with bioconverters for extracting text from PMC JATS XML and PubMed baseline/update XML.

Usage

1. Direct spaCy usage

For plain, markup-free text (e.g. PubMed abstracts):

import spacy
nlp = spacy.load("biosenter")
doc = nlp("As shown in Fig. 1, expression increased. A second effect was seen in Fig. 2.")
for sent in doc.sents:
    print(sent.text)

2. Citation-aware, with bioconverters (split_into_sentences)

For real PMC full text, which carries inline markup and citation markers that a plain spaCy Doc can't represent correctly. bioconverters.pmcxml2tagged is built for exactly this -- it keeps formatting tags and resolved citations inline instead of stripping them, which is what split_into_sentences needs to work with:

from bioconverters import pmcxml2tagged

from biosenter import split_into_sentences

# pmcxml2tagged() yields (metadata, text) pairs with inline markup and
# citations preserved, e.g.:
#   'Recurrent <italic>C. difficile</italic> infection is common
#   (<citation pmid="23079555">1</citation>).'
for meta, text in pmcxml2tagged('PMC1234567.xml'):
    for start, end, sentence in split_into_sentences(text):
        print(sentence)

Benchmarks

Sentence-boundary F1 against corpora/test/ (75 held-out PMC articles) excluding the formatting/citation handling. The articles used to train and evaluate with annotated by Claude Sonnet and Opus.

Model corpora/test/
spaCy rule-based sentencizer F1 0.9264 (P 0.8961, R 0.9588)
en_core_web_sm F1 0.9556 (P 0.9281, R 0.9847)
scispacy en_core_sci_sm F1 0.9751 (P 0.9820, R 0.9683)
biosenter (bundled) F1 0.9866 (P 0.9859, R 0.9873)

Reproduce with scripts/evaluate_senter.py, which loads any of these by name (they're all just installed spaCy packages):

pip install en_core_web_sm  # or: python -m spacy download en_core_web_sm
python scripts/evaluate_senter.py --models rule en_core_web_sm biosenter/model \
  --pmc_eval_dir corpora/test

scispacy's released models pin to an older spaCy than biosenter requires (en_core_sci_sm 0.5.4 needs spacy<3.8) -- their own README recommends an isolated environment for exactly this reason, so run it separately:

pip install scispacy
pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.4/en_core_sci_sm-0.5.4.tar.gz
pip install --no-deps -e .  # biosenter itself, for split_into_sentences -- skip its spacy>=3.8 pin here
python scripts/evaluate_senter.py --models en_core_sci_sm --pmc_eval_dir corpora/test

Retraining / evaluating

The bundled model, the corpus it was trained on, and the tooling to rebuild or extend either are all included:

  • corpora/train/ and corpora/test/ -- 225 LLM-annotated PMC articles used to train and score the bundled model. See corpora/README.md for the dataset schema and how it was built.
  • scripts/fetch_pmc.py -- fetch more PMC Open Access articles (random or by PMCID), filtered to commercially-redistributable licenses by default.
  • scripts/prepare_pmc_senter_corpus.py -- convert corpora/{train,test} into spaCy training data.
  • scripts/train_senter.py -- train a new model.
  • scripts/evaluate_senter.py -- score a model against the hand-labelled eval set.
python scripts/prepare_pmc_senter_corpus.py --corpus_dir corpora/train --out_path data/senter/pmc_train.spacy
python scripts/prepare_pmc_senter_corpus.py --corpus_dir corpora/test --out_path data/senter/pmc_val.spacy
python scripts/train_senter.py --data_dir data/senter --run_name my_run
python scripts/evaluate_senter.py --models rule runs/my_run/model-best --pmc_eval_dir corpora/test --verbose

License

MIT. See LICENSE.

Metadata

Release files for biosenter 0.1.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 biosenter 0.1.0
File Size Uploaded
biosenter-0.1.0.tar.gz 3.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for biosenter 0.1.0
File Interpreter ABI Platform
biosenter-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 MB

Release files / biosenter-0.1.0.tar.gz

Download URL biosenter-0.1.0.tar.gz
Size 3.3 MB
Tags Source
SHA-256 checksum
How to use checksums
74512b82c8a8a846cff94b9cad4c4c08e6ce751ca2915946fc7d7909f19f980a
BLAKE2b-256 checksum
How to use checksums
3545e6444f5f7182a0f6a506c570fad1d8d87bf663a0c8768b7c22749ec8d0d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / biosenter-0.1.0-py3-none-any.whl

Download URL biosenter-0.1.0-py3-none-any.whl
Size 3.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2ccc018ee80d7b2b611058ec10a3708b0ca8ef63fe2bf13b446c71352b7ba279
BLAKE2b-256 checksum
How to use checksums
eaada141badcef743a15ac68a5efc381dfee6f6b63600eb445f1b28859623470
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

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