Detect Clinical Entities (bert_token_classifier_ner_jsl)

Description

This model is BERT-based version of ner_jsl model and it is better than the legacy NER model (MedicalNerModel) that is based on BiLSTM-CNN-Char architecture.

Definitions of Predicted Entities:

  • Injury_or_Poisoning: Physical harm or injury caused to the body, including those caused by accidents, falls, or poisoning of a patient or someone else.
  • Direction: All the information relating to the laterality of the internal and external organs.
  • Test: Mentions of laboratory, pathology, and radiological tests.
  • Admission_Discharge: Terms that indicate the admission and/or the discharge of a patient.
  • Death_Entity: Mentions that indicate the death of a patient.
  • Relationship_Status: State of patients romantic or social relationships (e.g. single, married, divorced).
  • Duration: The duration of a medical treatment or medication use.
  • Respiration: Number of breaths per minute.
  • Hyperlipidemia: Terms that indicate hyperlipidemia with relevant subtypes and synonims.
  • Birth_Entity: Mentions that indicate giving birth.
  • Age: All mention of ages, past or present, related to the patient or with anybody else.
  • Labour_Delivery: Extractions include stages of labor and delivery.
  • Family_History_Header: identifies section headers that correspond to Family History of the patient.
  • BMI: Numeric values and other text information related to Body Mass Index.
  • Temperature: All mentions that refer to body temperature.
  • Alcohol: Terms that indicate alcohol use, abuse or drinking issues of a patient or someone else.
  • Kidney_Disease: Terms that refer to any kidney diseases (includes mentions of modifiers such as “Acute” or “Chronic”).
  • Oncological: All the cancer, tumor or metastasis related extractions mentioned in the document, of the patient or someone else.
  • Medical_History_Header: Identifies section headers that correspond to Past Medical History of a patient.
  • Cerebrovascular_Disease: All terms that refer to cerebrovascular diseases and events.
  • Oxygen_Therapy: Breathing support triggered by patient or entirely or partially by machine (e.g. ventilator, BPAP, CPAP).
  • O2_Saturation: Systemic arterial, venous or peripheral oxygen saturation measurements.
  • Psychological_Condition: All the Mental health diagnosis, disorders, conditions or syndromes of a patient or someone else.
  • Heart_Disease: All mentions of acquired, congenital or degenerative heart diseases.
  • Employment: All mentions of patient or provider occupational titles and employment status .
  • Obesity: Terms related to a patient being obese (overweight and BMI are extracted as different labels).
  • Disease_Syndrome_Disorder: All the diseases mentioned in the document, of the patient or someone else (excluding diseases that are extracted with their specific labels, such as “Heart_Disease” etc.).
  • Pregnancy: All terms related to Pregnancy (excluding terms that are extracted with their specific labels, such as “Labour_Delivery” etc.).
  • ImagingFindings: All mentions of radiographic and imagistic findings.
  • Procedure: All mentions of invasive medical or surgical procedures or treatments.
  • Medical_Device: All mentions related to medical devices and supplies.
  • Race_Ethnicity: All terms that refer to racial and national origin of sociocultural groups.
  • Section_Header: All the section headers present in the text (Medical History, Family History, Social History, Physical Examination and Vital signs Headers are extracted separately with their specific labels).
  • Symptom: All the symptoms mentioned in the document, of a patient or someone else.
  • Treatment: Includes therapeutic and minimally invasive treatment and procedures (invasive treatments or procedures are extracted as “Procedure”).
  • Substance: All mentions of substance use related to the patient or someone else (recreational drugs, illicit drugs).
  • Route: Drug and medication administration routes available described by FDA.
  • Drug_Ingredient: Active ingredient/s found in drug products.
  • Blood_Pressure: Systemic blood pressure, mean arterial pressure, systolic and/or diastolic are extracted.
  • Diet: All mentions and information regarding patients dietary habits.
  • External_body_part_or_region: All mentions related to external body parts or organs that can be examined by naked eye.
  • LDL: All mentions related to the lab test and results for LDL (Low Density Lipoprotein).
  • VS_Finding: Qualitative data (e.g. Fever, Cyanosis, Tachycardia) and any other symptoms that refers to vital signs.
  • Allergen: Allergen related extractions mentioned in the document.
  • EKG_Findings: All mentions of EKG readings.
  • Imaging_Technique: All mentions of special radiographic views or special imaging techniques used in radiology.
  • Triglycerides: All mentions terms related to specific lab test for Triglycerides.
  • RelativeTime: Time references that are relative to different times or events (e.g. words such as “approximately”, “in the morning”).
  • Gender: Gender-specific nouns and pronouns.
  • Pulse: Peripheral heart rate, without advanced information like measurement location.
  • Social_History_Header: Identifies section headers that correspond to Social History of a patient.
  • Substance_Quantity: All mentions of substance quantity (quantitative information related to illicit/recreational drugs).
  • Diabetes: All terms related to diabetes mellitus.
  • Modifier: Terms that modify the symptoms, diseases or risk factors. If a modifier is included in ICD-10 name of a specific disease, the respective modifier is not extracted separately.
  • Internal_organ_or_component: All mentions related to internal body parts or organs that can not be examined by naked eye.
  • Clinical_Dept: Terms that indicate the medical and/or surgical departments.
  • Form: Drug and medication forms available described by FDA.
  • Drug_BrandName: Commercial labeling name chosen by the labeler or the drug manufacturer for a drug containing a single or multiple drug active ingredients.
  • Strength: Potency of one unit of drug (or a combination of drugs) the measurement units available are described by FDA.
  • Fetus_NewBorn: All terms related to fetus, infant, new born (excluding terms that are extracted with their specific labels, such as “Labour_Delivery”, “Pregnancy” etc.).
  • RelativeDate: Temporal references that are relative to the date of the text or to any other specific date (e.g. “approximately two years ago”, “about two days ago”).
  • Height: All mentions related to a patients height.
  • Test_Result: Terms related to all the test results present in the document (clinical tests results are included).
  • Sexually_Active_or_Sexual_Orientation: All terms that are related to sexuality, sexual orientations and sexual activity.
  • Frequency: Frequency of administration for a dose prescribed.
  • Time: Specific time references (hour and/or minutes).
  • Weight: All mentions related to a patients weight.
  • Vaccine: Generic and brand name of vaccines or vaccination procedure.
  • Vital_Signs_Header: Identifies section headers that correspond to Vital Signs of a patient.
  • Communicable_Disease: Includes all mentions of communicable diseases.
  • Dosage: Quantity prescribed by the physician for an active ingredient; measurement units are available described by FDA.
  • Overweight: Terms related to the patient being overweight (BMI and Obesity is extracted separately).
  • Hypertension: All terms related to Hypertension (quantitative data such as 150/100 is extracted as Blood_Pressure).
  • HDL: Terms related to the lab test for HDL (High Density Lipoprotein).
  • Total_Cholesterol: Terms related to the lab test and results for cholesterol.
  • Smoking: All mentions of smoking status of a patient.
  • Date: Mentions of an exact date, in any format, including day number, month and/or year.

Predicted Entities

Injury_or_Poisoning, Direction, Test, Admission_Discharge, Death_Entity, Relationship_Status, Duration, Respiration, Hyperlipidemia, Birth_Entity, Age, Labour_Delivery, Family_History_Header, BMI, Temperature, Alcohol, Kidney_Disease, Oncological, Medical_History_Header, Cerebrovascular_Disease, Oxygen_Therapy, O2_Saturation, Psychological_Condition, Heart_Disease, Employment, Obesity, Disease_Syndrome_Disorder, Pregnancy, ImagingFindings, Procedure, Medical_Device, Race_Ethnicity, Section_Header, Symptom, Treatment, Substance, Route, Drug_Ingredient, Blood_Pressure, Diet, External_body_part_or_region, LDL, VS_Finding, Allergen, EKG_Findings, Imaging_Technique, Triglycerides, RelativeTime, Gender, Pulse, Social_History_Header, Substance_Quantity, Diabetes, Modifier, Internal_organ_or_component, Clinical_Dept, Form, Drug_BrandName, Strength, Fetus_NewBorn, RelativeDate, Height, Test_Result, Sexually_Active_or_Sexual_Orientation, Frequency, Time, Weight, Vaccine, Vital_Signs_Header, Communicable_Disease, Dosage, Overweight, Hypertension, HDL, Total_Cholesterol, Smoking, Date

Live Demo Open in Colab Copy S3 URI

How to use

documentAssembler = DocumentAssembler()\
.setInputCol("text")\
.setOutputCol("document")

sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare", "en", "clinical/models")\
.setInputCols(["document"])\
.setOutputCol("sentence")

tokenizer = Tokenizer()\
.setInputCols("sentence")\
.setOutputCol("token")

tokenClassifier = MedicalBertForTokenClassifier.pretrained("bert_token_classifier_ner_jsl", "en", "clinical/models")\
.setInputCols("token", "sentence")\
.setOutputCol("ner")\
.setCaseSensitive(True)

ner_converter = NerConverter()\
.setInputCols(["sentence","token","ner"])\
.setOutputCol("ner_chunk")

pipeline =  Pipeline(stages=[
	       documentAssembler,
	       sentenceDetector,
	       tokenizer,
	       tokenClassifier,
	       ner_converter])
						       
model = pipeline.fit(spark.createDataFrame([[""]]).toDF("text"))

sample_text = """A 28-year-old female with a history of gestational diabetes mellitus diagnosed eight years prior to presentation and subsequent type two diabetes mellitus ( T2DM ), one prior episode of HTG-induced pancreatitis three years prior to presentation , associated with an acute hepatitis , and obesity with a body mass index ( BMI ) of 33.5 kg/m2 , presented with a one-week history of polyuria , polydipsia , poor appetite , and vomiting . Two weeks prior to presentation , she was treated with a five-day course of amoxicillin for a respiratory tract infection . She was on metformin , glipizide , and dapagliflozin for T2DM and atorvastatin and gemfibrozil for HTG . She had been on dapagliflozin for six months at the time of presentation . Physical examination on presentation was significant for dry oral mucosa ; significantly , her abdominal examination was benign with no tenderness , guarding , or rigidity . Pertinent laboratory findings on admission were : serum glucose 111 mg/dl , bicarbonate 18 mmol/l , anion gap 20 , creatinine 0.4 mg/dL , triglycerides 508 mg/dL , total cholesterol 122 mg/dL , glycated hemoglobin ( HbA1c ) 10% , and venous pH 7.27 . Serum lipase was normal at 43 U/L . Serum acetone levels could not be assessed as blood samples kept hemolyzing due to significant lipemia . The patient was initially admitted for starvation ketosis , as she reported poor oral intake for three days prior to admission . However , serum chemistry obtained six hours after presentation revealed her glucose was 186 mg/dL , the anion gap was still elevated at 21 , serum bicarbonate was 16 mmol/L , triglyceride level peaked at 2050 mg/dL , and lipase was 52 U/L . The β-hydroxybutyrate level was obtained and found to be elevated at 5.29 mmol/L - the original sample was centrifuged and the chylomicron layer removed prior to analysis due to interference from turbidity caused by lipemia again . The patient was treated with an insulin drip for euDKA and HTG with a reduction in the anion gap to 13 and triglycerides to 1400 mg/dL , within 24 hours . Her euDKA was thought to be precipitated by her respiratory tract infection in the setting of SGLT2 inhibitor use . The patient was seen by the endocrinology service and she was discharged on 40 units of insulin glargine at night , 12 units of insulin lispro with meals , and metformin 1000 mg two times a day . It was determined that all SGLT2 inhibitors should be discontinued indefinitely . She had close follow-up with endocrinology post discharge ."""

result = model.transform(spark.createDataFrame([[sample_text]]).toDF("text"))
val documentAssembler = new DocumentAssembler()
		.setInputCol("text")
		.setOutputCol("document")

val sentenceDetector = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare","en","clinical/models")
		.setInputCols(Array("document"))
		.setOutputCol("sentence")

val tokenizer = new Tokenizer()
		.setInputCols("sentence")
		.setOutputCol("token")
		
val tokenClassifier = MedicalBertForTokenClassifier.pretrained("bert_token_classifier_ner_jsl", "en", "clinical/models")
		.setInputCols(Array("token", "sentence"))
		.setOutputCol("ner")
		.setCaseSensitive(True)

val ner_converter = new NerConverter()
		.setInputCols(Array("sentence","token","ner"))
		.setOutputCol("ner_chunk")

val pipeline =  new Pipeline().setStages(Array(
				documentAssembler,
				sentenceDetector,
				tokenizer,
				tokenClassifier,
				ner_converter))
												
val sample_text = Seq("""A 28-year-old female with a history of gestational diabetes mellitus diagnosed eight years prior to presentation and subsequent type two diabetes mellitus ( T2DM ), one prior episode of HTG-induced pancreatitis three years prior to presentation , associated with an acute hepatitis , and obesity with a body mass index ( BMI ) of 33.5 kg/m2 , presented with a one-week history of polyuria , polydipsia , poor appetite , and vomiting . Two weeks prior to presentation , she was treated with a five-day course of amoxicillin for a respiratory tract infection . She was on metformin , glipizide , and dapagliflozin for T2DM and atorvastatin and gemfibrozil for HTG . She had been on dapagliflozin for six months at the time of presentation . Physical examination on presentation was significant for dry oral mucosa ; significantly , her abdominal examination was benign with no tenderness , guarding , or rigidity . Pertinent laboratory findings on admission were : serum glucose 111 mg/dl , bicarbonate 18 mmol/l , anion gap 20 , creatinine 0.4 mg/dL , triglycerides 508 mg/dL , total cholesterol 122 mg/dL , glycated hemoglobin ( HbA1c ) 10% , and venous pH 7.27 . Serum lipase was normal at 43 U/L . Serum acetone levels could not be assessed as blood samples kept hemolyzing due to significant lipemia . The patient was initially admitted for starvation ketosis , as she reported poor oral intake for three days prior to admission . However , serum chemistry obtained six hours after presentation revealed her glucose was 186 mg/dL , the anion gap was still elevated at 21 , serum bicarbonate was 16 mmol/L , triglyceride level peaked at 2050 mg/dL , and lipase was 52 U/L . The β-hydroxybutyrate level was obtained and found to be elevated at 5.29 mmol/L - the original sample was centrifuged and the chylomicron layer removed prior to analysis due to interference from turbidity caused by lipemia again . The patient was treated with an insulin drip for euDKA and HTG with a reduction in the anion gap to 13 and triglycerides to 1400 mg/dL , within 24 hours . Her euDKA was thought to be precipitated by her respiratory tract infection in the setting of SGLT2 inhibitor use . The patient was seen by the endocrinology service and she was discharged on 40 units of insulin glargine at night , 12 units of insulin lispro with meals , and metformin 1000 mg two times a day . It was determined that all SGLT2 inhibitors should be discontinued indefinitely . She had close follow-up with endocrinology post discharge .""").toDS.toDF("text")

val result = pipeline.fit(sample_text).transform(sample_text)
import nlu
nlu.load("en.classify.token_bert.ner_jsl").predict("""A 28-year-old female with a history of gestational diabetes mellitus diagnosed eight years prior to presentation and subsequent type two diabetes mellitus ( T2DM ), one prior episode of HTG-induced pancreatitis three years prior to presentation , associated with an acute hepatitis , and obesity with a body mass index ( BMI ) of 33.5 kg/m2 , presented with a one-week history of polyuria , polydipsia , poor appetite , and vomiting . Two weeks prior to presentation , she was treated with a five-day course of amoxicillin for a respiratory tract infection . She was on metformin , glipizide , and dapagliflozin for T2DM and atorvastatin and gemfibrozil for HTG . She had been on dapagliflozin for six months at the time of presentation . Physical examination on presentation was significant for dry oral mucosa ; significantly , her abdominal examination was benign with no tenderness , guarding , or rigidity . Pertinent laboratory findings on admission were : serum glucose 111 mg/dl , bicarbonate 18 mmol/l , anion gap 20 , creatinine 0.4 mg/dL , triglycerides 508 mg/dL , total cholesterol 122 mg/dL , glycated hemoglobin ( HbA1c ) 10% , and venous pH 7.27 . Serum lipase was normal at 43 U/L . Serum acetone levels could not be assessed as blood samples kept hemolyzing due to significant lipemia . The patient was initially admitted for starvation ketosis , as she reported poor oral intake for three days prior to admission . However , serum chemistry obtained six hours after presentation revealed her glucose was 186 mg/dL , the anion gap was still elevated at 21 , serum bicarbonate was 16 mmol/L , triglyceride level peaked at 2050 mg/dL , and lipase was 52 U/L . The β-hydroxybutyrate level was obtained and found to be elevated at 5.29 mmol/L - the original sample was centrifuged and the chylomicron layer removed prior to analysis due to interference from turbidity caused by lipemia again . The patient was treated with an insulin drip for euDKA and HTG with a reduction in the anion gap to 13 and triglycerides to 1400 mg/dL , within 24 hours . Her euDKA was thought to be precipitated by her respiratory tract infection in the setting of SGLT2 inhibitor use . The patient was seen by the endocrinology service and she was discharged on 40 units of insulin glargine at night , 12 units of insulin lispro with meals , and metformin 1000 mg two times a day . It was determined that all SGLT2 inhibitors should be discontinued indefinitely . She had close follow-up with endocrinology post discharge .""")

Results

+------------+-------------------------+
|chunk       |label                    |
+------------+-------------------------+
|28-year-old |Age                      |
|female      |Gender                   |
|gestational |Diabetes                 |
|diabetes    |Diabetes                 |
|mellitus    |Diabetes                 |
|eight       |RelativeDate             |
|years       |RelativeDate             |
|prior       |RelativeDate             |
|type        |Diabetes                 |
|two         |Diabetes                 |
|diabetes    |Diabetes                 |
|mellitus    |Diabetes                 |
|T2DM        |Diabetes                 |
|HTG-induced |Diabetes                 |
|pancreatitis|Disease_Syndrome_Disorder|
|three       |RelativeDate             |
|years       |RelativeDate             |
|prior       |RelativeDate             |
|acute       |Disease_Syndrome_Disorder|
|hepatitis   |Disease_Syndrome_Disorder|
|obesity     |Obesity                  |
|body        |BMI                      |
|mass        |BMI                      |
|index       |BMI                      |
|BMI         |BMI                      |
|)           |BMI                      |
|of          |BMI                      |
|33.5        |BMI                      |
|kg/m2       |BMI                      |
|polyuria    |Symptom                  |
|polydipsia  |Symptom                  |
|poor        |Symptom                  |
|appetite    |Symptom                  |
|vomiting    |Symptom                  |
|Two         |RelativeDate             |
|weeks       |RelativeDate             |
|prior       |RelativeDate             |
|she         |Gender                   |
|five-day    |Drug                     |
|course      |Drug                     |
+------------+-------------------------+

Model Information

Model Name: bert_token_classifier_ner_jsl
Compatibility: Healthcare NLP 3.2.0+
License: Licensed
Edition: Official
Input Labels: [sentence, token]
Output Labels: [ner]
Language: en
Case sensitive: true
Max sentense length: 128

Data Source

Trained on data gathered and manually annotated by John Snow Labs. https://www.johnsnowlabs.com/data/

Benchmarking

label       precision recall   f1-score  support
Admission_Discharge       0.84      0.97      0.90       415
Age       0.96      0.96      0.96      2434
Alcohol       0.75      0.83      0.79       145
BMI       1.00      0.77      0.87        26
Blood_Pressure       0.86      0.88      0.87       597
Cerebrovascular_Disease       0.74      0.77      0.75       266
Clinical_Dept       0.90      0.92      0.91      2385
Communicable_Disease       0.70      0.59      0.64        85
Date       0.95      0.98      0.96      1438
Death_Entity       0.83      0.83      0.83        59
Diabetes       0.95      0.95      0.95       350
Diet       0.60      0.49      0.54       229
Direction       0.88      0.90      0.89      6187
Disease_Syndrome_Disorder       0.90      0.89      0.89     13236
Dosage       0.57      0.49      0.53       263
Drug       0.91      0.93      0.92     15926
Duration       0.82      0.85      0.83      1218
EKG_Findings       0.64      0.70      0.67       325
Employment       0.79      0.85      0.82       539
External_body_part_or_region       0.84      0.84      0.84      4805
Family_History_Header       1.00      1.00      1.00       889
Fetus_NewBorn       0.57      0.56      0.56       341
Frequency       0.87      0.90      0.88      1718
Gender       0.98      0.98      0.98      5666
HDL       0.60      1.00      0.75         6
Heart_Disease       0.88      0.88      0.88      2295
Height       0.89      0.96      0.92       134
Hyperlipidemia       1.00      0.95      0.97       194
Hypertension       0.95      0.98      0.97       566
ImagingFindings       0.66      0.64      0.65       601
Imaging_Technique       0.62      0.67      0.64       108
Injury_or_Poisoning       0.85      0.83      0.84      1680
Internal_organ_or_component       0.90      0.91      0.90     21318
Kidney_Disease       0.89      0.89      0.89       446
LDL       0.88      0.97      0.92        37
Labour_Delivery       0.82      0.71      0.76       306
Medical_Device       0.89      0.93      0.91     12852
Medical_History_Header       0.96      0.97      0.96      1013
Modifier       0.68      0.60      0.64      1398
O2_Saturation       0.84      0.82      0.83       199
Obesity       0.96      0.98      0.97       130
Oncological       0.88      0.96      0.92      1635
Overweight       0.80      0.80      0.80        10
Oxygen_Therapy       0.91      0.92      0.92       231
Pregnancy       0.81      0.83      0.82       439
Procedure       0.91      0.91      0.91     14410
Psychological_Condition       0.81      0.81      0.81       354
Pulse       0.85      0.95      0.89       389
Race_Ethnicity       1.00      1.00      1.00       163
Relationship_Status       0.93      0.91      0.92        57
RelativeDate       0.83      0.86      0.84      1562
RelativeTime       0.74      0.79      0.77       431
Respiration       0.99      0.95      0.97       221
Route       0.68      0.69      0.69       597
Section_Header       0.97      0.98      0.98     28580
Sexually_Active_or_Sexual_Orientation       1.00      0.64      0.78        14
Smoking       0.83      0.90      0.86       225
Social_History_Header       0.95      0.99      0.97       825
Strength       0.71      0.55      0.62       227
Substance       0.85      0.81      0.83       193
Symptom       0.84      0.86      0.85     23092
Temperature       0.94      0.97      0.96       410
Test       0.84      0.88      0.86      9050
Test_Result       0.84      0.84      0.84      2766
Time       0.90      0.81      0.86       140
Total_Cholesterol       0.69      0.95      0.80        73
Treatment       0.73      0.72      0.73       506
Triglycerides       0.83      0.80      0.81        30
VS_Finding       0.76      0.77      0.76       588
Vaccine       0.70      0.84      0.76        92
Vital_Signs_Header       0.95      0.98      0.97      2223
Weight       0.88      0.89      0.88       306
O       0.97      0.96      0.97    253164
accuracy         -         -       0.94    445974
macro-avg       0.82      0.82      0.81    445974
weighted-avg       0.94      0.94      0.94    445974