zmbfeng commited on
Commit
8ebc1ba
1 Parent(s): 7a26524

single sentence contradition detection refactored

Browse files
Files changed (1) hide show
  1. app.py +32 -35
app.py CHANGED
@@ -197,7 +197,38 @@ if uploaded_pdf_file is not None:
197
  st.session_state.list_count = len(st.session_state.restored_paragraphs)
198
  st.write(f'The number of elements at the top level of the hierarchy: {st.session_state.list_count}')
199
  st.rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
 
 
 
 
 
201
  def find_sentences_scores(paragraph_sentence_encodings, query_encoding, processing_progress_bar,total_count):
202
  paragraph_scores = []
203
  sentence_scores = []
@@ -251,42 +282,8 @@ if 'paragraph_sentence_encodings' in st.session_state:
251
  if 'prev_query' not in st.session_state or st.session_state.prev_query != query:
252
  st.session_state.prev_query = query
253
  st.session_state.premise = query
 
254
 
255
- query_encoding = encode_sentence(query)
256
-
257
- total_count = len(st.session_state.paragraph_sentence_encodings)
258
- processing_progress_bar = st.progress(0)
259
-
260
-
261
-
262
- sentence_scores,paragraph_scores = find_sentences_scores(
263
- st.session_state.paragraph_sentence_encodings, query_encoding, processing_progress_bar,total_count)
264
-
265
- sorted_paragraph_scores = sorted(paragraph_scores, key=lambda x: x[0], reverse=True)
266
-
267
-
268
-
269
- st.write("Top scored paragraphs and their scores:")
270
- for i, (similarity_score, commonality_score, paragraph) in enumerate(
271
- sorted_paragraph_scores[:3]): #number of paragraphs to consider
272
- #st.write("top_three_sentences: ", paragraph['top_three_sentences'])
273
- st.write("paragarph number ***", i)
274
- prev_contradiction_detected =True
275
- for top_sentence in paragraph['top_three_sentences']:
276
-
277
- if prev_contradiction_detected:
278
- contradiction_detection_result =contradiction_detection(st.session_state.premise,top_sentence[1])
279
- if contradiction_detection_result == {"Contradiction"}:
280
- st.write("master document page number ", paragraph['original_text']['page_num'])
281
- st.write("master document sentence: ", top_sentence[1])
282
- st.write("secondary document sentence: ", st.session_state.premise)
283
- st.write(contradiction_detection_result)
284
- # st.write(contradiction_detection(st.session_state.premise, top_sentence[1]))
285
-
286
- else:
287
- prev_contradiction_detected = False
288
- else:
289
- break
290
 
291
  #print(top_sentence[1])
292
  # st.write(f"Similarity Score: {similarity_score}, Commonality Score: {commonality_score}")
 
197
  st.session_state.list_count = len(st.session_state.restored_paragraphs)
198
  st.write(f'The number of elements at the top level of the hierarchy: {st.session_state.list_count}')
199
  st.rerun()
200
+ def contradiction_detection_for_sentence(query):
201
+ query_encoding = encode_sentence(query)
202
+
203
+ total_count = len(st.session_state.paragraph_sentence_encodings)
204
+ processing_progress_bar = st.progress(0)
205
+
206
+ sentence_scores, paragraph_scores = find_sentences_scores(
207
+ st.session_state.paragraph_sentence_encodings, query_encoding, processing_progress_bar, total_count)
208
+
209
+ sorted_paragraph_scores = sorted(paragraph_scores, key=lambda x: x[0], reverse=True)
210
+
211
+ st.write("Top scored paragraphs and their scores:")
212
+ for i, (similarity_score, commonality_score, paragraph) in enumerate(
213
+ sorted_paragraph_scores[:3]): # number of paragraphs to consider
214
+ # st.write("top_three_sentences: ", paragraph['top_three_sentences'])
215
+ st.write("paragarph number ***", i)
216
+ prev_contradiction_detected = True
217
+ for top_sentence in paragraph['top_three_sentences']:
218
+
219
+ if prev_contradiction_detected:
220
+ contradiction_detection_result = contradiction_detection(st.session_state.premise, top_sentence[1])
221
+ if contradiction_detection_result == {"Contradiction"}:
222
+ st.write("master document page number ", paragraph['original_text']['page_num'])
223
+ st.write("master document sentence: ", top_sentence[1])
224
+ st.write("secondary document sentence: ", st.session_state.premise)
225
+ st.write(contradiction_detection_result)
226
+ # st.write(contradiction_detection(st.session_state.premise, top_sentence[1]))
227
 
228
+ else:
229
+ prev_contradiction_detected = False
230
+ else:
231
+ break
232
  def find_sentences_scores(paragraph_sentence_encodings, query_encoding, processing_progress_bar,total_count):
233
  paragraph_scores = []
234
  sentence_scores = []
 
282
  if 'prev_query' not in st.session_state or st.session_state.prev_query != query:
283
  st.session_state.prev_query = query
284
  st.session_state.premise = query
285
+ contradiction_detection_for_sentence(query)
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
 
288
  #print(top_sentence[1])
289
  # st.write(f"Similarity Score: {similarity_score}, Commonality Score: {commonality_score}")