xuandin commited on
Commit
c616050
·
verified ·
1 Parent(s): 0be0916

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -78
app.py CHANGED
@@ -94,6 +94,7 @@ def perform_verification(claim, context, model_qatc, tokenizer_qatc, model_tc, t
94
  torch.cuda.empty_cache()
95
  gc.collect()
96
 
 
97
  # Parallel classification using ThreadPoolExecutor
98
  with ThreadPoolExecutor(max_workers=2) as executor:
99
  future_tc = executor.submit(cached_classify_claim, claim, evidence, tc_model_name, False)
@@ -102,7 +103,6 @@ def perform_verification(claim, context, model_qatc, tokenizer_qatc, model_tc, t
102
  prob3class, pred_tc = future_tc.result()
103
  prob2class, pred_bc = future_bc.result()
104
 
105
- verdict_start_time = time.time()
106
  with torch.no_grad():
107
  verdict = "NEI"
108
  if pred_tc != 0:
@@ -137,7 +137,7 @@ def monitor_performance():
137
 
138
  # Set page configuration
139
  st.set_page_config(
140
- page_title="SemViQA - Hệ thống Kiểm chứng Thông tin Tiếng Việt",
141
  page_icon="🔍",
142
  layout="wide",
143
  initial_sidebar_state="expanded"
@@ -340,18 +340,18 @@ st.markdown("""
340
  st.markdown("""
341
  <div class="main-header">
342
  <div class="main-title">SemViQA</div>
343
- <div class="sub-title">Hệ thống Kiểm chứng Thông tin Tiếng Việt</div>
344
  </div>
345
  """, unsafe_allow_html=True)
346
 
347
  # Sidebar
348
  with st.sidebar:
349
- st.markdown("### ⚙️ Cài đặt Hệ thống")
350
 
351
  # Model selection
352
- st.markdown("#### 🧠 Chọn Mô hình")
353
  qatc_model_name = st.selectbox(
354
- " hình QATC",
355
  [
356
  "SemViQA/qatc-infoxlm-viwikifc",
357
  "SemViQA/qatc-infoxlm-isedsc01",
@@ -361,7 +361,7 @@ with st.sidebar:
361
  )
362
 
363
  bc_model_name = st.selectbox(
364
- " hình Phân loại Nhị phân",
365
  [
366
  "SemViQA/bc-xlmr-viwikifc",
367
  "SemViQA/bc-xlmr-isedsc01",
@@ -373,7 +373,7 @@ with st.sidebar:
373
  )
374
 
375
  tc_model_name = st.selectbox(
376
- " hình Phân loại Ba lớp",
377
  [
378
  "SemViQA/tc-xlmr-viwikifc",
379
  "SemViQA/tc-xlmr-isedsc01",
@@ -385,40 +385,40 @@ with st.sidebar:
385
  )
386
 
387
  # Threshold settings
388
- st.markdown("#### ⚖️ Ngưỡng Phân tích")
389
  tfidf_threshold = st.slider(
390
- "Ngưỡng TF-IDF",
391
  0.0, 1.0, 0.5,
392
- help="Điều chỉnh độ nhạy trong việc tìm kiếm bằng chứng"
393
  )
394
 
395
  length_ratio_threshold = st.slider(
396
- "Ngưỡng Tỷ lệ Độ dài",
397
  0.1, 1.0, 0.5,
398
- help="Điều chỉnh độ dài tối đa của bằng chứng"
399
  )
400
 
401
  # Display settings
402
- st.markdown("#### 👁️ Hiển thị")
403
  show_details = st.checkbox(
404
- "Hiển thị Chi tiết Xác suất",
405
  value=False,
406
- help="Hiển thị thông tin chi tiết về xác suất dự đoán"
407
  )
408
 
409
  # Performance settings
410
- st.markdown("#### ⚡ Hiệu suất")
411
  num_threads = st.slider(
412
- "Số luồng CPU",
413
  1, psutil.cpu_count(),
414
  psutil.cpu_count(logical=False),
415
- help="Điều chỉnh hiệu suất xử lý"
416
  )
417
  os.environ["OMP_NUM_THREADS"] = str(num_threads)
418
  os.environ["MKL_NUM_THREADS"] = str(num_threads)
419
 
420
  # Main content
421
- tabs = st.tabs(["🔍 Kiểm chứng", "📊 Lịch sử", "ℹ️ Thông tin"])
422
 
423
  tokenizer_qatc, model_qatc = load_model(qatc_model_name, QATCForQuestionAnswering, device=DEVICE)
424
  tokenizer_bc, model_bc = load_model(bc_model_name, ClaimModelForClassification, is_bc=True, device=DEVICE)
@@ -434,25 +434,25 @@ with tabs[0]:
434
  col1, col2 = st.columns([2, 1])
435
 
436
  with col1:
437
- st.markdown("### 📝 Nhập Thông tin")
438
  claim = st.text_area(
439
- "Câu khẳng định cần kiểm chứng",
440
  "Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất.",
441
- help="Nhập câu khẳng định cần được kiểm chứng"
442
  )
443
 
444
  context = st.text_area(
445
- "Ngữ cảnh",
446
  "Sau khi thống nhất, Việt Nam tiếp tục gặp khó khăn do sự sụp đổ và tan rã của đồng minh Liên Xô cùng Khối phía Đông, các lệnh cấm vận của Hoa Kỳ, chiến tranh với Campuchia, biên giới giáp Trung Quốc và hậu quả của chính sách bao cấp sau nhiều năm áp dụng. Năm 1986, Đảng Cộng sản ban hành cải cách đổi mới, tạo điều kiện hình thành kinh tế thị trường và hội nhập sâu rộng. Cải cách đổi mới kết hợp cùng quy mô dân số lớn đưa Việt Nam trở thành một trong những nước đang phát triển có tốc độ tăng trưởng thuộc nhóm nhanh nhất thế giới, được coi là Hổ mới châu Á dù cho vẫn gặp phải những thách thức như tham nhũng, tội phạm gia tăng, ô nhiễm môi trường và phúc lợi xã hội chưa đầy đủ. Ngoài ra, giới bất đồng chính kiến, chính phủ một số nước phương Tây và các tổ chức theo dõi nhân quyền có quan điểm chỉ trích hồ sơ nhân quyền của Việt Nam liên quan đến các vấn đề tôn giáo, kiểm duyệt truyền thông, hạn chế hoạt động ủng hộ nhân quyền cùng các quyền tự do dân sự.",
447
- help="Nhập ngữ cảnh hoặc văn bản tham khảo"
448
  )
449
 
450
- verify_button = st.button("🔍 Kiểm chứng", use_container_width=True)
451
 
452
  with col2:
453
- st.markdown("### 📊 Kết quả")
454
  if verify_button:
455
- with st.spinner("Đang kiểm chứng..."):
456
  # Preprocess texts
457
  preprocessed_claim = preprocess_text(claim)
458
  preprocessed_context = preprocess_text(context)
@@ -526,17 +526,17 @@ with tabs[0]:
526
 
527
  st.markdown(f"""
528
  <div class="result-box">
529
- <h3>Kết quả Kiểm chứng</h3>
530
- <p><strong>Câu khẳng định:</strong> {res['claim']}</p>
531
- <p><strong>Bằng chứng:</strong> {res['evidence']}</p>
532
  <p class="verdict {verdict_class}">
533
  {verdict_icons.get(res['verdict'], '')} {res['verdict']}
534
  </p>
535
  <div class="stats-box">
536
- <p><strong>Thời gian trích xuất bằng chứng:</strong> {res['evidence_time']:.2f} giây</p>
537
- <p><strong>Thời gian phân loại:</strong> {res['verdict_time']:.2f} giây</p>
538
- <p><strong>Tổng thời gian:</strong> {res['total_time']:.2f} giây</p>
539
- <p><strong>Hiệu suất:</strong></p>
540
  <ul>
541
  <li>CPU: {res['performance_metrics']['cpu_percent']}%</li>
542
  <li>RAM: {res['performance_metrics']['memory_percent']}%</li>
@@ -549,35 +549,35 @@ with tabs[0]:
549
 
550
  # Download button with performance metrics
551
  result_text = f"""
552
- Câu khẳng định: {res['claim']}
553
- Bằng chứng: {res['evidence']}
554
- Kết luận: {res['verdict']}
555
- Chi tiết: {res['details']}
556
 
557
- Hiệu suất:
558
  - CPU: {res['performance_metrics']['cpu_percent']}%
559
  - RAM: {res['performance_metrics']['memory_percent']}%
560
  {f"- GPU Memory: {res['performance_metrics'].get('gpu_memory_used', 'N/A'):.2f} MB" if DEVICE == "cuda" else ""}
561
  """
562
  st.download_button(
563
- "📥 Tải kết quả",
564
  data=result_text,
565
- file_name="ket_qua_kiem_chung.txt",
566
  mime="text/plain"
567
  )
568
  else:
569
- st.info("Vui lòng nhập thông tin nhấn nút Kiểm chứng để bắt đầu.")
570
 
571
  # --- Tab History ---
572
  with tabs[1]:
573
- st.markdown("### 📊 Lịch sử Kiểm chứng")
574
  if 'history' in st.session_state and st.session_state.history:
575
  # Download full history
576
  history_df = pd.DataFrame(st.session_state.history)
577
  st.download_button(
578
- "📥 Tải toàn bộ lịch sử",
579
  data=history_df.to_csv(index=False).encode('utf-8'),
580
- file_name="lich_su_kiem_chung.csv",
581
  mime="text/csv"
582
  )
583
 
@@ -585,42 +585,36 @@ with tabs[1]:
585
  for idx, record in enumerate(reversed(st.session_state.history), 1):
586
  st.markdown(f"""
587
  <div class="result-box">
588
- <h4>Kiểm chứng #{idx}</h4>
589
- <p><strong>Câu khẳng định:</strong> {record['claim']}</p>
590
- <p><strong>Kết luận:</strong> {verdict_icons.get(record['verdict'], '')} {record['verdict']}</p>
591
- <p><strong>Thời gian:</strong> {record['total_time']:.2f} giây</p>
592
  </div>
593
  """, unsafe_allow_html=True)
594
  else:
595
- st.info("Chưa lịch sử kiểm chứng.")
596
 
597
  # --- Tab Info ---
598
  with tabs[2]:
599
  st.markdown("""
600
- <div class="info-section">
601
- <h3>ℹ️ Thông tin về SemViQA</h3>
602
- <p>SemViQA là hệ thống kiểm chứng thông tin tự động cho tiếng Việt, được phát triển bởi nhóm nghiên cứu tại Đại học Công nghệ Thông tin - Đại học Quốc gia TP.HCM.</p>
603
-
604
- <h4>🔍 Cách sử dụng</h4>
605
- <ol>
606
- <li>Nhập câu khẳng định cần kiểm chứng</li>
607
- <li>Nhập ngữ cảnh hoặc văn bản tham khảo</li>
608
- <li>Điều chỉnh các tham số trong phần Cài đặt nếu cần</li>
609
- <li>Nhấn nút Kiểm chứng</li>
610
- </ol>
611
-
612
- <h4>⚙️ Các tham số</h4>
613
- <ul>
614
- <li><strong>Ngưỡng TF-IDF:</strong> Điều chỉnh độ nhạy trong việc tìm kiếm bằng chứng</li>
615
- <li><strong>Ngưỡng Tỷ lệ Độ dài:</strong> Điều chỉnh độ dài tối đa của bằng chứng</li>
616
- <li><strong>Số luồng CPU:</strong> Điều chỉnh hiệu suất xử lý</li>
617
- </ul>
618
-
619
- <h4>📊 Kết quả</h4>
620
- <ul>
621
- <li><strong>SUPPORTED:</strong> Câu khẳng định được hỗ trợ bởi bằng chứng</li>
622
- <li><strong>REFUTED:</strong> Câu khẳng định bị bác bỏ bởi bằng chứng</li>
623
- <li><strong>NEI:</strong> Không đủ bằng chứng để kết luận</li>
624
- </ul>
625
- </div>
626
- """, unsafe_allow_html=True)
 
94
  torch.cuda.empty_cache()
95
  gc.collect()
96
 
97
+ verdict_start_time = time.time()
98
  # Parallel classification using ThreadPoolExecutor
99
  with ThreadPoolExecutor(max_workers=2) as executor:
100
  future_tc = executor.submit(cached_classify_claim, claim, evidence, tc_model_name, False)
 
103
  prob3class, pred_tc = future_tc.result()
104
  prob2class, pred_bc = future_bc.result()
105
 
 
106
  with torch.no_grad():
107
  verdict = "NEI"
108
  if pred_tc != 0:
 
137
 
138
  # Set page configuration
139
  st.set_page_config(
140
+ page_title="SemViQA - A Semantic Question Answering System for Vietnamese Information Fact-Checking",
141
  page_icon="🔍",
142
  layout="wide",
143
  initial_sidebar_state="expanded"
 
340
  st.markdown("""
341
  <div class="main-header">
342
  <div class="main-title">SemViQA</div>
343
+ <div class="sub-title">A Semantic Question Answering System for Vietnamese Information Fact-Checking</div>
344
  </div>
345
  """, unsafe_allow_html=True)
346
 
347
  # Sidebar
348
  with st.sidebar:
349
+ st.markdown("### ⚙️ System Settings")
350
 
351
  # Model selection
352
+ st.markdown("#### 🧠 Model Selection")
353
  qatc_model_name = st.selectbox(
354
+ "QATC Model",
355
  [
356
  "SemViQA/qatc-infoxlm-viwikifc",
357
  "SemViQA/qatc-infoxlm-isedsc01",
 
361
  )
362
 
363
  bc_model_name = st.selectbox(
364
+ "Binary Classification Model",
365
  [
366
  "SemViQA/bc-xlmr-viwikifc",
367
  "SemViQA/bc-xlmr-isedsc01",
 
373
  )
374
 
375
  tc_model_name = st.selectbox(
376
+ "Three-Class Classification Model",
377
  [
378
  "SemViQA/tc-xlmr-viwikifc",
379
  "SemViQA/tc-xlmr-isedsc01",
 
385
  )
386
 
387
  # Threshold settings
388
+ st.markdown("#### ⚖️ Analysis Thresholds")
389
  tfidf_threshold = st.slider(
390
+ "Confidence Threshold",
391
  0.0, 1.0, 0.5,
392
+ help="Adjust sensitivity in evidence search"
393
  )
394
 
395
  length_ratio_threshold = st.slider(
396
+ "Length Ratio Threshold",
397
  0.1, 1.0, 0.5,
398
+ help="Adjust maximum evidence length"
399
  )
400
 
401
  # Display settings
402
+ st.markdown("#### 👁️ Display")
403
  show_details = st.checkbox(
404
+ "Show Probability Details",
405
  value=False,
406
+ help="Display detailed probability information"
407
  )
408
 
409
  # Performance settings
410
+ st.markdown("#### ⚡ Performance")
411
  num_threads = st.slider(
412
+ "CPU Threads",
413
  1, psutil.cpu_count(),
414
  psutil.cpu_count(logical=False),
415
+ help="Adjust processing performance"
416
  )
417
  os.environ["OMP_NUM_THREADS"] = str(num_threads)
418
  os.environ["MKL_NUM_THREADS"] = str(num_threads)
419
 
420
  # Main content
421
+ tabs = st.tabs(["🔍 Verify", "📊 History", "ℹ️ Info"])
422
 
423
  tokenizer_qatc, model_qatc = load_model(qatc_model_name, QATCForQuestionAnswering, device=DEVICE)
424
  tokenizer_bc, model_bc = load_model(bc_model_name, ClaimModelForClassification, is_bc=True, device=DEVICE)
 
434
  col1, col2 = st.columns([2, 1])
435
 
436
  with col1:
437
+ st.markdown("### 📝 Input Information")
438
  claim = st.text_area(
439
+ "Claim to Verify",
440
  "Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất.",
441
+ help="Enter the claim to be verified"
442
  )
443
 
444
  context = st.text_area(
445
+ "Context",
446
  "Sau khi thống nhất, Việt Nam tiếp tục gặp khó khăn do sự sụp đổ và tan rã của đồng minh Liên Xô cùng Khối phía Đông, các lệnh cấm vận của Hoa Kỳ, chiến tranh với Campuchia, biên giới giáp Trung Quốc và hậu quả của chính sách bao cấp sau nhiều năm áp dụng. Năm 1986, Đảng Cộng sản ban hành cải cách đổi mới, tạo điều kiện hình thành kinh tế thị trường và hội nhập sâu rộng. Cải cách đổi mới kết hợp cùng quy mô dân số lớn đưa Việt Nam trở thành một trong những nước đang phát triển có tốc độ tăng trưởng thuộc nhóm nhanh nhất thế giới, được coi là Hổ mới châu Á dù cho vẫn gặp phải những thách thức như tham nhũng, tội phạm gia tăng, ô nhiễm môi trường và phúc lợi xã hội chưa đầy đủ. Ngoài ra, giới bất đồng chính kiến, chính phủ một số nước phương Tây và các tổ chức theo dõi nhân quyền có quan điểm chỉ trích hồ sơ nhân quyền của Việt Nam liên quan đến các vấn đề tôn giáo, kiểm duyệt truyền thông, hạn chế hoạt động ủng hộ nhân quyền cùng các quyền tự do dân sự.",
447
+ help="Enter context or reference text"
448
  )
449
 
450
+ verify_button = st.button("🔍 Verify", use_container_width=True)
451
 
452
  with col2:
453
+ st.markdown("### 📊 Results")
454
  if verify_button:
455
+ with st.spinner("Verifying..."):
456
  # Preprocess texts
457
  preprocessed_claim = preprocess_text(claim)
458
  preprocessed_context = preprocess_text(context)
 
526
 
527
  st.markdown(f"""
528
  <div class="result-box">
529
+ <h3>Verification Results</h3>
530
+ <p><strong>Claim:</strong> {res['claim']}</p>
531
+ <p><strong>Evidence:</strong> {res['evidence']}</p>
532
  <p class="verdict {verdict_class}">
533
  {verdict_icons.get(res['verdict'], '')} {res['verdict']}
534
  </p>
535
  <div class="stats-box">
536
+ <p><strong>Evidence Extraction Time:</strong> {res['evidence_time']:.2f} seconds</p>
537
+ <p><strong>Classification Time:</strong> {res['verdict_time']:.2f} seconds</p>
538
+ <p><strong>Total Time:</strong> {res['total_time']:.2f} seconds</p>
539
+ <p><strong>Performance:</strong></p>
540
  <ul>
541
  <li>CPU: {res['performance_metrics']['cpu_percent']}%</li>
542
  <li>RAM: {res['performance_metrics']['memory_percent']}%</li>
 
549
 
550
  # Download button with performance metrics
551
  result_text = f"""
552
+ Claim: {res['claim']}
553
+ Evidence: {res['evidence']}
554
+ Verdict: {res['verdict']}
555
+ Details: {res['details']}
556
 
557
+ Performance:
558
  - CPU: {res['performance_metrics']['cpu_percent']}%
559
  - RAM: {res['performance_metrics']['memory_percent']}%
560
  {f"- GPU Memory: {res['performance_metrics'].get('gpu_memory_used', 'N/A'):.2f} MB" if DEVICE == "cuda" else ""}
561
  """
562
  st.download_button(
563
+ "📥 Download Results",
564
  data=result_text,
565
+ file_name="verification_results.txt",
566
  mime="text/plain"
567
  )
568
  else:
569
+ st.info("Please enter information and click Verify to begin.")
570
 
571
  # --- Tab History ---
572
  with tabs[1]:
573
+ st.markdown("### 📊 Verification History")
574
  if 'history' in st.session_state and st.session_state.history:
575
  # Download full history
576
  history_df = pd.DataFrame(st.session_state.history)
577
  st.download_button(
578
+ "📥 Download Full History",
579
  data=history_df.to_csv(index=False).encode('utf-8'),
580
+ file_name="verification_history.csv",
581
  mime="text/csv"
582
  )
583
 
 
585
  for idx, record in enumerate(reversed(st.session_state.history), 1):
586
  st.markdown(f"""
587
  <div class="result-box">
588
+ <h4>Verification #{idx}</h4>
589
+ <p><strong>Claim:</strong> {record['claim']}</p>
590
+ <p><strong>Verdict:</strong> {verdict_icons.get(record['verdict'], '')} {record['verdict']}</p>
591
+ <p><strong>Time:</strong> {record['total_time']:.2f} seconds</p>
592
  </div>
593
  """, unsafe_allow_html=True)
594
  else:
595
+ st.info("No verification history available.")
596
 
597
  # --- Tab Info ---
598
  with tabs[2]:
599
  st.markdown("""
600
+ ### ℹ️ About SemViQA
601
+ **Author:** [**Nam V. Nguyen**](https://github.com/DAVID-NGUYEN-S16), [**Dien X. Tran**](https://github.com/xndien2004), Thanh T. Tran, Anh T. Hoang, Tai V. Duong, Di T. Le, Phuc-Lu Le
602
+
603
+ SemViQA is a cutting-edge Vietnamese fact-checking system designed to combat misinformation. It leverages semantic-based evidence retrieval (SER) and a two-step verdict classification (TVC) approach to verify claims efficiently. By combining TF-IDF with a Question Answering Token Classifier (QATC), SemViQA improves accuracy while reducing inference time. Achieving state-of-the-art performance, it has set new benchmarks on ViWikiFC (80.82% accuracy) and ISE-DSC01 (78.97% accuracy) datasets. With its 7x speed boost, SemViQA is a powerful tool for ensuring information integrity in the Vietnamese language.
604
+
605
+ #### 🔍 How to Use
606
+ 1. Enter the claim to verify
607
+ 2. Enter context or reference text
608
+ 3. Adjust parameters in Settings if needed
609
+ 4. Click Verify button
610
+
611
+ #### ⚙️ Parameters
612
+ - **Confidence Threshold:** Adjust sensitivity in evidence search
613
+ - **Length Ratio Threshold:** An important parameter in the evidence retrieval process. It determines how text segments are processed when compared to the length of the claim to be verified.
614
+ - **CPU Threads:** Adjust processing performance
615
+
616
+ #### 📊 Results
617
+ - **SUPPORTED:** The claim is supported by evidence
618
+ - **REFUTED:** The claim is refuted by evidence
619
+ - **NEI:** Not enough information to conclude
620
+ """)