Inferensys

Glossary

Directional Derivative

The rate of change of a model's prediction score with respect to an infinitesimal shift in the input's activation along a specific concept vector direction.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
CONCEPT SENSITIVITY ANALYSIS

What is Directional Derivative?

The directional derivative quantifies the rate of change of a model's prediction score with respect to an infinitesimal shift in the input's activation along a specific concept vector direction.

In the context of neural network interpretability, the directional derivative measures the instantaneous sensitivity of a class logit to a Concept Activation Vector (CAV). Formally, if ( f(x) ) is the logit for a class and ( v_c ) is a unit CAV representing a concept, the directional derivative is ( \nabla f(x) \cdot v_c ). This scalar value captures how strongly and in which direction the prediction responds to the abstract concept encoded by ( v_c ).

This computation is the mathematical foundation of the Testing with CAVs (TCAV) framework. By calculating the directional derivative for multiple inputs, TCAV derives a sensitivity score that quantifies a model's overall reliance on a user-defined concept. A statistically significant, positive directional derivative indicates that amplifying the concept's activation increases the model's confidence in the target class, providing a quantitative bridge between high-level semantics and internal network geometry.

Concept Sensitivity Analysis

Key Characteristics of the Directional Derivative

The directional derivative quantifies how a model's prediction score changes as its internal activations are infinitesimally shifted along a specific concept vector direction, forming the mathematical backbone of concept-based interpretability.

01

Mathematical Definition

For a class prediction score ( f_l(x) ) at layer ( l ), the directional derivative with respect to a concept vector ( v_C ) is defined as:

( S_{C,k,l}(x) = \nabla h_{l,k}(f_l(x)) \cdot v_C )

  • ( h_{l,k} ) is the logit function for class ( k ) from layer ( l )
  • ( \nabla h_{l,k} ) is the gradient of that logit with respect to activations
  • ( v_C ) is the unit Concept Activation Vector (CAV)
  • The dot product yields a scalar sensitivity score
  • A positive value indicates the concept increases the class prediction; a negative value decreases it
02

Role in TCAV Framework

The directional derivative is the core computational mechanism within Testing with CAVs (TCAV). It transforms abstract concept vectors into quantifiable metrics:

  • For each input ( x ) in a dataset, TCAV computes the directional derivative toward a concept vector
  • The fraction of inputs with a positive directional derivative becomes the TCAV score
  • This score represents how sensitive the model's prediction is to the concept
  • A TCAV score of 0.8 means 80% of inputs show increased class probability when activations shift toward the concept
  • Enables quantitative hypothesis testing about what a model has learned
03

Geometric Interpretation

In the high-dimensional activation space, the directional derivative has a clear geometric meaning:

  • The gradient ( \nabla h ) points in the direction of steepest ascent for the class score
  • The directional derivative measures the projection of this gradient onto the concept vector
  • If the gradient and concept vector are aligned (cosine similarity near 1), the derivative is large and positive
  • If they are orthogonal (cosine similarity near 0), the concept has no local influence
  • If they are opposed (cosine similarity near -1), the concept actively suppresses the prediction
  • This projection reveals which concepts the model uses as evidence for or against a class
04

Statistical Validation

Raw directional derivatives require statistical testing to ensure the concept signal is not an artifact:

  • TCAV computes directional derivatives for the true concept vector and for multiple random vectors
  • A two-sided t-test compares the distribution of sensitivity scores
  • The null hypothesis: the concept vector produces scores indistinguishable from random directions
  • A concept passes validation only if the p-value is below a threshold (typically 0.05)
  • This guards against spurious correlations where random noise directions accidentally align with gradients
  • Only statistically significant concepts are considered genuinely learned by the model
05

Layer-Specific Analysis

Computing directional derivatives at different network layers reveals where concepts are encoded:

  • Early layers: Directional derivatives often capture low-level concepts like textures, edges, or colors
  • Middle layers: Begin encoding composite concepts like object parts and shapes
  • Final layers: Encode high-level semantic concepts like object categories and abstract attributes
  • A concept may have a strong directional derivative at one layer but be absent at another
  • This layer-wise profiling maps the hierarchy of abstraction in the network
  • Engineers use this to identify which layers to probe for specific concept auditing tasks
06

Practical Computation

Implementing the directional derivative requires careful numerical handling:

  • Compute the gradient of the target class logit with respect to activations at the chosen layer using backpropagation
  • Normalize the CAV to a unit vector to ensure comparability across concepts
  • The dot product ( \nabla h \cdot v_C ) is computed per input in a batch
  • For stochastic settings, average gradients over multiple forward passes
  • Libraries like TensorFlow and PyTorch provide automatic differentiation for efficient gradient computation
  • The result is a scalar tensor representing instantaneous sensitivity at the current activation point
DIRECTIONAL DERIVATIVES IN CONCEPT-BASED EXPLANATIONS

Frequently Asked Questions

Addressing common questions about how directional derivatives quantify a model's sensitivity to high-level concepts, enabling rigorous, human-auditable explanations of neural network decisions.

A directional derivative quantifies the instantaneous rate of change of a model's prediction score with respect to an infinitesimal shift in the input's activation along a specific concept vector direction. In the context of Concept Activation Vectors (CAVs) and Testing with CAVs (TCAV), it measures how sensitive a class prediction is to the presence of a high-level, human-understandable concept. Mathematically, for a class logit (y_k) and a concept vector (v_l) in the activation space of a layer, the directional derivative (S_{k,l}(x)) is computed as the dot product of the gradient of (y_k) with respect to the activations and the unit concept vector. This value forms the core of the sensitivity metric, directly indicating whether increasing the concept's presence pushes the prediction towards or away from the target class.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.