Haystack Entailment Checker
Custom node for the Haystack NLP framework. Using a Natural Language Inference model, it checks whether a lists of Documents/passages entails, contradicts or is neutral with respect to a given statement.
Live Demo: Fact Checking 🎸 Rocks!
How it works
- The node takes a list of Documents (commonly returned by a Retriever) and a statement as input.
- Using a Natural Language Inference model, the text entailment between each text passage/Document (premise) and the statement (hypothesis) is computed. For every text passage, we get 3 scores (summing to 1): entailment, contradiction and neutral.
- The text entailment scores are aggregated using a weighted average. The weight is the relevance score of each passage returned by the Retriever, if availaible. It expresses the similarity between the text passage and the statement. Now we have a summary score, so it is possible to tell if the passages confirm, are neutral or disprove the user statement.
- empirical consideration: if in the first N passages (N<K), there is strong evidence of entailment/contradiction (partial aggregate scores > threshold), it is better not to consider (K-N) less relevant documents.
Installation
pip install haystack-entailment-checker
Usage
Basic example
from haystack import Document
from haystack_entailment_checker import EntailmentChecker
ec = EntailmentChecker(
model_name_or_path = "microsoft/deberta-v2-xlarge-mnli",
use_gpu = False,
entailment_contradiction_threshold = 0.5)
doc = Document("My cat is lazy")
print(ec.run("My cat is very active", [doc]))
# ({'documents': [...],
# 'aggregate_entailment_info': {'contradiction': 1.0, 'neutral': 0.0, 'entailment': 0.0}}, ...)
Fact-checking pipeline (Retriever + EntailmentChecker)
from haystack import Document, Pipeline
from haystack.nodes import BM25Retriever
from haystack.document_stores import InMemoryDocumentStore
from haystack_entailment_checker import EntailmentChecker
# INDEXING
# the knowledge base can consist of many documents
docs = [...]
ds = InMemoryDocumentStore(use_bm25=True)
ds.write_documents(docs)
# QUERYING
retriever = BM25Retriever(document_store=ds)
ec = EntailmentChecker()
pipe = Pipeline()
pipe.add_node(component=retriever, name="Retriever", inputs=["Query"])
pipe.add_node(component=ec, name="EntailmentChecker", inputs=["Retriever"])
pipe.run(query="YOUR STATEMENT TO CHECK")
Acknowledgements 🙏
Special thanks goes to @davidberenstein1957, who contributed to the original implementation of this node, in the Fact Checking 🎸 Rocks! project.
Metadata
Release files for haystack-entailment-checker 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| haystack_entailment_checker-0.0.4.tar.gz | 213.3 kB | Without provenance | Details for haystack_entailment_checker-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| haystack_entailment_checker-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for haystack_entailment_checker-0.0.4-py3-none-any.whl |
Total release size: 218.2 kB
Release files / haystack_entailment_checker-0.0.4.tar.gz
| Download URL | haystack_entailment_checker-0.0.4.tar.gz |
|---|---|
| Size | 213.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
beef71150b62a3aa870a96829ad340808de98821db79d4ce4dc965f504a6ee9c
|
|
BLAKE2b-256 checksum How to use checksums |
7096a41b6157ca0147cdff01c5e9b5209cb928fa385dc1216b8ccd8054e98d47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|
Release files / haystack_entailment_checker-0.0.4-py3-none-any.whl
| Download URL | haystack_entailment_checker-0.0.4-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da9ff320dac544ca68d43bbcbe8d2b2904a208e8263a34136531eb5b85ccb9c5
|
|
BLAKE2b-256 checksum How to use checksums |
fed3567ce33b610d778d9d1af62fbd6438823b5a7bc3f2963111e8eaf66daaa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.24.1
|
Security for haystack-entailment-checker 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.