Upload README.md
Browse files
README.md
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Fact Checking rocks!
|
3 |
+
emoji: ๐ธ
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.10.0
|
8 |
+
app_file: Rock_fact_checker.py
|
9 |
+
pinned: true
|
10 |
+
models: [sentence-transformers/msmarco-distilbert-base-tas-b, microsoft/deberta-v2-xlarge-mnli]
|
11 |
+
license: apache-2.0
|
12 |
+
---
|
13 |
+
|
14 |
+
# Fact Checking ๐ธ Rocks! [![Generic badge](https://img.shields.io/badge/๐ค-Open%20in%20Spaces-blue.svg)](https://huggingface.co/spaces/anakin87/fact-checking-rocks) [![Generic badge](https://img.shields.io/github/stars/anakin87/fact-checking-rocks?label=Github&style=social)](https://github.com/anakin87/fact-checking-rocks)
|
15 |
+
|
16 |
+
## *Fact checking baseline combining dense retrieval and textual entailment*
|
17 |
+
|
18 |
+
- [Fact Checking ๐ธ Rocks! ย ](#fact-checking--rocks---)
|
19 |
+
- [*Fact checking baseline combining dense retrieval and textual entailment*](#fact-checking-baseline-combining-dense-retrieval-and-textual-entailment)
|
20 |
+
- [Idea](#idea)
|
21 |
+
- [System description](#system-description)
|
22 |
+
- [Indexing pipeline](#indexing-pipeline)
|
23 |
+
- [Search pipeline](#search-pipeline)
|
24 |
+
- [Limits and possible improvements](#limits-and-possible-improvements)
|
25 |
+
- [Repository structure](#repository-structure)
|
26 |
+
- [Installation](#installation)
|
27 |
+
|
28 |
+
### Idea
|
29 |
+
๐ก This project aims to show that a *naive and simple baseline* for fact checking can be built by combining dense retrieval and a textual entailment task.
|
30 |
+
In a nutshell, the flow is as follows:
|
31 |
+
* the user enters a factual statement
|
32 |
+
* the relevant passages are retrieved from the knowledge base using dense retrieval
|
33 |
+
* the system computes the text entailment between each relevant passage and the statement, using a Natural Language Inference model
|
34 |
+
* the entailment scores are aggregated to produce a summary score.
|
35 |
+
|
36 |
+
### System description
|
37 |
+
๐ช This project is strongly based on [๐ Haystack](https://github.com/deepset-ai/haystack), an open source NLP framework to realize search system. The main components of our system are an indexing pipeline and a search pipeline.
|
38 |
+
|
39 |
+
|
40 |
+
#### Indexing pipeline
|
41 |
+
* [Crawling](https://github.com/anakin87/fact-checking-rocks/blob/321ba7893bbe79582f8c052493acfda497c5b785/notebooks/get_wikipedia_data.ipynb): Crawl data from Wikipedia, starting from the page [List of mainstream rock performers](https://en.wikipedia.org/wiki/List_of_mainstream_rock_performers) and using the [python wrapper](https://github.com/goldsmith/Wikipedia)
|
42 |
+
* [Indexing](https://github.com/anakin87/fact-checking-rocks/blob/321ba7893bbe79582f8c052493acfda497c5b785/notebooks/indexing.ipynb)
|
43 |
+
* preprocess the downloaded documents into chunks consisting of 2 sentences
|
44 |
+
* chunks with less than 10 words are discarded, because not very informative
|
45 |
+
* instantiate a [FAISS](https://github.com/facebookresearch/faiss) Document store and store the passages on it
|
46 |
+
* create embeddings for the passages, using a Sentence Transformer model and save them in FAISS. The retrieval task will involve [*asymmetric semantic search*](https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search) (statements to be verified are usually shorter than inherent passages), therefore I choose the model `msmarco-distilbert-base-tas-b`
|
47 |
+
* save FAISS index.
|
48 |
+
|
49 |
+
#### Search pipeline
|
50 |
+
|
51 |
+
* the user enters a factual statement
|
52 |
+
* compute the embedding of the user statement using the same Sentence Transformer used for indexing (`msmarco-distilbert-base-tas-b`)
|
53 |
+
* retrieve the K most relevant text passages stored in FAISS (along with their relevance scores)
|
54 |
+
* **text entailment task**: compute the text entailment between each text passage (premise) and the user statement (hypotesis), using a Natural Language Inference model (`microsoft/deberta-v2-xlarge-mnli`). For every text passage, we have 3 scores (summing to 1): entailment, contradiction and neutral. *(For this task, I developed a custom Haystack node: `EntailmentChecker`)*
|
55 |
+
* aggregate the text entailment scores: compute the weighted average of them, where the weight is the relevance score. **Now it is possible to tell if the knowledge base confirms, is neutral or disproves the user statement.**
|
56 |
+
* *empirical consideration: if in the first N passages (N<K), there is strong evidence of entailment/contradiction (partial aggregate scores > 0.5), it is better not to consider (K-N) less relevant documents.*
|
57 |
+
|
58 |
+
### Limits and possible improvements
|
59 |
+
โจ As mentioned, the current approach to fact checking is simple and naive. Some **structural limits of this approach**:
|
60 |
+
* there is **no statement detection**. In fact, the statement to be verified is chosen by the user. In real-world applications, this step is often necessary.
|
61 |
+
* **Wikipedia is taken as a source of truth**. Unfortunately, Wikipedia does not contain universal knowledge and there is no real guarantee that it is a source of truth. There are certainly very interesting approaches that view a snapshot of the entire web as an uncurated source of knowledge (see [Facebook Research SPHERE](https://arxiv.org/abs/2112.09924)).
|
62 |
+
* Several papers and even our experiments show a general effectiveness of **dense retrieval** in retrieving textual passages for evaluating the user statement. However, there may be cases in which the most useful textual passages for fact checking do not emerge from the simple semantic similarity with the statement to be verified.
|
63 |
+
* **no organic evaluation** was performed, but only manual experiments.
|
64 |
+
|
65 |
+
While keeping this simple approach, some **improvements** could be made:
|
66 |
+
* For reasons of simplicity and infrastructural limitations, the retrieval uses only a very small portion of the Wikipedia data (artists pages from the [List of mainstream rock performers](https://en.wikipedia.org/wiki/List_of_mainstream_rock_performers)). With these few data available, in many cases the knowledge base remains neutral even with respect to statements about rock albums/songs. Certainly, fact checking **quality could improve by expanding the knowledge base** and possibly extending it to the entire Wikipedia.
|
67 |
+
* Both the retriever model and the Natural Language Inference model are general purpose models and have not been fine-tuned for our domain. Undoubtedly they can **show better performance if fine-tuned in the rock music domain**. Particularly, the retriever model might be adapted with low effort, using [Generative Pseudo Labelling](https://haystack.deepset.ai/guides/gpl).
|
68 |
+
|
69 |
+
### Repository structure
|
70 |
+
* [Rock_fact_checker.py](Rock_fact_checker.py) and [pages folder](./pages/): multi-page Streamlit web app
|
71 |
+
* [app_utils folder](./app_utils/): python modules used in the web app
|
72 |
+
* [notebooks folder](./notebooks/): Jupyter/Colab notebooks to get Wikipedia data and index the text passages (using Haystack)
|
73 |
+
* [data folder](./data/): all necessary data, including original Wikipedia data, FAISS Index and prepared random statements
|
74 |
+
|
75 |
+
### Installation
|
76 |
+
๐ป To install this project locally, follow these steps:
|
77 |
+
* `git clone https://github.com/anakin87/fact-checking-rocks`
|
78 |
+
* `cd fact-checking-rocks`
|
79 |
+
* `pip install -r requirements.txt`
|
80 |
+
|
81 |
+
To run the web app, simply type: `streamlit run Rock_fact_checker.py`
|