Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -119,6 +119,21 @@ st.markdown(
|
|
119 |
# Container for the whole content with dynamic height
|
120 |
with st.container():
|
121 |
st.markdown("<p class='big-title'>SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
st.markdown("<p class='sub-title'>Enter the claim and context to verify its accuracy</p>", unsafe_allow_html=True)
|
123 |
|
124 |
# Sidebar: Global Settings
|
@@ -185,8 +200,8 @@ with st.container():
|
|
185 |
st.markdown("<h3>Verification Result</h3>", unsafe_allow_html=True)
|
186 |
if verify_button:
|
187 |
# Placeholder for displaying result/loading
|
188 |
-
with st.spinner("Verifying..."):
|
189 |
-
start_time = time.time()
|
190 |
|
191 |
with torch.no_grad():
|
192 |
# Extract evidence
|
@@ -286,24 +301,361 @@ with st.container():
|
|
286 |
# --- Tab About ---
|
287 |
with tabs[2]:
|
288 |
st.subheader("About")
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
# Container for the whole content with dynamic height
|
120 |
with st.container():
|
121 |
st.markdown("<p class='big-title'>SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking</p>", unsafe_allow_html=True)
|
122 |
+
st.markdown("""
|
123 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
124 |
+
<p><strong>Developed by:</strong></p>
|
125 |
+
<p>
|
126 |
+
<a href="https://github.com/DAVID-NGUYEN-S16">Nam V. Nguyen</a>,
|
127 |
+
<a href="https://github.com/xndien2004">Dien X. Tran</a>,
|
128 |
+
Thanh T. Tran,
|
129 |
+
Anh T. Hoang,
|
130 |
+
Tai V. Duong,
|
131 |
+
Di T. Le,
|
132 |
+
Phuc-Lu Le
|
133 |
+
</p>
|
134 |
+
<p><strong>Equal Contribution:</strong> Nam V. Nguyen, Dien X. Tran</p>
|
135 |
+
</div>
|
136 |
+
""", unsafe_allow_html=True)
|
137 |
st.markdown("<p class='sub-title'>Enter the claim and context to verify its accuracy</p>", unsafe_allow_html=True)
|
138 |
|
139 |
# Sidebar: Global Settings
|
|
|
200 |
st.markdown("<h3>Verification Result</h3>", unsafe_allow_html=True)
|
201 |
if verify_button:
|
202 |
# Placeholder for displaying result/loading
|
203 |
+
with st.spinner("Verifying..."):
|
204 |
+
start_time = time.time()
|
205 |
|
206 |
with torch.no_grad():
|
207 |
# Extract evidence
|
|
|
301 |
# --- Tab About ---
|
302 |
with tabs[2]:
|
303 |
st.subheader("About")
|
304 |
+
about_content = '''
|
305 |
+
<p align="center">
|
306 |
+
<img alt="SemViQA Logo" src="image/logo.png" height="250" />
|
307 |
+
<br>
|
308 |
+
</p>
|
309 |
+
</p>
|
310 |
+
|
311 |
+
# **SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking**
|
312 |
+
|
313 |
+
### **Authors**:
|
314 |
+
[**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
|
315 |
+
<p align="center">
|
316 |
+
<a href="https://arxiv.org/abs/2503.00955">
|
317 |
+
<img src="https://img.shields.io/badge/arXiv-2411.00918-red?style=flat&label=arXiv">
|
318 |
+
</a>
|
319 |
+
<a href="https://huggingface.co/SemViQA">
|
320 |
+
<img src="https://img.shields.io/badge/Hugging%20Face-Model-yellow?style=flat">
|
321 |
+
</a>
|
322 |
+
<a href="https://pypi.org/project/SemViQA">
|
323 |
+
<img src="https://img.shields.io/pypi/v/SemViQA?color=blue&label=PyPI">
|
324 |
+
</a>
|
325 |
+
<a href="https://github.com/DAVID-NGUYEN-S16/SemViQA">
|
326 |
+
<img src="https://img.shields.io/github/stars/DAVID-NGUYEN-S16/SemViQA?style=social">
|
327 |
+
</a>
|
328 |
+
</p>
|
329 |
+
|
330 |
+
|
331 |
+
<p align="center">
|
332 |
+
<a href="#-about">📌 About</a> •
|
333 |
+
<a href="#-checkpoints">🔍 Checkpoints</a> •
|
334 |
+
<a href="#-quick-start">🚀 Quick Start</a> •
|
335 |
+
<a href="#-training">🏋️♂️ Training</a> •
|
336 |
+
<a href="#-evaluation">📊 Evaluation</a> •
|
337 |
+
<a href="#-citation">📖 Citation</a>
|
338 |
+
</p>
|
339 |
+
|
340 |
+
---
|
341 |
+
|
342 |
+
## 📌 **About**
|
343 |
+
|
344 |
+
Misinformation is a growing problem, exacerbated by the increasing use of **Large Language Models (LLMs)** like GPT and Gemini. This issue is even more critical for **low-resource languages like Vietnamese**, where existing fact-checking methods struggle with **semantic ambiguity, homonyms, and complex linguistic structures**.
|
345 |
+
|
346 |
+
To address these challenges, we introduce **SemViQA**, a novel **Vietnamese fact-checking framework** integrating:
|
347 |
+
|
348 |
+
- **Semantic-based Evidence Retrieval (SER)**: Combines **TF-IDF** with a **Question Answering Token Classifier (QATC)** to enhance retrieval precision while reducing inference time.
|
349 |
+
- **Two-step Verdict Classification (TVC)**: Uses hierarchical classification optimized with **Cross-Entropy and Focal Loss**, improving claim verification across three categories:
|
350 |
+
- **Supported** ✅
|
351 |
+
- **Refuted** ❌
|
352 |
+
- **Not Enough Information (NEI)** 🤷♂️
|
353 |
+
|
354 |
+
### **🏆 Achievements**
|
355 |
+
- **1st place** in the **UIT Data Science Challenge** 🏅
|
356 |
+
- **State-of-the-art** performance on:
|
357 |
+
- **ISE-DSC01** → **78.97% strict accuracy**
|
358 |
+
- **ViWikiFC** → **80.82% strict accuracy**
|
359 |
+
- **SemViQA Faster**: **7x speed improvement** over the standard model 🚀
|
360 |
+
|
361 |
+
These results establish **SemViQA** as a **benchmark for Vietnamese fact verification**, advancing efforts to combat misinformation and ensure **information integrity**.
|
362 |
+
|
363 |
+
---
|
364 |
+
## 🔍 Checkpoints
|
365 |
+
We are making our **SemViQA** experiment checkpoints publicly available to support the **Vietnamese fact-checking research community**. By sharing these models, we aim to:
|
366 |
+
|
367 |
+
- **Facilitate reproducibility**: Allow researchers and developers to validate and build upon our results.
|
368 |
+
- **Save computational resources**: Enable fine-tuning or transfer learning on top of **pre-trained and fine-tuned models** instead of training from scratch.
|
369 |
+
- **Encourage further improvements**: Provide a strong baseline for future advancements in **Vietnamese misinformation detection**.
|
370 |
+
|
371 |
+
|
372 |
+
<table>
|
373 |
+
<tr>
|
374 |
+
<th>Method</th>
|
375 |
+
<th>Model</th>
|
376 |
+
<th>ViWikiFC</th>
|
377 |
+
<th>ISE-DSC01</th>
|
378 |
+
</tr>
|
379 |
+
<tr>
|
380 |
+
<td rowspan="3"><strong>TC</strong></td>
|
381 |
+
<td>InfoXLM<sub>large</sub></td>
|
382 |
+
<td><a href="https://huggingface.co/SemViQA/tc-infoxlm-viwikifc">Link</a></td>
|
383 |
+
<td><a href="https://huggingface.co/SemViQA/tc-infoxlm-isedsc01">Link</a></td>
|
384 |
+
</tr>
|
385 |
+
<tr>
|
386 |
+
<td>XLM-R<sub>large</sub></td>
|
387 |
+
<td><a href="https://huggingface.co/SemViQA/tc-xlmr-viwikifc">Link</a></td>
|
388 |
+
<td><a href="https://huggingface.co/SemViQA/tc-xlmr-isedsc01">Link</a></td>
|
389 |
+
</tr>
|
390 |
+
<tr>
|
391 |
+
<td>Ernie-M<sub>large</sub></td>
|
392 |
+
<td><a href="https://huggingface.co/SemViQA/tc-erniem-viwikifc">Link</a></td>
|
393 |
+
<td><a href="https://huggingface.co/SemViQA/tc-erniem-isedsc01">Link</a></td>
|
394 |
+
</tr>
|
395 |
+
<tr>
|
396 |
+
<td rowspan="3"><strong>BC</strong></td>
|
397 |
+
<td>InfoXLM<sub>large</sub></td>
|
398 |
+
<td><a href="https://huggingface.co/SemViQA/bc-infoxlm-viwikifc">Link</a></td>
|
399 |
+
<td><a href="https://huggingface.co/SemViQA/bc-infoxlm-isedsc01">Link</a></td>
|
400 |
+
</tr>
|
401 |
+
<tr>
|
402 |
+
<td>XLM-R<sub>large</sub></td>
|
403 |
+
<td><a href="https://huggingface.co/SemViQA/bc-xlmr-viwikifc">Link</a></td>
|
404 |
+
<td><a href="https://huggingface.co/SemViQA/bc-xlmr-isedsc01">Link</a></td>
|
405 |
+
</tr>
|
406 |
+
<tr>
|
407 |
+
<td>Ernie-M<sub>large</sub></td>
|
408 |
+
<td><a href="https://huggingface.co/SemViQA/bc-erniem-viwikifc">Link</a></td>
|
409 |
+
<td><a href="https://huggingface.co/SemViQA/bc-erniem-isedsc01">Link</a></td>
|
410 |
+
</tr>
|
411 |
+
<tr>
|
412 |
+
<td rowspan="2"><strong>QATC</strong></td>
|
413 |
+
<td>InfoXLM<sub>large</sub></td>
|
414 |
+
<td><a href="https://huggingface.co/SemViQA/qatc-infoxlm-viwikifc">Link</a></td>
|
415 |
+
<td><a href="https://huggingface.co/SemViQA/qatc-infoxlm-isedsc01">Link</a></td>
|
416 |
+
</tr>
|
417 |
+
<tr>
|
418 |
+
<td>ViMRC<sub>large</sub></td>
|
419 |
+
<td><a href="https://huggingface.co/SemViQA/qatc-vimrc-viwikifc">Link</a></td>
|
420 |
+
<td><a href="https://huggingface.co/SemViQA/qatc-vimrc-isedsc01">Link</a></td>
|
421 |
+
</tr>
|
422 |
+
<tr>
|
423 |
+
<td rowspan="2"><strong>QA origin</strong></td>
|
424 |
+
<td>InfoXLM<sub>large</sub></td>
|
425 |
+
<td><a href="https://huggingface.co/SemViQA/infoxlm-large-viwikifc">Link</a></td>
|
426 |
+
<td><a href="https://huggingface.co/SemViQA/infoxlm-large-isedsc01">Link</a></td>
|
427 |
+
</tr>
|
428 |
+
<tr>
|
429 |
+
<td>ViMRC<sub>large</sub></td>
|
430 |
+
<td><a href="https://huggingface.co/SemViQA/vi-mrc-large-viwikifc">Link</a></td>
|
431 |
+
<td><a href="https://huggingface.co/SemViQA/vi-mrc-large-isedsc01">Link</a></td>
|
432 |
+
</tr>
|
433 |
+
</table>
|
434 |
+
|
435 |
+
|
436 |
+
|
437 |
+
---
|
438 |
+
|
439 |
+
## 🚀 **Quick Start**
|
440 |
+
|
441 |
+
### 📥 **Installation**
|
442 |
+
|
443 |
+
#### **1️⃣ Clone this repository**
|
444 |
+
```bash
|
445 |
+
git clone https://github.com/DAVID-NGUYEN-S16/SemViQA.git
|
446 |
+
cd SemViQA
|
447 |
+
```
|
448 |
+
|
449 |
+
#### **2️⃣ Set up Python environment**
|
450 |
+
We recommend using **Python 3.11** in a virtual environment (`venv`) or **Anaconda**.
|
451 |
+
|
452 |
+
**Using `venv`:**
|
453 |
+
```bash
|
454 |
+
python -m venv semviqa_env
|
455 |
+
source semviqa_env/bin/activate # On MacOS/Linux
|
456 |
+
semviqa_env\Scripts\activate # On Windows
|
457 |
+
```
|
458 |
+
|
459 |
+
**Using `Anaconda`:**
|
460 |
+
```bash
|
461 |
+
conda create -n semviqa_env python=3.11 -y
|
462 |
+
conda activate semviqa_env
|
463 |
+
```
|
464 |
+
|
465 |
+
#### **3️⃣ Install dependencies**
|
466 |
+
```bash
|
467 |
+
pip install --upgrade pip
|
468 |
+
pip install transformers==4.42.3
|
469 |
+
pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
|
470 |
+
pip install -r requirements.txt
|
471 |
+
```
|
472 |
+
---
|
473 |
+
|
474 |
+
## 🏋️♂️ **Training**
|
475 |
+
|
476 |
+
Train different components of **SemViQA** using the provided scripts:
|
477 |
+
|
478 |
+
### **1️⃣ Three-Class Classification Training**
|
479 |
+
Train a three-class claim classification model using the following command:
|
480 |
+
```bash
|
481 |
+
bash scripts/tc.sh
|
482 |
+
```
|
483 |
+
If you want to fine-tune the model using pre-trained weights, you can initialize it as follows:
|
484 |
+
```python
|
485 |
+
# Install semviqa
|
486 |
+
!pip install semviqa
|
487 |
+
|
488 |
+
# Initalize a pipeline
|
489 |
+
from transformers import AutoTokenizer
|
490 |
+
from semviqa.tvc.model import ClaimModelForClassification
|
491 |
+
|
492 |
+
tokenizer = AutoTokenizer.from_pretrained("SemViQA/tc-infoxlm-viwikifc")
|
493 |
+
model = ClaimModelForClassification.from_pretrained("SemViQA/tc-infoxlm-viwikifc", num_labels=3)
|
494 |
+
```
|
495 |
+
|
496 |
+
### **2️⃣ Binary Classification Training**
|
497 |
+
Train a binary classification model using the command below:
|
498 |
+
```bash
|
499 |
+
bash scripts/bc.sh
|
500 |
+
```
|
501 |
+
To fine-tune the model with existing weights, use the following setup:
|
502 |
+
```python
|
503 |
+
# Install semviqa
|
504 |
+
!pip install semviqa
|
505 |
+
|
506 |
+
# Initalize a pipeline
|
507 |
+
from transformers import AutoTokenizer
|
508 |
+
from semviqa.tvc.model import ClaimModelForClassification
|
509 |
+
|
510 |
+
tokenizer = AutoTokenizer.from_pretrained("SemViQA/bc-infoxlm-viwikifc")
|
511 |
+
model = ClaimModelForClassification.from_pretrained("SemViQA/bc-infoxlm-viwikifc", num_labels=2)
|
512 |
+
```
|
513 |
+
|
514 |
+
### **3️⃣ QATC Model Training**
|
515 |
+
Train the Question Answering Token Classifier (QATC) model using the following command:
|
516 |
+
```bash
|
517 |
+
bash scripts/qatc.sh
|
518 |
+
```
|
519 |
+
|
520 |
+
To continue training from pre-trained weights, use this setup:
|
521 |
+
```python
|
522 |
+
# Install semviqa
|
523 |
+
!pip install semviqa
|
524 |
+
|
525 |
+
# Initalize a pipeline
|
526 |
+
from transformers import AutoTokenizer
|
527 |
+
from semviqa.ser.qatc_model import QATCForQuestionAnswering
|
528 |
+
|
529 |
+
tokenizer = AutoTokenizer.from_pretrained("SemViQA/qatc-infoxlm-viwikifc")
|
530 |
+
model = QATCForQuestionAnswering.from_pretrained("SemViQA/qatc-infoxlm-viwikifc")
|
531 |
+
```
|
532 |
+
|
533 |
+
---
|
534 |
+
|
535 |
+
## 📊 **Evaluation**
|
536 |
+
|
537 |
+
### **1️⃣ Semantic-based Evidence Retrieval**
|
538 |
+
This module extracts the most relevant evidence from a given context based on a claim. It leverages TF-IDF combined with the QATC model to ensure accurate retrieval.
|
539 |
+
```python
|
540 |
+
# Install semviqa package
|
541 |
+
!pip install semviqa
|
542 |
+
|
543 |
+
# Import the ser module
|
544 |
+
import torch
|
545 |
+
from transformers import AutoTokenizer
|
546 |
+
from semviqa.ser.qatc_model import QATCForQuestionAnswering
|
547 |
+
from semviqa.ser.ser_eval import extract_evidence_tfidf_qatc
|
548 |
+
|
549 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
550 |
+
|
551 |
+
tokenizer = AutoTokenizer.from_pretrained("SemViQA/qatc-infoxlm-viwikifc")
|
552 |
+
model = QATCForQuestionAnswering.from_pretrained("SemViQA/qatc-infoxlm-viwikifc")
|
553 |
+
|
554 |
+
claim = "Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất."
|
555 |
+
context = "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ự."
|
556 |
+
|
557 |
+
evidence = extract_evidence_tfidf_qatc(
|
558 |
+
claim, context, model, tokenizer, device, confidence_threshold=0.5, length_ratio_threshold=0.6
|
559 |
+
)
|
560 |
+
|
561 |
+
print(evidence)
|
562 |
+
# evidence: 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
|
563 |
+
```
|
564 |
+
|
565 |
+
|
566 |
+
### **2️⃣ Two-step Verdict Classification**
|
567 |
+
This module performs claim classification using a **two-step approach**:
|
568 |
+
1. **Three-class classification**: Determines if a claim is **Supported, Refuted, or Not Enough Information (NEI)**.
|
569 |
+
2. **Binary classification** (if necessary): Further verifies if the claim is **Supported** or **Refuted**.
|
570 |
+
```python
|
571 |
+
# Install semviqa package
|
572 |
+
!pip install semviqa
|
573 |
+
|
574 |
+
# Import the tvc module
|
575 |
+
import torch
|
576 |
+
from semviqa.tvc.tvc_eval import classify_claim
|
577 |
+
from semviqa.tvc.model import ClaimModelForClassification
|
578 |
+
|
579 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
580 |
+
|
581 |
+
tokenizer = AutoTokenizer.from_pretrained("SemViQA/tc-infoxlm-viwikifc")
|
582 |
+
model_tc = ClaimModelForClassification.from_pretrained("SemViQA/tc-infoxlm-viwikifc", num_labels=3).to(device)
|
583 |
+
model_bc = ClaimModelForClassification.from_pretrained("SemViQA/bc-infoxlm-viwikifc", num_labels=2).to(device)
|
584 |
+
|
585 |
+
claim = "Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất."
|
586 |
+
evidence = "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."
|
587 |
+
|
588 |
+
verdict = "NEI"
|
589 |
+
prob_tc, pred_tc = classify_claim(claim, evidence, model_tc, tokenizer, device)
|
590 |
+
|
591 |
+
if pred_tc != 0:
|
592 |
+
prob_bc, pred_bc = classify_claim(claim, evidence, model_bc, tokenizer, device)
|
593 |
+
verdict = "SUPPORTED" if pred_bc == 0 else "REFUTED" if prob_bc > prob_tc else ["NEI", "SUPPORTED", "REFUTED"][pred_tc]
|
594 |
+
|
595 |
+
print(verdict)
|
596 |
+
# Output: REFUTED
|
597 |
+
```
|
598 |
+
|
599 |
+
### **3️⃣ Full Pipeline Evaluation**
|
600 |
+
Use the trained models to **predict test data**:
|
601 |
+
```bash
|
602 |
+
bash scripts/pipeline.sh
|
603 |
+
```
|
604 |
+
|
605 |
+
Alternatively, you can use **SemViQA** programmatically:
|
606 |
+
|
607 |
+
```python
|
608 |
+
# Install semviqa package
|
609 |
+
!pip install semviqa
|
610 |
+
|
611 |
+
# Import the pipeline
|
612 |
+
from semviqa.pipeline import SemViQAPipeline
|
613 |
+
claim = "Chiến tranh với Campuchia đã kết thúc trước khi Việt Nam thống nhất."
|
614 |
+
context = "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ự."
|
615 |
+
|
616 |
+
semviqa = SemViQAPipeline(
|
617 |
+
model_evidence_QA="SemViQA/qatc-infoxlm-viwikifc",
|
618 |
+
model_bc="SemViQA/bc-infoxlm-viwikifc",
|
619 |
+
model_tc="SemViQA/tc-infoxlm-viwikifc",
|
620 |
+
thres_evidence=0.5,
|
621 |
+
length_ratio_threshold=0.5,
|
622 |
+
is_qatc_faster=False
|
623 |
+
)
|
624 |
+
|
625 |
+
result = semviqa.predict(claim, context)
|
626 |
+
print(result)
|
627 |
+
# Output: {'verdict': 'REFUTED', 'evidence': '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'}
|
628 |
+
|
629 |
+
# Extract only evidence
|
630 |
+
evidence_only = semviqa.predict(claim, context, return_evidence_only=True)
|
631 |
+
print(evidence_only)
|
632 |
+
# Output: {'evidence': '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'}
|
633 |
+
```
|
634 |
+
|
635 |
+
## **Acknowledgment**
|
636 |
+
Our development is based on our previous works:
|
637 |
+
- [Check-Fact-Question-Answering-System](https://github.com/DAVID-NGUYEN-S16/Check-Fact-Question-Answering-System)
|
638 |
+
- [Extract-Evidence-Question-Answering](https://github.com/DAVID-NGUYEN-S16/Extract-evidence-question-answering)
|
639 |
+
|
640 |
+
**SemViQA** is the final version we have developed for verifying fact-checking in Vietnamese, achieving state-of-the-art (SOTA) performance compared to any other system for Vietnamese.
|
641 |
+
|
642 |
+
## 📖 **Citation**
|
643 |
+
|
644 |
+
If you use **SemViQA** in your research, please cite our work:
|
645 |
+
|
646 |
+
```bibtex
|
647 |
+
@misc{nguyen2025semviqasemanticquestionanswering,
|
648 |
+
title={SemViQA: A Semantic Question Answering System for Vietnamese Information Fact-Checking},
|
649 |
+
author={Nam V. Nguyen and Dien X. Tran and Thanh T. Tran and Anh T. Hoang and Tai V. Duong and Di T. Le and Phuc-Lu Le},
|
650 |
+
year={2025},
|
651 |
+
eprint={2503.00955},
|
652 |
+
archivePrefix={arXiv},
|
653 |
+
primaryClass={cs.CL},
|
654 |
+
url={https://arxiv.org/abs/2503.00955},
|
655 |
+
}
|
656 |
+
```
|
657 |
+
|
658 |
+
'''
|
659 |
+
|
660 |
+
st.markdown(about_content, unsafe_allow_html=True)
|
661 |
+
|