fractalego
commited on
Commit
•
01cb32d
1
Parent(s):
ef06b45
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Fact checking
|
2 |
+
|
3 |
+
This generative model - trained on FEVER - aims to predict whether a claim is consistent with the provided evidence.
|
4 |
+
|
5 |
+
|
6 |
+
### Installation and simple usage
|
7 |
+
One quick way to install it is to type
|
8 |
+
|
9 |
+
```bash
|
10 |
+
pip install fact_checking
|
11 |
+
```
|
12 |
+
|
13 |
+
and then use the following code:
|
14 |
+
|
15 |
+
```python
|
16 |
+
from transformers import (
|
17 |
+
GPT2LMHeadModel,
|
18 |
+
GPT2Tokenizer,
|
19 |
+
)
|
20 |
+
|
21 |
+
from fact_checking import FactChecker
|
22 |
+
|
23 |
+
_evidence = """
|
24 |
+
Justine Tanya Bateman (born February 19, 1966) is an American writer, producer, and actress . She is best known for her regular role as Mallory Keaton on the sitcom Family Ties (1982 -- 1989). Until recently, Bateman ran a production and consulting company, SECTION 5 . In the fall of 2012, she started studying computer science at UCLA.
|
25 |
+
"""
|
26 |
+
|
27 |
+
_claim = 'Justine Bateman is a poet.'
|
28 |
+
|
29 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
30 |
+
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
|
31 |
+
fact_checker = FactChecker(fact_checking_model, tokenizer)
|
32 |
+
is_claim_true = fact_checker.validate(_evidence, _claim)
|
33 |
+
|
34 |
+
print(is_claim_true)
|
35 |
+
```
|
36 |
+
|
37 |
+
which gives the output
|
38 |
+
|
39 |
+
```bash
|
40 |
+
True
|
41 |
+
```
|
42 |
+
|
43 |
+
### Probabilistic output with replicas
|
44 |
+
The output can include a probabilistic component, obtained by iterating a number of times the output generation.
|
45 |
+
The system generates an ensemble of answers and groups them by Yes or No.
|
46 |
+
|
47 |
+
For example, one can ask
|
48 |
+
```python
|
49 |
+
from transformers import (
|
50 |
+
GPT2LMHeadModel,
|
51 |
+
GPT2Tokenizer,
|
52 |
+
)
|
53 |
+
|
54 |
+
from fact_checking import FactChecker
|
55 |
+
|
56 |
+
_evidence = """
|
57 |
+
Jane writes code for Huggingface.
|
58 |
+
"""
|
59 |
+
|
60 |
+
_claim = 'Jane is an engineer.'
|
61 |
+
|
62 |
+
|
63 |
+
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
|
64 |
+
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
|
65 |
+
fact_checker = FactChecker(fact_checking_model, tokenizer)
|
66 |
+
is_claim_true = fact_checker.validate_with_replicas(_evidence, _claim)
|
67 |
+
|
68 |
+
print(is_claim_true)
|
69 |
+
|
70 |
+
```
|
71 |
+
|
72 |
+
with output
|
73 |
+
```bash
|
74 |
+
{'Y': 0.95, 'N': 0.05}
|
75 |
+
```
|
76 |
+
|
77 |
+
|
78 |
+
### Score on FEVER
|
79 |
+
|
80 |
+
The score on the FEVER dev dataset is as follows
|
81 |
+
|
82 |
+
| precision | recall | F1|
|
83 |
+
| --- | --- | --- |
|
84 |
+
|0.94|0.98|0.96|
|
85 |
+
|
86 |
+
These results should be taken with many grains of salt. This is still a work in progress,
|
87 |
+
and there might be leakage coming from the underlining GPT2 model unnaturally raising the scores.
|
88 |
+
|
89 |
+
|