Skip to main content

Check a claim consistency against the provided evidence

Project description

Fact checking

This generative model - trained on FEVER - aims to predict whether a claim is consistent with the provided evidence.

Installation and simple usage

One quick way to install it is to type

pip install fact_checking

and then use the following code:

from transformers import (
    GPT2LMHeadModel,
    GPT2Tokenizer,
)

from fact_checking import FactChecker

_evidence = """
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.
"""

_claim = 'Justine Bateman is a poet.'

tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
fact_checker = FactChecker(fact_checking_model, tokenizer)
is_claim_true = fact_checker.validate(_evidence, _claim)

print(is_claim_true)

which gives the output

True

Probabilistic output with replicas

The output can include a probabilistic component, obtained by iterating a number of times the output generation. The system generates an ensemble of answers and groups them by Yes or No.

For example, one can ask

from transformers import (
    GPT2LMHeadModel,
    GPT2Tokenizer,
)

from fact_checking import FactChecker

_evidence = """
Jane writes code for Huggingface.
"""

_claim = 'Jane is an engineer.'


tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
fact_checking_model = GPT2LMHeadModel.from_pretrained('fractalego/fact-checking')
fact_checker = FactChecker(fact_checking_model, tokenizer)
is_claim_true = fact_checker.validate_with_replicas(_evidence, _claim)

print(is_claim_true)

with output

{'Y': 0.95, 'N': 0.05}

Score on FEVER

The score on the FEVER dev dataset is as follows

precision recall F1
0.94 0.98 0.96

These results should be taken with many grains of salt. This is still a work in progress, and there might be leakage coming from the underlining GPT2 model unnaturally raising the scores.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fact_checking-0.0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

fact_checking-0.0.2-py2-none-any.whl (5.2 kB view details)

Uploaded Python 2

File details

Details for the file fact_checking-0.0.2.tar.gz.

File metadata

  • Download URL: fact_checking-0.0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for fact_checking-0.0.2.tar.gz
Algorithm Hash digest
SHA256 06dc63bb23e8b2e9a9b19fd80cdf04397cccca65758107a96eef6f873df54e94
MD5 4808f68b852a08d6046ce157d445de8a
BLAKE2b-256 d57fe788b08a3807036ad994c18785fcad5cc56b977cf120079f1e72db4b1d88

See more details on using hashes here.

File details

Details for the file fact_checking-0.0.2-py2-none-any.whl.

File metadata

  • Download URL: fact_checking-0.0.2-py2-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for fact_checking-0.0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 bcf4238278c852a7d46bb9d0a9398d569f959e8899df1adfe06e04a325e9c6dd
MD5 9b64c2751ddbec523fc5ad2fe00d9ef9
BLAKE2b-256 a8e972f1384adc795a862f28ff93a11c22ac6f2d5dd2989c38a81b8699c5717e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page