JasonTPhillipsJr commited on
Commit
4b2b2d4
·
verified ·
1 Parent(s): 4aae01c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -90,15 +90,22 @@ def process_entity(batch, model, device):
90
  spaBERT_embedding = spaBERT_embedding[:, 0, :].detach() # [batch_size, hidden_size]
91
 
92
  #return pivot_embeddings.cpu().numpy(), input_ids.cpu().numpy()
93
- return spaBERT_embedding, input_ids
94
 
95
  spaBERT_embeddings = []
 
96
  for batch in (data_loader):
97
- spaBERT_embedding, input_ids = process_entity(batch, spaBERT_model, device)
98
  spaBERT_embeddings.append(spaBERT_embedding)
 
99
 
100
- embedding_cache = {}
 
 
 
101
 
 
 
102
 
103
  #Get BERT Embedding for review
104
  def get_bert_embedding(review_text):
@@ -257,7 +264,7 @@ selected_key = user_selection.split(" (")[0] # Remove the label part
257
  selected_review = example_reviews[selected_key]
258
 
259
  # Process the text when the button is clicked
260
- if st.button("Highlight Geo-Entities"):
261
  if selected_review.strip():
262
  bert_embedding = get_bert_embedding(selected_review)
263
  spaBert_embedding = processSpatialEntities(selected_review,nlp)
@@ -270,14 +277,7 @@ if st.button("Highlight Geo-Entities"):
270
  st.write("Concatenated Embedding:", combined_embedding)
271
 
272
  prediction = get_prediction(combined_embedding)
273
-
274
- if(prediction == 0):
275
- st.write("Prediction: Not Spam")
276
- elif(prediction == 1):
277
- st.write("Prediction: Spam")
278
- else:
279
- st.write("error during prediction")
280
-
281
  # Process the text using spaCy
282
  doc = nlp(selected_review)
283
 
@@ -294,5 +294,14 @@ if st.button("Highlight Geo-Entities"):
294
 
295
  # Display the highlighted text with HTML support
296
  st.markdown(highlighted_text, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
297
  else:
298
  st.error("Please select a review.")
 
90
  spaBERT_embedding = spaBERT_embedding[:, 0, :].detach() # [batch_size, hidden_size]
91
 
92
  #return pivot_embeddings.cpu().numpy(), input_ids.cpu().numpy()
93
+ return spaBERT_embedding, input_ids, pseudo_sentence_decoded
94
 
95
  spaBERT_embeddings = []
96
+ pseudo_sentences = []
97
  for batch in (data_loader):
98
+ spaBERT_embedding, input_ids, pseudo_sentence = process_entity(batch, spaBERT_model, device)
99
  spaBERT_embeddings.append(spaBERT_embedding)
100
+ pseudo_sentences.append(pseudo_sentence)
101
 
102
+ # Print all the pseudo sentences
103
+ print("Pseudo Sentences:")
104
+ for idx, sentence in enumerate(pseudo_sentences):
105
+ print(f"{idx + 1}: {sentence}")
106
 
107
+
108
+ embedding_cache = {}
109
 
110
  #Get BERT Embedding for review
111
  def get_bert_embedding(review_text):
 
264
  selected_review = example_reviews[selected_key]
265
 
266
  # Process the text when the button is clicked
267
+ if st.button("Process Review"):
268
  if selected_review.strip():
269
  bert_embedding = get_bert_embedding(selected_review)
270
  spaBert_embedding = processSpatialEntities(selected_review,nlp)
 
277
  st.write("Concatenated Embedding:", combined_embedding)
278
 
279
  prediction = get_prediction(combined_embedding)
280
+
 
 
 
 
 
 
 
281
  # Process the text using spaCy
282
  doc = nlp(selected_review)
283
 
 
294
 
295
  # Display the highlighted text with HTML support
296
  st.markdown(highlighted_text, unsafe_allow_html=True)
297
+
298
+ #Display the models prediction
299
+ if(prediction == 0):
300
+ st.write("Prediction: Not Spam")
301
+ elif(prediction == 1):
302
+ st.write("Prediction: Spam")
303
+ else:
304
+ st.write("error during prediction")
305
+
306
  else:
307
  st.error("Please select a review.")