Description
This model can be used to identify temporal relationships among clinical events.
Included Relations
AFTER
, BEFORE
, OVERLAP
Live Demo Open in ColabDownload
How to use
Use as part of an nlp pipeline with the following stages: DocumentAssembler, SentenceDetector, Tokenizer, PerceptronModel, DependencyParserModel, WordEmbeddingsModel, NerDLModel, NerConverter, RelationExtractionModel.
clinical_re_Model = RelationExtractionModel()\
.pretrained("re_temporal_events_clinical", "en", 'clinical/models')\
.setInputCols(["embeddings", "pos_tags", "ner_chunks", "dependencies"])\
.setOutputCol("relations")\
.setMaxSyntacticDistance(4)\ #default: 0
.setPredictionThreshold(0.9)\ #default: 0.5
.setRelationPairs(["date-problem", "occurrence-date"]) # Possible relation pairs. Default: All Relations.
nlp_pipeline = Pipeline(stages=[document_assembler, sentence_detector, tokenizer, pos_tagger, dependecy_parser, word_embeddings, clinical_ner, ner_converter, clinical_re_Model])
light_pipeline = LightPipeline(nlp_pipeline.fit(spark.createDataFrame([['']]).toDF("text")))
annotations = light_pipeline.fullAnnotate("""The patient is a 56-year-old right-handed female with longstanding intermittent right low back pain, who was involved in a motor vehicle accident in September of 2005. At that time, she did not notice any specific injury, but five days later, she started getting abnormal right low back pain.""")
...
val clinical_re_Model = RelationExtractionModel()
.pretrained("re_temporal_events_clinical", "en", 'clinical/models')
.setInputCols("embeddings", "pos_tags", "ner_chunks", "dependencies")
.setOutputCol("relations")
.setMaxSyntacticDistance(4)
.setPredictionThreshold(0.9)
.setRelationPairs("date-problem", "occurrence-date")
val pipeline = new Pipeline().setStages(Array(document_assembler, sentence_detector, tokenizer, pos_tagger, dependecy_parser, word_embeddings, clinical_ner, ner_converter, clinical_re_Model))
val result = pipeline.fit(Seq.empty["""The patient is a 56-year-old right-handed female with longstanding intermittent right low back pain, who was involved in a motor vehicle accident in September of 2005. At that time, she did not notice any specific injury, but five days later, she started getting abnormal right low back pain."""].toDS.toDF("text")).transform(data)
Results
+----+------------+------------+-----------------+---------------+--------------------------+-----------+-----------------+---------------+---------------------+--------------+
| | relation | entity1 | entity1_begin | entity1_end | chunk1 | entity2 | entity2_begin | entity2_end | chunk2 | confidence |
+====+============+============+=================+===============+==========================+===========+=================+===============+=====================+==============+
| 0 | OVERLAP | OCCURRENCE | 121 | 144 | a motor vehicle accident | DATE | 149 | 165 | September of 2005 | 0.999975 |
+----+------------+------------+-----------------+---------------+--------------------------+-----------+-----------------+---------------+---------------------+--------------+
| 1 | OVERLAP | DATE | 171 | 179 | that time | PROBLEM | 201 | 219 | any specific injury | 0.956654 |
+----+------------+------------+-----------------+---------------+--------------------------+-----------+-----------------+---------------+---------------------+--------------+
Model Information
Model Name: | re_temporal_events_clinical |
Type: | re |
Compatibility: | Spark NLP for Healthcare 2.6.0 + |
Edition: | Official |
License: | Licensed |
Input Labels: | [embeddings, pos_tags, ner_chunks, dependencies] |
Output Labels: | [relations] |
Language: | [en] |
Case sensitive: | false |
Dependencies: | embeddings_clinical |
Data Source
Trained on data gathered and manually annotated by John Snow Labs https://portal.dbmi.hms.harvard.edu/projects/n2c2-nlp/
Benchmarking
|Relation | Recall | Precision | F1 |
|---------:|--------:|----------:|-----:|
| OVERLAP | 0.81 | 0.73 | 0.77 |
| BEFORE | 0.85 | 0.88 | 0.86 |
| AFTER | 0.38 | 0.46 | 0.43 |