Natural Language Explanation: Generating Explanations
Module: Natural Language Processing | Difficulty: Advanced
Rationale Extraction
Explanation Generation
Evaluation
| Metric | What it Measures |
|---|---|
| BLEU | Overlap with gold |
| AUPRC | Faithfulness |
| Human Eval | Overall quality |
Faithfulness
import torch
import torch.nn as nn
class ExplanationGenerator(nn.Module):
def __init__(self, encoder, decoder):
super().__init__()
self.encoder = encoder
self.decoder = decoder
def forward(self, input_text, label=None):
encoded = self.encoder(input_text)
if label is not None:
output = self.decoder(label, encoded)
return output
return self.decoder.generate(encoded)
Research Insight: Generated explanations are often not faithful to the model's reasoning process. The key challenge is ensuring that explanations reflect the model's actual decision-making, not post-hoc rationalization. Contrastive explanations are more faithful than additive ones.