Zeroshot Ner Jsl Large With FewShotAssertion and ContextualAssertion - Pipeline

Description

This pipeline extracts clinical entities and their assertion status (e.g., present/absent/possible/conditional/associated-with-someone-else) from medical text.

It first performs clinical Zero-shot Named Entity Recognition (NER) using a pretrained model with contextual understanding, restricted to a fixed, predefined clinical label schema (e.g., AGE, GENDER, SYMPTOM, TEST, TEST_RESULT, TREATMENT, BLOOD_PRESSURE, TEMPERATURE, O2_SATURATION, and other configured labels). To support long notes, the text is recursively split into overlapping 512-character chunks (40-character overlap) before tokenization and inference.

Assertion status is then assigned with a hybrid strategy:

  • AssertionDL (deep learning): uses pretrained clinical word embeddings and an AssertionDL model to predict assertion for each extracted entity within a configurable scope window.
  • Contextual assertion (rule-based): applies contextual assertion models to detect absent, possible, conditional, and associated-with-someone-else cues and their scope around each entity.

Finally, an AssertionMerger combines the AssertionDL and contextual outputs using majority voting and confidence-based ordering to produce a single consolidated assertion label per entity.

Outputs include consolidated NER spans (ner_chunk) with character offsets and confidence, plus merged assertion predictions (assertion_merged) with confidence aligned to each entity.

Copy S3 URI

How to use


from sparknlp.pretrained import PretrainedPipeline

pipeline = PretrainedPipeline("zeroshot_ner_jsl_medium_assertiondl_pipeline", "en", "clinical/models")

sample_text = """ The patient is a 21-day-old Caucasian male here for 2 days of congestion - mom has been suctioning yellow discharge from the patient's nares, plus she has noticed some mild problems with his breathing while feeding (but negative for any perioral cyanosis or retractions). Additionally, there is no side effect observed after Influenza vaccine. One day ago, mom also noticed a tactile temperature and gave the patient Tylenol. Baby also has had some decreased p.o. intake. His normal breast-feeding is down from 20 minutes q.2h. to 5 to 10 minutes secondary to his respiratory congestion. He sleeps well, but has been more tired and has been fussy over the past 2 days. The parents noticed no improvement with albuterol treatments given in the ER. His urine output has also decreased; normally he has 8 to 10 wet and 5 dirty diapers per 24 hours, now he has down to 4 wet diapers per 24 hours. Mom denies any diarrhea. His bowel movements are yellow colored and soft in nature."""

result = pipeline.transform(spark.createDataFrame(sample_text).toDF("text"))


from johnsnowlabs import nlp, medical

pipeline = nlp.PretrainedPipeline("zeroshot_ner_jsl_medium_assertiondl_pipeline", "en", "clinical/models")

sample_text = """ The patient is a 21-day-old Caucasian male here for 2 days of congestion - mom has been suctioning yellow discharge from the patient's nares, plus she has noticed some mild problems with his breathing while feeding (but negative for any perioral cyanosis or retractions). Additionally, there is no side effect observed after Influenza vaccine. One day ago, mom also noticed a tactile temperature and gave the patient Tylenol. Baby also has had some decreased p.o. intake. His normal breast-feeding is down from 20 minutes q.2h. to 5 to 10 minutes secondary to his respiratory congestion. He sleeps well, but has been more tired and has been fussy over the past 2 days. The parents noticed no improvement with albuterol treatments given in the ER. His urine output has also decreased; normally he has 8 to 10 wet and 5 dirty diapers per 24 hours, now he has down to 4 wet diapers per 24 hours. Mom denies any diarrhea. His bowel movements are yellow colored and soft in nature."""

result = pipeline.transform(spark.createDataFrame(sample_text).toDF("text"))


import com.johnsnowlabs.nlp.pretrained.PretrainedPipeline

val pipeline = PretrainedPipeline("zeroshot_ner_jsl_medium_assertiondl_pipeline", "en", "clinical/models")

val sample_text = """ The patient is a 21-day-old Caucasian male here for 2 days of congestion - mom has been suctioning yellow discharge from the patient's nares, plus she has noticed some mild problems with his breathing while feeding (but negative for any perioral cyanosis or retractions). Additionally, there is no side effect observed after Influenza vaccine. One day ago, mom also noticed a tactile temperature and gave the patient Tylenol. Baby also has had some decreased p.o. intake. His normal breast-feeding is down from 20 minutes q.2h. to 5 to 10 minutes secondary to his respiratory congestion. He sleeps well, but has been more tired and has been fussy over the past 2 days. The parents noticed no improvement with albuterol treatments given in the ER. His urine output has also decreased; normally he has 8 to 10 wet and 5 dirty diapers per 24 hours, now he has down to 4 wet diapers per 24 hours. Mom denies any diarrhea. His bowel movements are yellow colored and soft in nature."""

val result = pipeline.transform(spark.createDataFrame(sample_text).toDF("text"))

Results


+----------------------+-----+---+--------------------+--------------+----------------------------+--------------------+
|chunk                 |begin|end|ner_label           |ner_confidence|assertion                   |assertion_confidence|
+----------------------+-----+---+--------------------+--------------+----------------------------+--------------------+
|21-day-old            |17   |26 |AGE                 |0.99695885    |absent                      |0.6835              |
|Caucasian             |28   |36 |RACE_ETHNICITY      |0.97338265    |absent                      |0.5848              |
|male                  |38   |41 |GENDER              |0.99688834    |absent                      |0.5802              |
|congestion            |62   |71 |COMMUNICABLE_DISEASE|0.75309765    |absent                      |0.5471              |
|mom                   |75   |77 |GENDER              |0.99827564    |associated_with_someone_else|1.0                 |
|yellow discharge      |99   |114|SYMPTOM             |0.6035481     |present                     |0.6836              |
|she                   |147  |149|GENDER              |0.9835265     |present                     |0.9235              |
|his                   |187  |189|GENDER              |0.8737909     |present                     |0.9127              |
|retractions           |258  |268|SYMPTOM             |0.81836647    |absent                      |0.9994              |
|mom                   |357  |359|GENDER              |0.9957776     |associated_with_someone_else|1.0                 |
|decreased p.o. intake |449  |469|SYMPTOM             |0.6698671     |present                     |0.9997              |
|His                   |472  |474|GENDER              |0.9965887     |absent                      |0.9706              |
|His                   |472  |474|GENDER              |0.9945926     |possible                    |0.6377              |
|his                   |560  |562|GENDER              |0.980966      |possible                    |0.5771              |
|respiratory congestion|564  |585|KIDNEY_DISEASE      |0.6405385     |possible                    |0.4784              |
|He                    |588  |589|GENDER              |0.9884072     |present                     |0.6782              |
|tired                 |622  |626|SYMPTOM             |0.7520301     |present                     |0.7104              |
|fussy                 |641  |645|SYMPTOM             |0.8103657     |present                     |0.9079              |
|His                   |747  |749|GENDER              |0.972946      |present                     |0.9976              |
|decreased             |773  |781|SYMPTOM             |0.6032276     |present                     |0.9782              |
|he                    |793  |794|GENDER              |0.99352384    |hypothetical                |0.9874              |
|he                    |850  |851|GENDER              |0.9923889     |associated_with_someone_else|1.0                 |
|Mom                   |893  |895|GENDER              |0.99196833    |absent                      |0.9951              |
|diarrhea              |908  |915|KIDNEY_DISEASE      |0.7366171     |absent                      |0.997               |
|His                   |918  |920|GENDER              |0.94910246    |absent                      |0.9859              |
|yellow colored        |942  |955|SYMPTOM             |0.5970007     |null                        |null                |
+----------------------+-----+---+--------------------+--------------+----------------------------+--------------------+




Model Information

Model Name: zeroshot_ner_jsl_medium_assertiondl_pipeline
Type: pipeline
Compatibility: Healthcare NLP 6.4.0+
License: Licensed
Edition: Official
Language: en
Size: 1.3 GB

Included Models

  • DocumentAssembler
  • InternalDocumentSplitter
  • TokenizerModel
  • PretrainedZeroShotNER
  • NerConverterInternalModel
  • WordEmbeddingsModel
  • AssertionDLModel
  • ContextualAssertion
  • ContextualAssertion
  • ContextualAssertion
  • ContextualAssertion
  • AssertionMerger