ajitrajasekharan commited on
Commit
6f5d2d2
1 Parent(s): c273b5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -5,6 +5,7 @@ import string
5
 
6
  bert_tokenizer = None
7
  bert_model = None
 
8
 
9
  from transformers import BertTokenizer, BertForMaskedLM
10
 
@@ -99,6 +100,8 @@ def on_option_change():
99
  text = st.session_state.my_choice
100
  run_test(text,top_k,model_name)
101
 
 
 
102
 
103
  def on_model_change1():
104
  model_name = st.session_state.my_model1
@@ -115,24 +118,28 @@ def init_selectbox():
115
  'Choose any of these sentences or type any text below',
116
  ('', "[MASK] who lives in New York and works for XCorp suffers from Parkinson's", "Lou Gehrig who lives in [MASK] and works for XCorp suffers from Parkinson's","Lou Gehrig who lives in New York and works for [MASK] suffers from Parkinson's","Lou Gehrig who lives in New York and works for XCorp suffers from [MASK]","[MASK] who lives in New York and works for XCorp suffers from Lou Gehrig's", "Parkinson who lives in [MASK] and works for XCorp suffers from Lou Gehrig's","Parkinson who lives in New York and works for [MASK] suffers from Lou Gehrig's","Parkinson who lives in New York and works for XCorp suffers from [MASK]","Lou Gehrig","Parkinson","Lou Gehrigh's is a [MASK]","Parkinson is a [MASK]","New York is a [MASK]","New York","XCorp","XCorp is a [MASK]","acute lymphoblastic leukemia","acute lymphoblastic leukemia is a [MASK]"),on_change=on_option_change,key='my_choice')
117
  return option
 
 
118
 
119
- st.markdown("<h3 style='text-align: center;'>Qualitative evaluation of any pretrained BERT model</h3>", unsafe_allow_html=True)
120
- st.markdown("""
 
 
121
  <small style="font-size:18px; color: #7f7f7f">Pretrained BERT models can be used as is, <a href="https://ajitrajasekharan.github.io/2021/01/02/my-first-post.html"><b>with no fine tuning to perform tasks like NER</b></a> <i>ideally if both fill-mask and CLS predictions are good, or minimally if fill-mask predictions are adequate</i></small>
122
  """, unsafe_allow_html=True)
123
  #st.write("https://ajitrajasekharan.github.io/2021/01/02/my-first-post.html")
124
- st.write("This app can be used to examine both model prediction for a masked position as well as the neighborhood of CLS vector")
125
- st.write(" - To examine model prediction for a position, enter the token [MASK] or <mask>")
126
- st.write(" - To examine just the [CLS] vector, enter a word/phrase or sentence. Example: eGFR or EGFR or non small cell lung cancer")
127
- top_k = st.sidebar.slider("Select how many predictions do you need", 1 , 50, 20) #some times it is possible to have less words
128
- print(top_k)
129
 
130
 
131
 
132
  #if st.button("Submit"):
133
 
134
  # with st.spinner("Computing"):
135
- try:
136
 
137
  model_name = st.sidebar.selectbox(label='Select Model to Apply', options=['ajitrajasekharan/biomedical', 'bert-base-cased','bert-large-cased','microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext','allenai/scibert_scivocab_cased','dmis-lab/biobert-v1.1'], index=0, key = "my_model1",on_change=on_model_change1)
138
  option = init_selectbox()
@@ -153,9 +160,14 @@ try:
153
 
154
 
155
 
156
- except Exception as e:
157
- st.error("Some error occurred during loading" + str(e))
158
- st.stop()
159
 
160
- st.write("---")
 
 
 
 
 
161
 
 
5
 
6
  bert_tokenizer = None
7
  bert_model = None
8
+ top_k = 20
9
 
10
  from transformers import BertTokenizer, BertForMaskedLM
11
 
 
100
  text = st.session_state.my_choice
101
  run_test(text,top_k,model_name)
102
 
103
+ def on_results_count_change():
104
+ top_k = int(st.session_state.my_slider)
105
 
106
  def on_model_change1():
107
  model_name = st.session_state.my_model1
 
118
  'Choose any of these sentences or type any text below',
119
  ('', "[MASK] who lives in New York and works for XCorp suffers from Parkinson's", "Lou Gehrig who lives in [MASK] and works for XCorp suffers from Parkinson's","Lou Gehrig who lives in New York and works for [MASK] suffers from Parkinson's","Lou Gehrig who lives in New York and works for XCorp suffers from [MASK]","[MASK] who lives in New York and works for XCorp suffers from Lou Gehrig's", "Parkinson who lives in [MASK] and works for XCorp suffers from Lou Gehrig's","Parkinson who lives in New York and works for [MASK] suffers from Lou Gehrig's","Parkinson who lives in New York and works for XCorp suffers from [MASK]","Lou Gehrig","Parkinson","Lou Gehrigh's is a [MASK]","Parkinson is a [MASK]","New York is a [MASK]","New York","XCorp","XCorp is a [MASK]","acute lymphoblastic leukemia","acute lymphoblastic leukemia is a [MASK]"),on_change=on_option_change,key='my_choice')
120
  return option
121
+
122
+
123
 
124
+ def main():
125
+
126
+ st.markdown("<h3 style='text-align: center;'>Qualitative evaluation of any pretrained BERT model</h3>", unsafe_allow_html=True)
127
+ st.markdown("""
128
  <small style="font-size:18px; color: #7f7f7f">Pretrained BERT models can be used as is, <a href="https://ajitrajasekharan.github.io/2021/01/02/my-first-post.html"><b>with no fine tuning to perform tasks like NER</b></a> <i>ideally if both fill-mask and CLS predictions are good, or minimally if fill-mask predictions are adequate</i></small>
129
  """, unsafe_allow_html=True)
130
  #st.write("https://ajitrajasekharan.github.io/2021/01/02/my-first-post.html")
131
+ st.write("This app can be used to examine both model prediction for a masked position as well as the neighborhood of CLS vector")
132
+ st.write(" - To examine model prediction for a position, enter the token [MASK] or <mask>")
133
+ st.write(" - To examine just the [CLS] vector, enter a word/phrase or sentence. Example: eGFR or EGFR or non small cell lung cancer")
134
+ top_k = st.sidebar.slider("Select how many predictions do you need", 1 , 50, top_k,key='my_slider',on_change=on_results_count_change) #some times it is possible to have less words
135
+ print(top_k)
136
 
137
 
138
 
139
  #if st.button("Submit"):
140
 
141
  # with st.spinner("Computing"):
142
+ try:
143
 
144
  model_name = st.sidebar.selectbox(label='Select Model to Apply', options=['ajitrajasekharan/biomedical', 'bert-base-cased','bert-large-cased','microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext','allenai/scibert_scivocab_cased','dmis-lab/biobert-v1.1'], index=0, key = "my_model1",on_change=on_model_change1)
145
  option = init_selectbox()
 
160
 
161
 
162
 
163
+ except Exception as e:
164
+ st.error("Some error occurred during loading" + str(e))
165
+ st.stop()
166
 
167
+ st.write("---")
168
+
169
+
170
+
171
+ if __name__ == "__main__":
172
+ main()
173