Sentence Entity Resolver for Hierarchical Condition Categories (HCC) codes (Augmented)

Description

This model maps extracted medical entities to Hierarchical Condition Categories (HCC) codes using sbiobert_base_cased_mli_onnx Sentence Bert Embeddings. Trained on the ICD-10-CM 20260401 release.

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")

word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical","en","clinical/models")\
    .setInputCols(["sentence","token"])\
    .setOutputCol("word_embeddings")

ner_model = MedicalNerModel.pretrained("ner_clinical","en","clinical/models")\
    .setInputCols(["sentence","token","word_embeddings"])\
    .setOutputCol("ner")

ner_converter = NerConverterInternal()\
    .setInputCols(["sentence","token","ner"])\
    .setOutputCol("ner_chunk")\
    .setWhiteList(['PROBLEM'])

chunk2doc = Chunk2Doc()\
    .setInputCols("ner_chunk")\
    .setOutputCol("ner_chunk_doc")

embedder = BertSentenceEmbeddings.pretrained("sbiobert_base_cased_mli_onnx","en","clinical/models")\
    .setInputCols(["ner_chunk_doc"])\
    .setOutputCol("sbert_embeddings")\
    .setCaseSensitive(False)

resolver = SentenceEntityResolverModel.pretrained("sbiobertresolve_hcc_augmented","en","clinical/models")\
    .setInputCols(["sbert_embeddings"])\
    .setOutputCol("hcc_code")\
    .setDistanceFunction("EUCLIDEAN")

pipeline = Pipeline(stages=[
    documentAssembler, sentenceDetector, tokenizer, word_embeddings,
    ner_model, ner_converter, chunk2doc, embedder, resolver
])

data = spark.createDataFrame([["The patient has a history of type 2 diabetes mellitus, essential hypertension, and end stage renal disease, presented with acute appendicitis, and was noted to have chronic obstructive pulmonary disease and other heart failure on exam."]]).toDF("text")
result = pipeline.fit(data).transform(data)


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

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

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

word_embeddings = nlp.WordEmbeddingsModel.pretrained("embeddings_clinical","en","clinical/models")\
    .setInputCols(["sentence","token"])\
    .setOutputCol("word_embeddings")

ner_model = medical.NerModel.pretrained("ner_clinical","en","clinical/models")\
    .setInputCols(["sentence","token","word_embeddings"])\
    .setOutputCol("ner")

ner_converter = medical.NerConverterInternal()\
    .setInputCols(["sentence","token","ner"])\
    .setOutputCol("ner_chunk")\
    .setWhiteList(['PROBLEM'])

chunk2doc = nlp.Chunk2Doc()\
    .setInputCols("ner_chunk")\
    .setOutputCol("ner_chunk_doc")

embedder = nlp.BertSentenceEmbeddings.pretrained("sbiobert_base_cased_mli_onnx","en","clinical/models")\
    .setInputCols(["ner_chunk_doc"])\
    .setOutputCol("sbert_embeddings")\
    .setCaseSensitive(False)

resolver = medical.SentenceEntityResolverModel.pretrained("sbiobertresolve_hcc_augmented","en","clinical/models")\
    .setInputCols(["sbert_embeddings"])\
    .setOutputCol("hcc_code")\
    .setDistanceFunction("EUCLIDEAN")

pipeline = nlp.Pipeline(stages=[
    documentAssembler, sentenceDetector, tokenizer, word_embeddings,
    ner_model, ner_converter, chunk2doc, embedder, resolver
])

data = spark.createDataFrame([["The patient has a history of type 2 diabetes mellitus, essential hypertension, and end stage renal disease, presented with acute appendicitis, and was noted to have chronic obstructive pulmonary disease and other heart failure on exam."]]).toDF("text")
result = pipeline.fit(data).transform(data)


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 word_embeddings = WordEmbeddingsModel
    .pretrained("embeddings_clinical", "en", "clinical/models")
    .setInputCols(Array("sentence", "token"))
    .setOutputCol("word_embeddings")

val ner_model = MedicalNerModel
    .pretrained("ner_clinical", "en", "clinical/models")
    .setInputCols(Array("sentence", "token", "word_embeddings"))
    .setOutputCol("ner")

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

val chunk2doc = new Chunk2Doc()
    .setInputCols("ner_chunk")
    .setOutputCol("ner_chunk_doc")

val embedder = BertSentenceEmbeddings
    .pretrained("sbiobert_base_cased_mli_onnx", "en","clinical/models")
    .setInputCols(Array("ner_chunk_doc"))
    .setOutputCol("sbert_embeddings")
    .setCaseSensitive(false)

val resolver = SentenceEntityResolverModel
    .pretrained("sbiobertresolve_hcc_augmented", "en", "clinical/models")
    .setInputCols(Array("sbert_embeddings"))
    .setOutputCol("hcc_code")
    .setDistanceFunction("EUCLIDEAN")

val pipeline = new Pipeline().setStages(Array(
    documentAssembler, sentenceDetector, tokenizer, word_embeddings,
    ner_model, ner_converter, chunk2doc, embedder, resolver
))

val data = Seq("The patient has a history of type 2 diabetes mellitus, essential hypertension, and end stage renal disease, presented with acute appendicitis, and was noted to have chronic obstructive pulmonary disease and other heart failure on exam.").toDF("text")
val res = pipeline.fit(data).transform(data)

Results

| ner_chunk                             | entity   |   hcc_code | resolution                                                                                 | all_k_results      | all_k_cosine_distances            | all_k_resolutions                                                                   | all_k_aux_labels   |
|:--------------------------------------|:---------|-----------:|:-------------------------------------------------------------------------------------------|:-------------------|:----------------------------------|:------------------------------------------------------------------------------------|:-------------------|
| type 2 diabetes mellitus              | PROBLEM  |          0 | type 2 diabetes mellitus [type 2 diabetes mellitus]                                        | 0:::19:::18:::108  | 0.0000:::0.0134:::0.0212:::0.0548 | type 2 diabetes mellitus [type 2 diabetes mellitus]:::diabetes mellitus type 2 [... |                    |
| essential hypertension                | PROBLEM  |          0 | essential hypertension [essential (primary) hypertension]                                  | 0                  | 0.0000                            | essential hypertension [essential (primary) hypertension]                           |                    |
| end stage renal disease               | PROBLEM  |        136 | end stage renal disease [end stage renal disease]                                          | 136:::134:::0      | 0.0000:::0.0164:::0.0367          | end stage renal disease [end stage renal disease]:::end-stage renal disease (dis... |                    |
| acute appendicitis                    | PROBLEM  |          0 | acute appendicitis [acute appendicitis]                                                    | 0                  | 0.0000                            | acute appendicitis [acute appendicitis]                                             |                    |
| chronic obstructive pulmonary disease | PROBLEM  |        111 | chronic obstructive pulmonary disease [chronic obstructive pulmonary disease, unspecified] | 111:::112:::85:::0 | 0.0000:::0.0433:::0.0622:::0.0632 | chronic obstructive pulmonary disease [chronic obstructive pulmonary disease, un... |                    |
| other heart failure                   | PROBLEM  |         85 | other heart failure [other heart failure]                                                  | 85:::0             | 0.0000:::0.0841                   | other heart failure [other heart failure]:::other ill-defined heart diseases [ot... |                    |

Model Information

Model Name: sbiobertresolve_hcc_augmented
Compatibility: Healthcare NLP 6.4.1+
License: Licensed
Edition: Official
Input Labels: [sbert_embeddings]
Output Labels: [hcc_code]
Language: en
Size: 1.3 GB
Case sensitive: false