Interpretability is the ability to understand or audit a model’s outputs and the factors behind them. For large language models (LLMs), analytical tools can reveal how inputs relate to generated text, helping identify possible biases or errors. Understanding pretraining data also helps trace the origins of downstream problems. section 10.0 section 10.1
Visualizations can show attention attribution at the layer, attention-head, or token level. Captum provides another way to analyze model behavior through attribution scores. section 10.2 section 10.2.1
Captum supports two approaches to estimating attribution scores:
- Perturbation-based methods evaluate a model multiple times with varied inputs. They do not require access to model weights. section 10.2.1
- Gradient-based methods use backpropagated gradient information and require access to model weights. section 10.2.1
Attributing generated text
For Llama 3 8B Instruct, generate a continuation to a prompt about a person’s location, occupation, and interests. Wrap the model with Captum’s FeatureAblation and LLMAttribution, then use TextTokenInput to attribute a target continuation to the prompt tokens. Plot the result as a token-attribution heat map. Feature ablation systematically removes input features to estimate their effects on the target. section 10.2.1
Listing 10.7 Getting the attribution result of your LLM
inp = TextTokenInput( eval_prompt, tokenizer, skip_tokens=[1]) target = "hiking, skiing, and playing the piano." attr_res = llm_attr.attribute(inp, target=target)
Create a token-based input and calculate attribution for a chosen target continuation. section 10.2.1
Listing 10.9 Plot attribution results of your LLM
inp = TextTemplateInput(
template="{} lives in {},
{} and is a {}. {} personal interests include",
values=["Nicole", "Zurich", "Switzerland", "data scientist", "Her"],)
target = "hiking, skiing, and playing the piano."
attr_res = llm_attr.attribute(inp, target=target)
attr_res.plot_token_attr(show=True)
Use a template to analyze selected values, such as the person’s location and occupation, rather than individual prompt tokens. section 10.2.1
Interpretability also benefits from knowing where an answer’s information came from. Retrieval-augmented generation makes retrieved sources available for auditing, while the Foundation Model Transparency Index assesses broader disclosures about model development, characteristics, and applications. These complement analysis of model behavior rather than performing the same job. section 5.4.2 section 10.3.1















