Spaces:
Runtime error
Runtime error
Commit
·
94b0e7c
1
Parent(s):
eb237c7
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,14 +85,9 @@ def init_session_states():
|
|
| 85 |
st.session_state['pos_model'] = None
|
| 86 |
if 'bio_model' not in st.session_state:
|
| 87 |
st.session_state['bio_model'] = None
|
| 88 |
-
if 'phi_model' not in st.session_state:
|
| 89 |
-
st.session_state['phi_model'] = None
|
| 90 |
if 'ner_bio' not in st.session_state:
|
| 91 |
st.session_state['ner_bio'] = None
|
| 92 |
-
|
| 93 |
-
st.session_state['ner_phi'] = None
|
| 94 |
-
if 'aggr' not in st.session_state:
|
| 95 |
-
st.session_state['aggr'] = None
|
| 96 |
|
| 97 |
|
| 98 |
|
|
@@ -109,12 +104,10 @@ def get_pos_arr(input_text,display_area):
|
|
| 109 |
def perform_inference(text,display_area):
|
| 110 |
|
| 111 |
if (st.session_state['bio_model'] is None):
|
| 112 |
-
display_area.text("Loading model 1 of
|
| 113 |
st.session_state['bio_model'] = bd.BatchInference("bio/desc_a100_config.json",'ajitrajasekharan/biomedical',False,False,DEFAULT_TOP_K,True,True, "bio/","bio/a100_labels.txt",False)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
display_area.text("Loading model 2 of 3. PHI model...")
|
| 117 |
-
st.session_state['phi_model'] = bd.BatchInference("bbc/desc_bbc_config.json",'bert-base-cased',False,False,DEFAULT_TOP_K,True,True, "bbc/","bbc/bbc_labels.txt",False)
|
| 118 |
|
| 119 |
#Load POS model if needed and gets POS tags
|
| 120 |
if (SPECIFIC_TAG not in text):
|
|
@@ -126,28 +119,14 @@ def perform_inference(text,display_area):
|
|
| 126 |
display_area.text("Initializing BIO module...")
|
| 127 |
st.session_state['ner_bio'] = ner.UnsupNER("bio/ner_a100_config.json")
|
| 128 |
|
| 129 |
-
if (st.session_state['ner_phi'] is None):
|
| 130 |
-
display_area.text("Initializing PHI module...")
|
| 131 |
-
st.session_state['ner_phi'] = ner.UnsupNER("bbc/ner_bbc_config.json")
|
| 132 |
-
|
| 133 |
-
if (st.session_state['aggr'] is None):
|
| 134 |
-
display_area.text("Initializing Aggregation modeule...")
|
| 135 |
-
st.session_state['aggr'] = aggr.AggregateNER("./ensemble_config.json")
|
| 136 |
|
| 137 |
|
| 138 |
-
|
| 139 |
-
display_area.text("Getting results from BIO model...")
|
| 140 |
bio_descs = st.session_state['bio_model'].get_descriptors(text,pos_arr)
|
| 141 |
-
display_area.text("
|
| 142 |
-
phi_results = st.session_state['phi_model'].get_descriptors(text,pos_arr)
|
| 143 |
-
display_area.text("Aggregating BIO & PHI results...")
|
| 144 |
bio_ner = st.session_state['ner_bio'].tag_sentence_service(text,bio_descs)
|
| 145 |
-
phi_ner = st.session_state['ner_phi'].tag_sentence_service(text,phi_results)
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
aggregate_results = st.session_state['aggr'].fetch_all(text,combined_arr)
|
| 150 |
-
return aggregate_results
|
| 151 |
|
| 152 |
|
| 153 |
sent_arr = [
|
|
@@ -156,20 +135,12 @@ sent_arr = [
|
|
| 156 |
"lou gehrig was diagnosed with Parkinson's ",
|
| 157 |
"A eGFR below 60 indicates chronic kidney disease",
|
| 158 |
"Overexpression of EGFR occurs across a wide range of different cancers",
|
| 159 |
-
"Stanford called",
|
| 160 |
"He was diagnosed with non small cell lung cancer",
|
| 161 |
-
"I met my girl friends at the pub ",
|
| 162 |
-
"I met my New York friends at the pub",
|
| 163 |
-
"I met my XCorp friends at the pub",
|
| 164 |
-
"I met my two friends at the pub",
|
| 165 |
"Bio-Techne's genomic tools include advanced tissue-based in-situ hybridization assays sold under the ACD brand as well as a portfolio of assays for prostate cancer diagnosis ",
|
| 166 |
"There are no treatment options specifically indicated for ACD and physicians must utilize agents approved for other dermatology conditions", "As ACD has been implicated in apoptosis-resistant glioblastoma (GBM), there is a high medical need for identifying novel ACD-inducing drugs ",
|
| 167 |
"Located in the heart of Dublin , in the family home of acclaimed writer Oscar Wilde , ACD provides the perfect backdrop to inspire Irish (and Irish-at-heart) students to excel in business and the arts",
|
| 168 |
"Patients treated with anticancer chemotherapy drugs ( ACD ) are vulnerable to infectious diseases due to immunosuppression and to the direct impact of ACD on their intestinal microbiota ",
|
| 169 |
-
"In the LASOR trial , increasing daily imatinib dose from 400 to 600mg induced MMR at 12 and 24 months in 25% and 36% of the patients, respectively, who had suboptimal cytogenetic responses "
|
| 170 |
-
"The sky turned dark in advance of the storm that was coming from the east ",
|
| 171 |
-
"She loves to watch Sunday afternoon football with her family ",
|
| 172 |
-
"Paul Erdos died at 83 "
|
| 173 |
]
|
| 174 |
|
| 175 |
|
|
@@ -179,21 +150,13 @@ sent_arr_masked = [
|
|
| 179 |
"lou:__entity__ gehrig:__entity__ was diagnosed with Parkinson's:__entity__ ",
|
| 180 |
"A eGFR:__entity__ below 60 indicates chronic kidney disease",
|
| 181 |
"Overexpression of EGFR:__entity__ occurs across a wide range of different cancers",
|
| 182 |
-
"Stanford:__entity__ called",
|
| 183 |
"He was diagnosed with non:__entity__ small:__entity__ cell:__entity__ lung:__entity__ cancer:__entity__",
|
| 184 |
-
"I met my girl:__entity__ friends at the pub ",
|
| 185 |
-
"I met my New:__entity__ York:__entity__ friends at the pub",
|
| 186 |
-
"I met my XCorp:__entity__ friends at the pub",
|
| 187 |
-
"I met my two:__entity__ friends at the pub",
|
| 188 |
"Bio-Techne's genomic tools include advanced tissue-based in-situ hybridization assays sold under the ACD:__entity__ brand as well as a portfolio of assays for prostate cancer diagnosis ",
|
| 189 |
"There are no treatment options specifically indicated for ACD:__entity__ and physicians must utilize agents approved for other dermatology conditions",
|
| 190 |
"As ACD:__entity__ has been implicated in apoptosis-resistant glioblastoma (GBM), there is a high medical need for identifying novel ACD-inducing drugs ",
|
| 191 |
"Located in the heart of Dublin , in the family home of acclaimed writer Oscar Wilde , ACD:__entity__ provides the perfect backdrop to inspire Irish (and Irish-at-heart) students to excel in business and the arts",
|
| 192 |
"Patients treated with anticancer chemotherapy drugs ( ACD:__entity__ ) are vulnerable to infectious diseases due to immunosuppression and to the direct impact of ACD on their intestinal microbiota ",
|
| 193 |
-
"In the LASOR:__entity__ trial:__entity__ , increasing daily imatinib dose from 400 to 600mg induced MMR at 12 and 24 months in 25% and 36% of the patients, respectively, who had suboptimal cytogenetic responses "
|
| 194 |
-
"The sky turned dark:__entity__ in advance of the storm that was coming from the east ",
|
| 195 |
-
"She loves to watch Sunday afternoon football:__entity__ with her family ",
|
| 196 |
-
"Paul:__entity__ Erdos:__entity__ died at 83:__entity__ "
|
| 197 |
]
|
| 198 |
|
| 199 |
def init_selectbox():
|
|
@@ -212,19 +175,19 @@ def main():
|
|
| 212 |
|
| 213 |
init_session_states()
|
| 214 |
|
| 215 |
-
st.markdown("<h3 style='text-align: center;'>NER using pretrained
|
| 216 |
#st.markdown("""
|
| 217 |
#<h3 style="font-size:16px; color: #ff0000; text-align: center"><b>App under construction... (not in working condition yet)</b></h3>
|
| 218 |
#""", unsafe_allow_html=True)
|
| 219 |
|
| 220 |
|
| 221 |
-
st.markdown("""
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
""", unsafe_allow_html=True)
|
| 226 |
|
| 227 |
-
st.write("This app uses
|
| 228 |
|
| 229 |
|
| 230 |
with st.form('my_form'):
|
|
@@ -254,7 +217,7 @@ def main():
|
|
| 254 |
# )
|
| 255 |
|
| 256 |
st.markdown("""
|
| 257 |
-
<small style="font-size:16px; color: #7f7f7f; text-align: left"><br/><br/>Models used: <br/>(1) <a href='https://huggingface.co/ajitrajasekharan/biomedical' target='_blank'>Biomedical model</a> pretrained on Pubmed,Clinical trials and BookCorpus subset.<br/>(2)
|
| 258 |
#""", unsafe_allow_html=True)
|
| 259 |
st.markdown("""
|
| 260 |
<h3 style="font-size:16px; color: #9f9f9f; text-align: center"><b> <a href='https://huggingface.co/spaces/ajitrajasekharan/Qualitative-pretrained-model-evaluation' target='_blank'>App link to examine pretrained models</a> used to perform NER without fine tuning</b></h3>
|
|
|
|
| 85 |
st.session_state['pos_model'] = None
|
| 86 |
if 'bio_model' not in st.session_state:
|
| 87 |
st.session_state['bio_model'] = None
|
|
|
|
|
|
|
| 88 |
if 'ner_bio' not in st.session_state:
|
| 89 |
st.session_state['ner_bio'] = None
|
| 90 |
+
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
|
| 93 |
|
|
|
|
| 104 |
def perform_inference(text,display_area):
|
| 105 |
|
| 106 |
if (st.session_state['bio_model'] is None):
|
| 107 |
+
display_area.text("Loading model 1 of 2. Bio model...")
|
| 108 |
st.session_state['bio_model'] = bd.BatchInference("bio/desc_a100_config.json",'ajitrajasekharan/biomedical',False,False,DEFAULT_TOP_K,True,True, "bio/","bio/a100_labels.txt",False)
|
| 109 |
|
| 110 |
+
|
|
|
|
|
|
|
| 111 |
|
| 112 |
#Load POS model if needed and gets POS tags
|
| 113 |
if (SPECIFIC_TAG not in text):
|
|
|
|
| 119 |
display_area.text("Initializing BIO module...")
|
| 120 |
st.session_state['ner_bio'] = ner.UnsupNER("bio/ner_a100_config.json")
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
+
display_area.text("Getting predictions from BIO model...")
|
|
|
|
| 125 |
bio_descs = st.session_state['bio_model'].get_descriptors(text,pos_arr)
|
| 126 |
+
display_area.text("Computing BIO results...")
|
|
|
|
|
|
|
| 127 |
bio_ner = st.session_state['ner_bio'].tag_sentence_service(text,bio_descs)
|
|
|
|
| 128 |
|
| 129 |
+
return bio_ner
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
sent_arr = [
|
|
|
|
| 135 |
"lou gehrig was diagnosed with Parkinson's ",
|
| 136 |
"A eGFR below 60 indicates chronic kidney disease",
|
| 137 |
"Overexpression of EGFR occurs across a wide range of different cancers",
|
|
|
|
| 138 |
"He was diagnosed with non small cell lung cancer",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
"Bio-Techne's genomic tools include advanced tissue-based in-situ hybridization assays sold under the ACD brand as well as a portfolio of assays for prostate cancer diagnosis ",
|
| 140 |
"There are no treatment options specifically indicated for ACD and physicians must utilize agents approved for other dermatology conditions", "As ACD has been implicated in apoptosis-resistant glioblastoma (GBM), there is a high medical need for identifying novel ACD-inducing drugs ",
|
| 141 |
"Located in the heart of Dublin , in the family home of acclaimed writer Oscar Wilde , ACD provides the perfect backdrop to inspire Irish (and Irish-at-heart) students to excel in business and the arts",
|
| 142 |
"Patients treated with anticancer chemotherapy drugs ( ACD ) are vulnerable to infectious diseases due to immunosuppression and to the direct impact of ACD on their intestinal microbiota ",
|
| 143 |
+
"In the LASOR trial , increasing daily imatinib dose from 400 to 600mg induced MMR at 12 and 24 months in 25% and 36% of the patients, respectively, who had suboptimal cytogenetic responses "
|
|
|
|
|
|
|
|
|
|
| 144 |
]
|
| 145 |
|
| 146 |
|
|
|
|
| 150 |
"lou:__entity__ gehrig:__entity__ was diagnosed with Parkinson's:__entity__ ",
|
| 151 |
"A eGFR:__entity__ below 60 indicates chronic kidney disease",
|
| 152 |
"Overexpression of EGFR:__entity__ occurs across a wide range of different cancers",
|
|
|
|
| 153 |
"He was diagnosed with non:__entity__ small:__entity__ cell:__entity__ lung:__entity__ cancer:__entity__",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
"Bio-Techne's genomic tools include advanced tissue-based in-situ hybridization assays sold under the ACD:__entity__ brand as well as a portfolio of assays for prostate cancer diagnosis ",
|
| 155 |
"There are no treatment options specifically indicated for ACD:__entity__ and physicians must utilize agents approved for other dermatology conditions",
|
| 156 |
"As ACD:__entity__ has been implicated in apoptosis-resistant glioblastoma (GBM), there is a high medical need for identifying novel ACD-inducing drugs ",
|
| 157 |
"Located in the heart of Dublin , in the family home of acclaimed writer Oscar Wilde , ACD:__entity__ provides the perfect backdrop to inspire Irish (and Irish-at-heart) students to excel in business and the arts",
|
| 158 |
"Patients treated with anticancer chemotherapy drugs ( ACD:__entity__ ) are vulnerable to infectious diseases due to immunosuppression and to the direct impact of ACD on their intestinal microbiota ",
|
| 159 |
+
"In the LASOR:__entity__ trial:__entity__ , increasing daily imatinib dose from 400 to 600mg induced MMR at 12 and 24 months in 25% and 36% of the patients, respectively, who had suboptimal cytogenetic responses "
|
|
|
|
|
|
|
|
|
|
| 160 |
]
|
| 161 |
|
| 162 |
def init_selectbox():
|
|
|
|
| 175 |
|
| 176 |
init_session_states()
|
| 177 |
|
| 178 |
+
st.markdown("<h3 style='text-align: center;'>Biomedical NER using a pretrained model with <a href='https://ajitrajasekharan.github.io/2021/01/02/my-first-post.html'>no fine tuning</a></h3>", unsafe_allow_html=True)
|
| 179 |
#st.markdown("""
|
| 180 |
#<h3 style="font-size:16px; color: #ff0000; text-align: center"><b>App under construction... (not in working condition yet)</b></h3>
|
| 181 |
#""", unsafe_allow_html=True)
|
| 182 |
|
| 183 |
|
| 184 |
+
#st.markdown("""
|
| 185 |
+
#<p style="text-align:center;"><img src="https://ajitrajasekharan.github.io/images/1.png" width="700"></p>
|
| 186 |
+
# <br/>
|
| 187 |
+
# <br/>
|
| 188 |
+
#""", unsafe_allow_html=True)
|
| 189 |
|
| 190 |
+
st.write("This app uses 2 models. A Bert model pretrained (**no fine tuning**) on biomedical corpus, and a POS tagger")
|
| 191 |
|
| 192 |
|
| 193 |
with st.form('my_form'):
|
|
|
|
| 217 |
# )
|
| 218 |
|
| 219 |
st.markdown("""
|
| 220 |
+
<small style="font-size:16px; color: #7f7f7f; text-align: left"><br/><br/>Models used: <br/>(1) <a href='https://huggingface.co/ajitrajasekharan/biomedical' target='_blank'>Biomedical model</a> pretrained on Pubmed,Clinical trials and BookCorpus subset.<br/>(2) Flair POS tagger</small>
|
| 221 |
#""", unsafe_allow_html=True)
|
| 222 |
st.markdown("""
|
| 223 |
<h3 style="font-size:16px; color: #9f9f9f; text-align: center"><b> <a href='https://huggingface.co/spaces/ajitrajasekharan/Qualitative-pretrained-model-evaluation' target='_blank'>App link to examine pretrained models</a> used to perform NER without fine tuning</b></h3>
|