aemin commited on
Commit
837539a
·
1 Parent(s): a09d34d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -61,7 +61,7 @@ st.sidebar.markdown(logo_html, unsafe_allow_html=True)
61
 
62
 
63
  #sidebar info
64
- model_name= ["nerdl_fewnerd_100d", "bert_large_token_classifier_ontonote", "ner_mit_movie_complex_distilbert_base_cased", "ner_conll_albert_large_uncased"]
65
  st.sidebar.title("Pretrained model to test")
66
  selected_model = st.sidebar.selectbox("", model_name)
67
 
@@ -73,14 +73,12 @@ if selected_model == "nerdl_fewnerd_100d":
73
  st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True)
74
  st.markdown("**`PERSON`** **,** **`ORGANIZATION`** **,** **`LOCATION`** **,** **`ART`** **,** **`BUILDING`** **,** **`PRODUCT`** **,** **`EVENT`** **,** **`OTHER`**", unsafe_allow_html=True)
75
 
76
- elif selected_model== "bert_large_token_classifier_ontonote":
77
- app_title= "Detect up to 18 entity types in general domain texts"
78
- app_description= "Named Entity Recognition model aimed to detect up to 18 entity types from general domain texts. This model is a fine-tuned BERT model that is ready to use for Named Entity Recognition and achieves state-of-the-art performance for the NER task, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)"
79
  st.title(app_title)
80
  st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True)
81
- st.markdown("""**`CARDINAL`** **,** **`DATE`** **,** **`EVENT`** **,** **`FAC`** **,** **`GPE`** **,** **`LANGUAGE`** **,** **`LAW`** **,** **`LOC`**,
82
- **`MONEY`** **,** **`NORP`** **,** **`ORDINAL`** **,** **`ORG`** **,** **`PERCENT`** **,** **`PERCENT`** **,** **`PERSON`** **,** **`PRODUCT`**,
83
- **`QUANTITY`** **,** **`TIME`** **,** **`WORK_OF_ART` **""", unsafe_allow_html=True)
84
 
85
 
86
  elif selected_model== "ner_mit_movie_complex_distilbert_base_cased":
@@ -142,13 +140,16 @@ def get_pipeline(text):
142
  ner_converter
143
  ])
144
 
145
- elif selected_model=="bert_large_token_classifier_ontonote":
146
- tokenClassifier = BertForTokenClassification \
147
- .pretrained('bert_large_token_classifier_ontonote', 'en') \
148
- .setInputCols(['token', 'document']) \
149
- .setOutputCol('ner') \
150
- .setCaseSensitive(True) \
151
- .setMaxSentenceLength(512)
 
 
 
152
 
153
  ner_converter= NerConverter()\
154
  .setInputCols(["document", "token", "ner"])\
@@ -159,7 +160,8 @@ def get_pipeline(text):
159
  documentAssembler,
160
  sentenceDetector,
161
  tokenizer,
162
- tokenClassifier,
 
163
  ner_converter
164
  ])
165
 
@@ -221,11 +223,16 @@ def get_pipeline(text):
221
 
222
  return result
223
 
 
 
 
224
 
225
 
226
- if selected_model=="ner_mit_movie_complex_distilbert_base_cased":
227
- text= st.text_input("Type here your text and press enter to run:", value="It's only appropriate that Solaris, Russian filmmaker Andrei Tarkovsky's psychological sci-fi classic from 1972, contains an equally original and mind-bending score. Solaris explores the inadequacies of time and memory on an enigmatic planet below a derelict space station. To reinforce the film's chilling setting, Tarkovsky commissioned composer Eduard Artemiev to construct an electronic soundscape reflecting planet Solaris' amorphous and mysterious surface")
228
 
 
 
229
 
230
  else:
231
  text= st.text_input("Type here your text and press enter to run:", value="12 Corazones ('12 Hearts') is Spanish-language dating game show produced in the United States for the television network Telemundo since January 2005, based on its namesake Argentine TV show format. The show is filmed in Los Angeles and revolves around the twelve Zodiac signs that identify each contestant. In 2008, Ho filmed a cameo in the Steven Spielberg feature film The Cloverfield Paradox, as a news pundit.")
 
61
 
62
 
63
  #sidebar info
64
+ model_name= ["nerdl_fewnerd_100d", "ner_conll_elmo", "ner_mit_movie_complex_distilbert_base_cased", "ner_conll_albert_large_uncased"]
65
  st.sidebar.title("Pretrained model to test")
66
  selected_model = st.sidebar.selectbox("", model_name)
67
 
 
73
  st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True)
74
  st.markdown("**`PERSON`** **,** **`ORGANIZATION`** **,** **`LOCATION`** **,** **`ART`** **,** **`BUILDING`** **,** **`PRODUCT`** **,** **`EVENT`** **,** **`OTHER`**", unsafe_allow_html=True)
75
 
76
+ elif selected_model== "ner_conll_elmo":
77
+ app_title= "Detect up to 4 entity types in general domain texts"
78
+ app_description= "Named Entity Recognition model aimed to detect up to 4 entity types from general domain texts. This model was trained on the CoNLL 2003 text corpu using Spark NLP, and it is available in Spark NLP Models hub (https://nlp.johnsnowlabs.com/models)"
79
  st.title(app_title)
80
  st.markdown("<h2>"+app_description+"</h2>" , unsafe_allow_html=True)
81
+ st.markdown("**`PER`** **,** **`LOC`** **,** **`ORG`** **,** **`MISC` **", unsafe_allow_html=True)
 
 
82
 
83
 
84
  elif selected_model== "ner_mit_movie_complex_distilbert_base_cased":
 
140
  ner_converter
141
  ])
142
 
143
+ elif selected_model=="ner_conll_elmo":
144
+ embeddings = ElmoEmbeddings\
145
+ .pretrained('elmo', 'en')\
146
+ .setInputCols(["token", "document"])\
147
+ .setOutputCol("embeddings")\
148
+ .setPoolingLayer("elmo")
149
+
150
+ ner = NerDLModel.pretrained('ner_conll_elmo', 'en') \
151
+ .setInputCols(['document', 'token', 'embeddings']) \
152
+ .setOutputCol('ner')
153
 
154
  ner_converter= NerConverter()\
155
  .setInputCols(["document", "token", "ner"])\
 
160
  documentAssembler,
161
  sentenceDetector,
162
  tokenizer,
163
+ embeddings,
164
+ ner,
165
  ner_converter
166
  ])
167
 
 
223
 
224
  return result
225
 
226
+ if selected_model=="ner_conll_albert_large_uncased":
227
+ text= st.text_input("Type here your text and press enter to run:", value="Mark Knopfler was born in Glasgow, Scotland. He is a British singer-songwriter, guitarist, and record producer. He became known as the lead guitarist, singer and songwriter of the rock band Dire Straits.")
228
+
229
 
230
 
231
+ elif selected_model=="ner_mit_movie_complex_distilbert_base_cased":
232
+ text= st.text_input("Type here your text and press enter to run:", value="It's only appropriate that Solaris, Russian filmmaker Andrei Tarkovsky's psychological sci-fi classic from 1972, contains an equally original and mind-bending score. Solaris explores the inadequacies of time and memory on an enigmatic planet below a derelict space station. To reinforce the film's chilling setting, Tarkovsky commissioned composer Eduard Artemiev to construct an electronic soundscape reflecting planet Solaris' amorphous and mysterious surface")
233
 
234
+ elif selected_model=="ner_conll_elmo":
235
+ text= st.text_input("Type here your text and press enter to run: ", value="Tottenham Hotspur Football Club, commonly referred to as Tottenham or Spurs, is an English professional football club based in Tottenham, London, that competes in the Premier League, the top flight of English football.")
236
 
237
  else:
238
  text= st.text_input("Type here your text and press enter to run:", value="12 Corazones ('12 Hearts') is Spanish-language dating game show produced in the United States for the television network Telemundo since January 2005, based on its namesake Argentine TV show format. The show is filmed in Los Angeles and revolves around the twelve Zodiac signs that identify each contestant. In 2008, Ho filmed a cameo in the Steven Spielberg feature film The Cloverfield Paradox, as a news pundit.")