|
| 1 | +--- |
| 2 | +layout: model |
| 3 | +title: Sentence Entity Resolver for NDC (sbiobert_base_cased_mli embeddings) |
| 4 | +author: John Snow Labs |
| 5 | +name: sbiobertresolve_ndc |
| 6 | +date: 2024-09-12 |
| 7 | +tags: [clinical, en, licensed, ndc, entity_resolution] |
| 8 | +task: Entity Resolution |
| 9 | +language: en |
| 10 | +edition: Healthcare NLP 5.4.1 |
| 11 | +spark_version: 3.0 |
| 12 | +supported: true |
| 13 | +annotator: SentenceEntityResolverModel |
| 14 | +article_header: |
| 15 | + type: cover |
| 16 | +use_language_switcher: "Python-Scala-Java" |
| 17 | +--- |
| 18 | + |
| 19 | +## Description |
| 20 | + |
| 21 | +This model maps clinical entities and concepts (like drugs/ingredients) to [National Drug Codes](https://www.fda.gov/drugs/drug-approvals-and-databases/national-drug-code-directory) using `sbiobert_base_cased_mli` Sentence Bert Embeddings. It also returns package options and alternative drugs in the `all_k_aux_label` column. |
| 22 | + |
| 23 | +## Predicted Entities |
| 24 | + |
| 25 | +`NDC codes`, `package options` |
| 26 | + |
| 27 | +{:.btn-box} |
| 28 | +[Live Demo](https://demo.johnsnowlabs.com/healthcare/ER_NDC/){:.button.button-orange} |
| 29 | +[Open in Colab](https://colab.research.google.com/github/JohnSnowLabs/spark-nlp-workshop/blob/master/tutorials/Certification_Trainings/Healthcare/26.Chunk_Mapping.ipynb){:.button.button-orange.button-orange-trans.co.button-icon} |
| 30 | +[Download](https://s3.amazonaws.com/auxdata.johnsnowlabs.com/clinical/models/sbiobertresolve_ndc_en_5.4.1_3.0_1726129988440.zip){:.button.button-orange.button-orange-trans.arr.button-icon.hidden} |
| 31 | +[Copy S3 URI](s3://auxdata.johnsnowlabs.com/clinical/models/sbiobertresolve_ndc_en_5.4.1_3.0_1726129988440.zip){:.button.button-orange.button-orange-trans.button-icon.button-copy-s3} |
| 32 | + |
| 33 | +## How to use |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +<div class="tabs-box" markdown="1"> |
| 38 | +{% include programmingLanguageSelectScalaPythonNLU.html %} |
| 39 | +```python |
| 40 | +document_assembler = DocumentAssembler()\ |
| 41 | + .setInputCol("text")\ |
| 42 | + .setOutputCol("document") |
| 43 | + |
| 44 | +sentenceDetectorDL = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare", "en", "clinical/models")\ |
| 45 | + .setInputCols(["document"])\ |
| 46 | + .setOutputCol("sentence") |
| 47 | + |
| 48 | +tokenizer = Tokenizer()\ |
| 49 | + .setInputCols(["sentence"])\ |
| 50 | + .setOutputCol("token") |
| 51 | + |
| 52 | +word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models")\ |
| 53 | + .setInputCols(["sentence", "token"])\ |
| 54 | + .setOutputCol("word_embeddings") |
| 55 | + |
| 56 | +ner = MedicalNerModel.pretrained("ner_posology_greedy", "en", "clinical/models")\ |
| 57 | + .setInputCols(["sentence", "token", "word_embeddings"])\ |
| 58 | + .setOutputCol("ner")\ |
| 59 | + |
| 60 | +ner_converter = NerConverterInternal()\ |
| 61 | + .setInputCols(["sentence", "token", "ner"])\ |
| 62 | + .setOutputCol("ner_chunk")\ |
| 63 | + .setWhiteList(["DRUG"]) |
| 64 | + |
| 65 | +c2doc = Chunk2Doc()\ |
| 66 | + .setInputCols("ner_chunk")\ |
| 67 | + .setOutputCol("ner_chunk_doc") |
| 68 | + |
| 69 | +sbert_embedder = BertSentenceEmbeddings.pretrained("sbiobert_base_cased_mli", "en", "clinical/models")\ |
| 70 | + .setInputCols(["ner_chunk_doc"])\ |
| 71 | + .setOutputCol("sentence_embeddings")\ |
| 72 | + .setCaseSensitive(False) |
| 73 | + |
| 74 | +ndc_resolver = SentenceEntityResolverModel.pretrained("sbiobertresolve_ndc", "en", "clinical/models")\ \ |
| 75 | + .setInputCols(["sentence_embeddings"]) \ |
| 76 | + .setOutputCol("ndc_code")\ |
| 77 | + .setDistanceFunction("EUCLIDEAN") |
| 78 | + |
| 79 | +resolver_pipeline = Pipeline(stages = [document_assembler, |
| 80 | + sentenceDetectorDL, |
| 81 | + tokenizer, |
| 82 | + word_embeddings, |
| 83 | + ner, |
| 84 | + ner_converter, |
| 85 | + c2doc, |
| 86 | + sbert_embedder, |
| 87 | + ndc_resolver]) |
| 88 | + |
| 89 | +text= "The patient was prescribed Amlodopine Vallarta 10-320mg, Eviplera. aspirin 81 mg and metformin 500 mg. The other patient is given Lescol 40 MG and Everolimus 1.5 mg tablet." |
| 90 | +data = spark.createDataFrame([[text]]).toDF("text") |
| 91 | + |
| 92 | +result = resolver_pipeline.fit(data).transform(data) |
| 93 | +``` |
| 94 | +```scala |
| 95 | +val document_assembler = new DocumentAssembler() |
| 96 | + .setInputCol("text") |
| 97 | + .setOutputCol("document") |
| 98 | + |
| 99 | +val sentence_detector = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare","en","clinical/models") |
| 100 | + .setInputCols("document") |
| 101 | + .setOutputCol("sentence") |
| 102 | + |
| 103 | +val tokenizer = new Tokenizer() |
| 104 | + .setInputCols("sentence") |
| 105 | + .setOutputCol("token") |
| 106 | + |
| 107 | +val word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models") |
| 108 | + .setInputCols(Array("sentence","token")) |
| 109 | + .setOutputCol("embeddings") |
| 110 | + |
| 111 | +val ner = MedicalNerModel.pretrained("ner_posology_greedy", "en", "clinical/models") |
| 112 | + .setInputCols(Array("sentence","token","embeddings")) |
| 113 | + .setOutputCol("ner") |
| 114 | + |
| 115 | +val ner_converter = new NerConverter() |
| 116 | + .setInputCols(Array("sentence","token","ner")) |
| 117 | + .setOutputCol("ner_chunk") |
| 118 | + .setWhiteList("DRUG") |
| 119 | + |
| 120 | +val chunk2doc = new Chunk2Doc() |
| 121 | + .setInputCols("ner_chunk") |
| 122 | + .setOutputCol("ner_chunk_doc") |
| 123 | + |
| 124 | +val sbert_embedder = BertSentenceEmbeddings.pretrained("sbiobert_base_cased_mli","en","clinical/models") |
| 125 | + .setInputCols("ner_chunk_doc") |
| 126 | + .setOutputCol("sbert_embeddings") |
| 127 | + |
| 128 | +val ndc_resolver = SentenceEntityResolverModel.pretrained("sbiobertresolve_ndc", "en", "clinical/models") |
| 129 | + .setInputCols("sbert_embeddings") |
| 130 | + .setOutputCol("ndc_code") |
| 131 | + .setDistanceFunction("EUCLIDEAN") |
| 132 | + |
| 133 | +val pipeline = new Pipeline().setStages(Array(document_assembler, |
| 134 | + sentence_detector, |
| 135 | + tokenizer, |
| 136 | + word_embeddings, |
| 137 | + ner, |
| 138 | + ner_converter, |
| 139 | + chunk2doc, |
| 140 | + sbert_embedder, |
| 141 | + ndc_resolver)) |
| 142 | + |
| 143 | +val data = Seq("The patient was prescribed Amlodopine Vallarta 10-320mg, Eviplera. aspirin 81 mg and metformin 500 mg. The other patient is given Lescol 40 MG and Everolimus 1.5 mg tablet.").toDS().toDF("text") |
| 144 | + |
| 145 | +val result = pipeline.fit(data).transform(data) |
| 146 | +``` |
| 147 | +</div> |
| 148 | + |
| 149 | +## Results |
| 150 | + |
| 151 | +```bash |
| 152 | +| | ner_chunk | entity | ndc_code | aux_list | |
| 153 | +|---:|:-----------------------------|:---------|:-----------|:----------------------------------------------------------------------------------------------------| |
| 154 | +| 0 | Amlodopine Vallarta 10-320mg | DRUG | 72483-0100 | '{'packages': "['1 BOTTLE in 1 BOX (72483-100-04) / 120 mL in 1 BOTTLE\']", \'alternatives\': [ ...| |
| 155 | +| 1 | aspirin 81 mg | DRUG | 41250-0780 | '{'packages': "['1 BOTTLE, PLASTIC in 1 PACKAGE (41250-780-01) / 120 TABLET, DELAYED RELEASE in ...| |
| 156 | +| 2 | metformin 500 mg | DRUG | 62207-0491 | '{'packages': "['5000 TABLET in 1 POUCH (62207-491-31)\', \'25000 TABLET in 1 CARTON (62207-491- ...| |
| 157 | +| 3 | Lescol 40 MG | DRUG | 0713-0862 | '{'packages': "['30 TABLET, FILM COATED in 1 BOTTLE, PLASTIC (0713-0862-30)\']", \'alternatives\ ...| |
| 158 | +| 4 | Everolimus 1.5 mg tablet | DRUG | 0054-0604 | '{'packages': "['60 TABLET in 1 BOTTLE (0054-0604-21)\']", \'alternatives\': [\'67877-721\', \'4 ...| |
| 159 | +``` |
| 160 | +
|
| 161 | +{:.model-param} |
| 162 | +## Model Information |
| 163 | +
|
| 164 | +{:.table-model} |
| 165 | +|---|---| |
| 166 | +|Model Name:|sbiobertresolve_ndc| |
| 167 | +|Compatibility:|Healthcare NLP 5.4.1+| |
| 168 | +|License:|Licensed| |
| 169 | +|Edition:|Official| |
| 170 | +|Input Labels:|[sentence_embeddings]| |
| 171 | +|Output Labels:|[ndc_code]| |
| 172 | +|Language:|en| |
| 173 | +|Size:|724.6 MB| |
| 174 | +|Case sensitive:|false| |
| 175 | +
|
| 176 | +## References |
| 177 | +
|
| 178 | +It is trained on U.S. FDA 2024-NDC Codes dataset |
0 commit comments