<jupyter_start><jupyter_text>![JohnSnowLabs](https://nlp.johnsnowlabs.com/assets/images/logo.png)[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/JohnSnowLabs/nlu/blob/master/examples/colab/healthcare/relation_extraction/overview_relation.ipynb)  Extract **relationships** between **named entities**With the *Named Entity Recognizer** models provided by NLU you can extract various named entities from you dataset, like `disease` and `medicine` names, `treatments` , `tests` , `patient names` etc..Between these `entities` there can exist some relation. For example, the sentence :  "`Timmys` had a `headache` , it was treated with `paracetamol` by `Dr Sami` "   , it has the named entities `Dr Sami` , `Timmy` , `headache` , `paracetamol`   and these entities have some relation between them.- The entity `Timmy` is related to `headache` ,  with a `has` relationship- The entity `headache` is related to `paracetamol` with a `is treated with` relation shipThe **Relation Extractor** models classifies for each pair for entities, wether some kind of relationship exists between them.All the models avaiable are :| Language | nlu.load() reference                                         | Spark NLP Model reference          || -------- | ------------------------------------------------------------ | ------------------------------------------------------------ || English  | [assert](https://nlp.johnsnowlabs.com/2021/01/26/assertion_dl_en.html) | [assertion_dl](https://nlp.johnsnowlabs.com/2021/01/26/assertion_dl_en.html)                   || English  | [assert.biobert](https://nlp.johnsnowlabs.com/2021/01/26/assertion_dl_biobert_en.html) | [assertion_dl_biobert](https://nlp.johnsnowlabs.com/2021/01/26/assertion_dl_biobert_en.html)                   || English  | [assert.healthcare](https://nlp.johnsnowlabs.com/2020/09/23/assertion_dl_healthcare_en.html) | [assertion_dl_healthcare](https://nlp.johnsnowlabs.com/2020/09/23/assertion_dl_healthcare_en.html)                   || English  | [assert.large](https://nlp.johnsnowlabs.com/2020/05/21/assertion_dl_large_en.html) | [assertion_dl_large](https://nlp.johnsnowlabs.com/2020/05/21/assertion_dl_large_en.html)                   |<jupyter_code># # Install NLU
!wget https://setup.johnsnowlabs.com/nlu/colab.sh | bash
# # Upload add your spark_nlp_fo"r_healthcare.json

import nlu<jupyter_output>--2022-04-15 04:06:28--  https://setup.johnsnowlabs.com/nlu/colab.sh
Resolving setup.johnsnowlabs.com (setup.johnsnowlabs.com)... 172.16.31.10
Connecting to setup.johnsnowlabs.com (setup.johnsnowlabs.com)|172.16.31.10|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://raw.githubusercontent.com/JohnSnowLabs/nlu/master/scripts/colab_setup.sh [following]
--2022-04-15 04:06:29--  https://raw.githubusercontent.com/JohnSnowLabs/nlu/master/scripts/colab_setup.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 192.168.3.11, 192.168.3.11, 192.168.3.11, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|192.168.3.11|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1665 (1.6K) [text/plain]
Saving to: ‘STDOUT’

-                   100%[===================>]   1.63K  --.-KB/s    in 0s      

2022-04-15 04:06:29 (34.8 MB/s) - written to stdout [1665/1665]

Installing  NLU [...]<jupyter_text>[Relation extraction between body parts and direction entities (ReDL).](https://nlp.johnsnowlabs.com/2021/02/04/redl_bodypart_direction_biobert_en.html)<jupyter_code>import nlu

nlu.load('en.med_ner.jsl.wip.clinical.greedy en.relation').predict('MRI demonstrated infarction in the upper brain stem , left cerebellum and  right basil ganglia"', output_level='relation')<jupyter_output>jsl_ner_wip_greedy_clinical download started this may take some time.
Approximate size to download 14.5 MB
[OK!]
redl_bodypart_direction_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Relation extraction between body parts and problem entities (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_bodypart_problem_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.jsl.wip.clinical.greedy en.relation.bodypart.problem').predict("No neurologic deficits other than some numbness in his left hand.", output_level='relation')<jupyter_output>jsl_ner_wip_greedy_clinical download started this may take some time.
Approximate size to download 14.5 MB
[OK!]
redl_bodypart_problem_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Relation extraction between body parts and procedures](https://nlp.johnsnowlabs.com/2021/02/04/redl_bodypart_procedure_test_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.jsl.wip.clinical.greedy en.relation.bodypart.procedure').predict("TECHNIQUE IN DETAIL: After informed consent was obtained from the patient and his mother, the chest was scanned with portable ultrasound.", output_level='relation')<jupyter_output>jsl_ner_wip_greedy_clinical download started this may take some time.
Approximate size to download 14.5 MB
[OK!]
redl_bodypart_procedure_test_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Extract relations between chemicals and proteins (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_chemprot_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.chemprot.clinical en.relation.chemprot').predict("""In this study, we examined the effects of mitiglinide on various cloned K(ATP) channels
     (Kir6.2/SUR1, Kir6.2/SUR2A, and Kir6.2/SUR2B) reconstituted in COS-1 cells, and compared them to another meglitinide-related compound, nateglinide. Patch-clamp analysis using
     inside-out recording configuration showed that mitiglinide inhibits the Kir6.2/SUR1 channel currents in a dose-dependent manner (IC50 value, 100 nM) but does not significantly
     inhibit either Kir6.2/SUR2A or Kir6.2/SUR2B channel currents even at high doses (more than 10 microM). Nateglinide inhibits Kir6.2/SUR1 and Kir6.2/SUR2B channels at 100 nM,
     and inhibits Kir6.2/SUR2A channels at high concentrations (1 microM). Binding experiments on mitiglinide, nateglinide, and repaglinide to SUR1 expressed in COS-1 cells 
     revealed that they inhibit the binding of [3H]glibenclamide to SUR1 (IC50 values: mitiglinide, 280 nM; nateglinide, 8 microM; repaglinide, 1.6 microM), suggesting that
     they all share a glibenclamide binding site. The insulin responses to glucose, mitiglinide, tolbutamide, and glibenclamide in MIN6 cells after chronic mitiglinide, nateglinide,
     or repaglinide treatment were comparable to those after chronic tolbutamide and glibenclamide treatment. These results indicate that, similar to the sulfonylureas, mitiglinide 
     is highly specific to the Kir6.2/SUR1 complex, i.e., the pancreatic beta-cell K(ATP) channel, 
     and suggest that mitiglinide may be a clinically useful anti-diabetic drug.""", output_level='relation')<jupyter_output>ner_chemprot_clinical download started this may take some time.
Approximate size to download 15.3 MB
[OK!]
redl_chemprot_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Extract relations between problem, treatment and test entities (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_clinical_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.clinical en.relation.clinical').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 .
""", output_level='relation')<jupyter_output>ner_clinical download started this may take some time.
Approximate size to download 13.9 MB
[OK!]
redl_clinical_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Extract temporal relations among clinical events (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_temporal_events_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.events_clinical en.relation.temporal_events').predict("She is diagnosed with cancer in 1991. Then she was admitted to <NAME> in May 2000 and discharged in October 2001", output_level='relation')<jupyter_output>ner_events_clinical download started this may take some time.
Approximate size to download 13.8 MB
[OK!]
redl_temporal_events_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Extract relations between phenotypic abnormalities and diseases (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_human_phenotype_gene_biobert_en.html)<jupyter_code>import nlu 
nlu.load('en.med_ner.human_phenotype.gene_clinical en.relation.humen_phenotype_gene').predict("She has a retinal degeneration, hearing loss and renal failure, short stature, \
Mutations in the SH3PXD2B gene coding for the Tks4 protein are responsible for the autosomal recessive.", output_level='relation')<jupyter_output>ner_human_phenotype_gene_clinical download started this may take some time.
Approximate size to download 14 MB
[OK!]
redl_human_phenotype_gene_biobert download started this may take some time.
Approximate size to download 383.4 MB
[OK!]
embeddings_clinical download started this may take some time.
Approximate size to download 1.6 GB
[OK!]<jupyter_text>[Extract relations between effects of using multiple drugs (ReDL)](https://nlp.johnsnowlabs.com/2021/02/04/redl_drug_drug_interaction_biobert_en.html)<jupyter_code>nlu.load('en.med_ner.posology en.relation.drug_drug_interaction').predict("""When carbamazepine is withdrawn from the combination therapy, aripiprazole dose should then be reduced. \
If additional adrenergic drugs are to be administered by any route, \
they should be used with caution because the pharmacologically predictable sympathetic effects of Metformin may be potentiated""", output_level='relation') 
df = nlu.load('en.med_ner.jsl.wip.clinical.greedy en.relation').predict('MRI demonstrated infarction in the upper brain stem , left cerebellum and  right basil ganglia"', output_level='relation') 
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10703391351157365, 'fraction_numerical': 0.03579759554997308, 'mean_word_length': 4.904131355932203, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 31, 'https://': 23, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 44, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '152567', 'license': 'Apache-2.0', 'n_tokens_mistral': 3926, 'n_tokens_neox': 3407, 'n_words': 1007, 'path': 'nlu/colab/healthcare/relation_extraction/overview_relation.ipynb', 'repo_name': 'iamvarol/spark-nlp-workshop', 'size': '11167'}