Sentence tokenizer for text from clinical notes.
Project description
clinitokenizer
clinitokenizer
is a sentence tokenizer for clinical text to split unstructured text from clinical text (such as Electronic Medical Records) into individual sentences.
General English sentence tokenizers are often unable to correctly parse medical abbreviations, jargon, and other conventions often used in medical records (see "Motivating Examples" section below). clinitokenizer is specifically trained on medical record data and can perform better in these situations (conversely, for non-domain specific use, using more general sentence tokenizers may yield better results).
The model has been trained on multiple datasets provided by i2b2 (now n2c2). Please visit the n2c2 site to request access to the dataset.
Installation
pip install clinitokenizer
Quickstart
from clinitokenizer.tokenize import clini_tokenize
text = "He was asked if he was taking any medications. Patient is currently taking 5 m.g. Tylenol."
sents = clini_tokenize(text)
# sents = ['He was asked if he was taking any medications.',
# 'Patient is currently taking 5 m.g. Tylenol.']
You can use clinitokenizer as a drop-in replacement for nltk's sent_tokenize
function:
# to swap in clinitokenizer, replace the nltk import...
from nltk.tokenize import sent_tokenize
# ... with the following clinitokenizer import:
from clinitokenizer.tokenize import clini_tokenize as sent_tokenize
# and tokenizing should work in the same manner!
nltk_sents = sent_tokenize(text)
Technical Details
clinitokenizer uses a bert-large
Transformer model fine-tuned on sentences from Electronic Medical Records provided from the i2b2/n2c2 dataset. The model has been fine-tuned and is inferenced using the Simple Transformers library, and the model is hosted on HuggingFace .
The model can be run on GPU or CPU, and will automatically switch depending on availability of GPU.
Tradeoffs and Considerations
clinitokenizer
uses a large neural network (about 1.2 GB) which will be downloaded and cached on-device on first run. This initial setup may take a few minutes, but should only happen once.
Compared to other off-the-shelf sentence tokenizers (i.e. nltk
), clinitokenizer
will run slower (especially on machines without GPU) and consume more memory, so if near-instant tokenization is the goal, using a GPU-based machine or another tokenizer may be better.
clinitokenizer
is optimized for natural-language text in the clinical domain. Therefore, when tokenizing more general English sentences or for tasks in a different domain, other generalized tokenizers may perform better.
Motivating Examples
Below are some examples of clinical text comparing clinitokenizer
to nltk.tokenize.sent_tokenize
:
"He was asked if he was taking any medications. Patient is currently taking 5 m.g. Tylenol."
notes: Challenge here is not mistaking m.g. for end-of-sentence.
nltk output:
He was asked if he was taking any medications.
Patient is currently taking 5 m.g.
Tylenol.
clinitokenizer output:
He was asked if he was taking any medications.
Patient is currently taking 5 m.g. Tylenol.
"Pt. has hx of alcohol use disorder He is recovering."
notes: Challenge here is there is a typo after 'disorder', missing a period. Can tokenizer semantically identify new sentence?
nltk output:
Pt.
has hx of alcohol use disorder He is recovering.
clinitokenizer output:
Pt. has hx of alcohol use disorder
He is recovering.
"Pt. has hx of alcohol use disorder but He is recovering."
notes: Opposite as previous example -- here, there is an accidental capitalization. Can tokenizer semantically identify it is NOT a new sentence?
nltk output:
Pt.
has hx of alcohol use disorder but He is recovering.
clinitokenizer output:
Pt. has hx of alcohol use disorder but He is recovering.
"Past Medical History: Patient has PMH of COPD."
notes: "Past Medical History" is a sentence header. Even though it is technically a single sentence according to English grammar, when extracting section headers it may be important to identify them as distinct from all sentences under that header.
nltk output:
Past Medical History: Patient has PMH of COPD.
clinitokenizer output:
Past Medical History:
Patient has PMH of COPD.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file clinitokenizer-0.0.4.tar.gz
.
File metadata
- Download URL: clinitokenizer-0.0.4.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5de51eae697d8e34d066e6c02e4fbddd9e2b155c0a4c5b9d9fd97d58106c186 |
|
MD5 | efa14e5d5d775a1fd4e02f021396df78 |
|
BLAKE2b-256 | 734c087f835bb01f5f311fe6c5bcba36986eddc82e55bc4e3e77c4db16e25d40 |
File details
Details for the file clinitokenizer-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: clinitokenizer-0.0.4-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44c8d5039ef13575ab04afb2960c54d9e604dde7c03fc9841602cebbdbb69d8a |
|
MD5 | 225bc0286d4b98371e7f4053716c0d68 |
|
BLAKE2b-256 | f8606fe9bf711a01206b1bcc87944d8e498c4bb7cac0c84f64eea13000d2d528 |