语言人工智能指南

自然语言推理和蕴涵

Natural language inference (NLI), also called recognizing textual entailment, is the task of deciding whether one sentence, the premise, makes another, the hypothesis, true (entailment), false (contradiction) or neither (neutral).

听听这个指南AI叙述 · ~7 min

在本页阅读需 8 分钟
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. Check a summary sentence against its source with NLI
  5. 现实世界的实施
  6. 自然语言推理和蕴涵的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

It matters because it is a standard test of language understanding and a working tool for zero-shot classification and for checking whether generated text is supported by its source.

主要要点

  1. Natural language inference labels a premise and hypothesis pair as entailment, contradiction or neutral, based on what a reasonable reader would infer.
  2. SNLI (2015) has 570,000 labeled pairs and MultiNLI (2017) has 433,000 pairs drawn from ten genres of English.
  3. A classifier that sees only the hypothesis gets about 67% of SNLI right, showing that crowd-written data contains exploitable artifacts.
  4. Any trained NLI model can act as a zero-shot classifier by turning each candidate label into a hypothesis and scoring entailment.
  5. NLI-based checkers flag unsupported summary sentences, and SummaC reached 74.4% balanced accuracy by aggregating sentence-level scores across a document.

深入探讨

Natural language inference asks a question people answer constantly without noticing: if this sentence is true, what follows? A system receives two pieces of text. The premise is taken as true, for example "A man is playing a guitar on stage." The hypothesis is a claim to evaluate, such as "A man is performing music." The system outputs one of three labels. Entailment means a typical reader would conclude the hypothesis is true given the premise. Contradiction means the hypothesis must be false, as with "The man is asleep in bed." Neutral means the premise does not settle it, as with "The man is a famous musician." The judgment is about what a reasonable person would infer, not strict formal logic.

Modern NLI systems are text classifiers built on pretrained Transformer language models. The premise and hypothesis are joined into one input with a separator token between them, so every word of the hypothesis can attend to every word of the premise. A small classification layer on top of the model's output produces three scores, which a softmax function turns into probabilities for entailment, neutral and contradiction. The model is fine-tuned, meaning further trained, on hundreds of thousands of labeled pairs until its predictions match the human labels.

The task is older than neural networks. Early Recognizing Textual Entailment (RTE) challenges used small test sets, which limited learning-based approaches. That changed in August 2015, when Samuel Bowman and colleagues released the Stanford Natural Language Inference corpus (SNLI) with 570,000 human-labeled sentence pairs, about two orders of magnitude larger than earlier resources of its kind. SNLI premises are image captions, and crowd workers wrote a hypothesis for each label. In 2017 Adina Williams, Nikita Nangia and Bowman released MultiNLI with 433,000 examples from ten genres of written and spoken English, published at NAACL 2018. MultiNLI became a standard training set for general-purpose NLI models.

High scores soon turned out to hide shortcuts. In 2018 Suchin Gururangan and colleagues showed that a classifier that never sees the premise, only the hypothesis, labels about 67% of SNLI and 53% of MultiNLI correctly, against a chance rate of about 33%. Crowd workers left annotation artifacts: negation words, for example, correlate strongly with contradiction. In 2019 Tom McCoy, Ellie Pavlick and Tal Linzen built HANS, a test set where three tempting heuristics fail: assuming entailment when the hypothesis reuses the premise's words, when it is a contiguous piece of the premise, or when it is a complete subtree of the premise's parse. Models trained on MultiNLI, including BERT, did very poorly on it. Adversarial NLI (ANLI), released by Yixin Nie and colleagues in 2019, answered by having people write examples specifically to fool strong models in a human-and-model-in-the-loop process, producing a harder test set.

NLI is now used more as a tool than a leaderboard. Wenpeng Yin, Jamaal Hay and Dan Roth showed in 2019 that a trained NLI model can act as a zero-shot classifier: treat the text as the premise, write each candidate label as a hypothesis, and pick the label with the highest entailment score. The bart-large-mnli model on Hugging Face packages exactly this method. A second use is checking generated text. A summary sentence that is entailed by the source is supported; one that is contradicted or neutral may be a hallucination, meaning a statement the source does not back.

Compared with alternatives, NLI-based checks are cheap and transparent. A fine-tuned NLI model is far smaller than a chatbot-scale language model, runs quickly on modest hardware and returns probabilities that can be thresholded and audited. Question-answering-based metrics, which generate questions from a summary and check whether the source answers them the same way, are slower but catch different errors; the TRUE study found the two families complementary. Asking a large language model to judge consistency is flexible but costlier, and its verdicts can vary with the prompt.

The limitations are real. NLI datasets are built at sentence level, while documents spread facts across many sentences; Laban and colleagues identified this granularity mismatch as the reason early NLI-based summary checkers performed poorly, and their SummaC method, which aggregates sentence-pair scores, reached 74.4% balanced accuracy on its six-dataset benchmark. Labels also depend on background assumptions about what a reasonable reader infers, so annotators sometimes disagree. Shortcut learning can reappear in any new domain, and a model trained on captions and fiction may misjudge legal or medical text. A neutral label means only that the premise does not settle the claim; it does not mean the claim is false.

In practice, building with NLI requires a pretrained model already fine-tuned on MultiNLI or a combination of SNLI, MultiNLI and ANLI, which are freely available, plus a validation set from the target domain to set decision thresholds. Fine-tuning a new model takes a single modern GPU and the public datasets. The main ongoing cost is evaluation: checking examples where the model's labels and human judgment differ, and watching for the overlap and negation shortcuts the research literature has documented.

04工作示例

Check a summary sentence against its source with NLI

  1. Load a public NLI model fine-tuned on MultiNLI, such as facebook/bart-large-mnli, with the Hugging Face Transformers library.

  2. Take a source sentence as the premise: "The library will close at 6 p.m. on Friday for staff training."

  3. Score three hypotheses: "The library closes early on Friday.", "The library is open late on Friday." and "The training is mandatory for all staff."

  4. Read the three probabilities for each pair and record the highest label.

  5. Expect entailment for the first, contradiction for the second and neutral for the third, since the premise does not say whether training is mandatory.

  6. Repeat with the premise reworded to share few words with the first hypothesis to see whether the model relies on word overlap.

它显示了什么

A small table of labels and probabilities showing which claims the source supports, contradicts or leaves open. Check it by labeling the same pairs yourself; disagreements, especially on the reworded premise, show where the model may be using shortcuts rather than meaning.

现实世界的实施

The facebook/bart-large-mnli model on Hugging Face classifies text into labels it was never trained on by turning each label into a hypothesis such as "This example is travel." and scoring entailment.

SummaC, published in 2021, splits a document and its summary into sentences and runs NLI on every pair to flag summaries that state things the source does not support.

The 2022 TRUE study found that large-scale NLI models performed strongly at judging factual consistency across 11 manually annotated datasets drawn from diverse generation tasks.

Researchers use the HANS test set to check whether a model trained on MultiNLI really reasons or just assumes that high word overlap means entailment.

Benchmarks such as SNLI, MultiNLI and Adversarial NLI are used to compare language models, since each item has a clear three-way label that makes scoring simple.

自然语言推理和蕴涵的未来

NLI research since 2019 has shifted from beating benchmarks toward measuring robustness and supporting other tasks. Adversarial collection, as in ANLI, showed that test sets written to fool current models stay hard longer than static ones. In evaluation, NLI models remain a common, inexpensive way to score factual consistency, and the 2022 TRUE study recommended NLI-based and question-answering-based metrics as starting points while noting that they catch different errors. Open problems include document-level inference, where the evidence for a claim is spread across many sentences; graded or disputed labels, where reasonable annotators disagree; and domain shift into specialized fields such as law or medicine, where training data is scarce. Large language models can perform NLI when prompted, which raises a practical question that research has not settled: when a small fine-tuned NLI classifier is preferable for its speed, cost and calibrated probabilities, and when a general model's broader knowledge justifies its cost. For hallucination detection, the consistent finding is that NLI provides useful evidence for human review rather than a final verdict on truth.

付诸实践

为什么这很重要

  • 速度与规模. 语言工作流程可以在不牺牲一致性的情况下更快地移动。
  • 交通与覆盖范围. 它扩展了跨语言和沟通方式的访问。
  • 更清晰的判决. 团队可以花更多时间进行判断,而自动化则可以处理重复。

留意

  • 幻觉的事实可以悄悄地进入报告、支持流程或研究成果。
  • 及时的敏感性可能会在类似的请求中产生不一致的结果。
  • 如果访问控制薄弱,敏感文本数据可能会暴露。

后续步骤

  1. 在推出之前定义输出格式、语气和质量标准。
  2. 当准确性很重要时,请使用可信来源进行地面响应。
  3. 为高风险输出保留人工审查检查点。
  4. 跟踪故障模式并定期重新训练提示或工作流程。

资料来源与延伸阅读

  1. arXiv (EMNLP 2015)A large annotated corpus for learning natural language inference
  2. arXiv (NAACL 2018)A Broad-Coverage Challenge Corpus for Sentence Understanding through Inference
  3. arXiv (NAACL 2018)Annotation Artifacts in Natural Language Inference Data
  4. arXiv (ACL 2019)Right for the Wrong Reasons: Diagnosing Syntactic Heuristics in Natural Language Inference
  5. arXiv (ACL 2020)Adversarial NLI: A New Benchmark for Natural Language Understanding
  6. arXiv (EMNLP 2019)Benchmarking Zero-shot Text Classification: Datasets, Evaluation and Entailment Approach
  7. arXiv (TACL)SummaC: Re-Visiting NLI-based Models for Inconsistency Detection in Summarization
  8. arXiv (NAACL 2022)TRUE: Re-evaluating Factual Consistency Evaluation

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

Take the Natural Language Inference and Entailment quiz

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

什么是自然语言推理和蕴涵?

Natural language inference (NLI), also called recognizing textual entailment, is the task of deciding whether one sentence, the premise, makes another, the hypothesis, true (entailment), false (contradiction) or neither (neutral). It matters because it is a standard test of language understanding and a working tool for zero-shot classification and for checking whether generated text is supported by its source.

自然语言推理的三个标准标签是什么?

NLI 将前提-假设对分类为蕴涵、矛盾或中性。

在 NLI 中,“蕴含”是什么意思?

蕴涵意味着前提保证了假设的真实性。

给定前提“一个人在舞台上弹吉他”,哪个假设是矛盾的?

如果一个人在舞台上弹吉他,舞台不可能是空的,因此该假设与前提相矛盾。

What is an annotation artifact in an NLI dataset?

NLI datasets can contain patterns such as certain words being associated with a label, allowing shortcut prediction that may fail out of domain.

哪些数据集被广泛用于训练和评估 NLI?

SNLI 和 MultiNLI 是专门为自然语言推理而构建的大型人工标记语料库。