🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Natural Language Explanation: Generating Explanations

Natural Language ProcessingNatural Language Explanation: Generating ExplanationsđŸŸĸ Free Lesson

Natural Language Explanation: Generating Explanations

Module: Natural Language Processing | Difficulty: Advanced

What You'll Learn

  • 1Distinguish plausibility of an explanation from faithfulness to the model
  • 2Compute comprehensiveness, sufficiency, and AOPC on a rationale benchmark
  • 3Build an occlusion rationale extractor over a trained text classifier
  • 4Use ERASER and CoS-E to evaluate free-form and extractive explanations

Natural language explanation asks a system to state, in words, why it produced an output, and to point at the evidence it used. The field splits into extractive rationales, short spans taken from the input, and free-form explanations, generated sentences that may add world knowledge.

Plausibility Versus Faithfulness

These two words are not synonyms. Plausibility asks whether humans judge the explanation convincing; faithfulness asks whether the model actually relied on that evidence. A rationale can be highly plausible and unfaithful, which is the core warning from the attention debate: attention weights are not automatically explanations, as Jain and Wallace (2019) showed by constructing adversarial attention distributions that flip predictions, and Wiegreffe and Pinter (2019) answered by showing attention can still be a useful signal under weaker criteria.

ERASER datasetTask typeExplanation form
boolQ, multiRCbinary reading comprehensiontoken spans in the passage
FEVER, XNLIfact verification and inferenceevidence sentences
IMDBsentimentopinion spans
RACE, MUTUAL, SQuADexams, dialogue, QAanswer supporting spans

CoS-E (Rajani et al., 2019) is the free-form counterpart for commonsense questions: 8,733 training, 1,092 validation, and 1,092 test items, each pairing a question with a human written explanation.

Perturbation Metrics

Let be the model probability of the predicted label on input , and let be with the rationale tokens deleted. Comprehensiveness asks how much the prediction depends on the rationale:

Sufficiency asks how well the rationale works on its own:

A good rationale has high comprehensiveness, deleting it hurts, and low sufficiency gap, keeping it alone still supports the label. Summing the drop over successive removals gives a curve rather than a single point:

where are the top rationale tokens ranked by contribution. Soft rationale models produce a distribution over tokens instead of a fixed span:

Here is the contextual state of token and a query vector for the label; the hard span is obtained by thresholding , and the same perturbation metrics then evaluate it.

Worked Code

python
import math, re

TRAIN = [
    ("great plot and wonderful acting", 1),
    ("awful script and boring scenes", 0),
    ("the cast was brilliant and fun", 1),
    ("dull story with terrible editing", 0),
    ("smart writing and lovely music", 1),
    ("painfully slow and unfunny", 0),
]

def tokenize(text):
    return re.findall(r"[a-z']+", text.lower())

def train_lr(train, steps=2000, lr=0.3):
    vocab = sorted({w for t, _ in train for w in tokenize(t)})
    idx = {w: i for i, w in enumerate(vocab)}
    w = [0.0] * len(vocab)
    b = 0.0
    for _ in range(steps):
        for text, label in train:
            xs = tokenize(text)
            z = sum(w[idx[t]] for t in xs) + b
            p = 1 / (1 + math.exp(-z))
            err = p - label
            for t in xs:
                w[idx[t]] -= lr * err
            b -= lr * err
    return idx, w, b

idx, w, b = train_lr(TRAIN)

def prob(text):
    xs = tokenize(text)
    z = sum(w[idx[t]] for t in xs if t in idx) + b
    return 1 / (1 + math.exp(-z))

rationale = "great plot"
text = rationale + " and dull scenes"
full = prob(text)
comp = full - prob("dull scenes")      # delete the rationale
suff = full - prob(rationale)          # keep only the rationale
print(f"full={full:.3f} comprehensiveness={comp:.3f} sufficiency={suff:.3f}")

The second program turns a model into a rationale extractor by occluding one token at a time, the standard left-to-right baseline in ERASER, and scores the recovered span against gold.

python
import math, re
from collections import Counter

TRAIN = [
    ("great plot and wonderful acting", 1),
    ("awful script and boring scenes", 0),
    ("the cast was brilliant and fun", 1),
    ("dull story with terrible editing", 0),
    ("smart writing and lovely music", 1),
    ("painfully slow and unfunny", 0),
]

def tokenize(text):
    return re.findall(r"[a-z']+", text.lower())

counts = {0: Counter(), 1: Counter()}
totals = {0: 0, 1: 0}
for text, label in TRAIN:
    counts[label].update(tokenize(text))
    totals[label] += len(tokenize(text))
vocab = set(counts[0]) | set(counts[1])

def prob(text):
    z = 0.0
    for word in tokenize(text):
        p1 = (counts[1][word] + 1) / (totals[1] + len(vocab))
        p0 = (counts[0][word] + 1) / (totals[0] + len(vocab))
        z += math.log(p1 / p0)
    return 1 / (1 + math.exp(-z))

def occlusion_rationale(text, k=2):
    words = tokenize(text)
    base = prob(text)
    ranked = sorted(
        ((base - prob(" ".join(words[:i] + words[i + 1:])), i)
         for i in range(len(words))),
        reverse=True,
    )
    top = sorted(i for _, i in ranked[:k])
    return [words[i] for i in top], [(s, words[i]) for s, i in ranked]

def span_f1(pred, gold):
    pred, gold = set(pred), set(gold)
    tp = len(pred & gold)
    if tp == 0:
        return 0.0
    precision, recall = tp / len(pred), tp / len(gold)
    return 2 * precision * recall / (precision + recall)

span, scores = occlusion_rationale("great plot and dull scenes", k=2)
print("rationale:", " ".join(span))
print("scores:", [(round(s, 3), word) for s, word in scores])
print("span F1:", round(span_f1(span, ["great", "plot"]), 3))

Real-World Applications

  • Medical triage: a risk model must show the note phrases that drove the score, evaluated with sufficiency on held-out records.
  • Moderation appeals: platforms show the flagged span, and its comprehensiveness decides whether the appeal is credible.
  • Assessment and tutoring: rationales accompany answers so a student can see which sentence was used.

💡Ask which question you are answering

If you need to know what the model used, measure faithfulness with perturbation metrics. If you need to know whether a person is convinced, run a human study. Reporting one as evidence for the other is the most common error in this area.

Common Mistakes

Quoting BLEU against gold rationales as quality

Fix: Report plausibility separately from comprehensiveness and sufficiency

Deleting tokens without replacing them

Fix: Match the token deletion scheme used by ERASER so the input length stays realistic

Assuming attention weights are faithful

Fix: Test with adversarial attention or occlusion before claiming faithfulness

Best Practices

  • Report both plausibility and faithfulness numbers
  • Include the random rationale baseline alongside the model
  • State deletion and insertion protocols, since scores depend on them

Key Takeaways

  • Plausibility is human approval; faithfulness is behavioural dependence on the span
  • Comprehensiveness should be high and the sufficiency gap low
  • AOPC summarizes the whole removal curve instead of one cut point
  • ERASER covers seven tasks; CoS-E has 8,733 training explanations

Frequently Asked Questions

Why is accuracy on the explanation not enough?

Because an explanation can match the human span while the model used other features. Only perturbation of the input reveals that, which is why ERASER scores comprehensiveness and sufficiency instead of exact match alone.

What is AOPC good for?

It summarizes how fast confidence decays as evidence is removed, so it is robust to the choice of a single removal step. Higher is better, and it makes systems with different rationale lengths comparable.

Are generated explanations evaluated the same way?

Not quite. Free-form explanations from CoS-E are compared with human text for content overlap, then checked separately for faithfulness, since a fluent sentence can still describe evidence the model ignored.

Interview Questions

Q1: How do you test whether an explanation is faithful?

Remove the cited span and measure the probability drop with comprehensiveness, or keep only that span and measure sufficiency

Q2: What does a low sufficiency gap tell you?

The rationale alone reproduces the prediction, so the model does not need the rest of the input

Q3: Why is attention not automatically an explanation?

Jain and Wallace showed adversarial attention can change predictions while weights look unchanged, so alignment needs testing

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert NLP Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement