---
title: 'OrdShap: Order-Aware Feature Attribution'
url: https://www.emergentmind.com/topics/ordshap
type: topic
---

# OrdShap: Order-Aware Feature Attribution

OrdShap is a post-hoc feature attribution framework designed to elicit position-sensitive explanations for sequential black-box models. Unlike prior attribution methods that assume fixed feature ordering, OrdShap quantifies the marginal effect of permuting feature positions, thereby separating the influence of feature value ("what is present") and feature position ("where it occurs") in the input sequence. The approach is rooted in an axiomatic, game-theoretic foundation, providing both theoretical guarantees and practical algorithms for order-aware model explanation, with demonstrated empirical benefits across domains such as healthcare, NLP, and synthetic data [2507.11855].

## 1. Motivation and Problem Formulation

Feature attribution in sequential architectures—including Transformers, RNNs, and their variants—traditionally conflates two sources of importance: the magnitude or identity of a value and its position in the sequence. Most post-hoc techniques (e.g., KernelSHAP, LIME, gradient-based saliency) perturb only feature values under a fixed index, treating the position as invariant. This assumption is violated in domains where shuffling elements induces significant prediction changes. For example, reordering medical measurements or text tokens may flip the prediction of a clinical outcome or sentiment, respectively.

OrdShap seeks to decompose the overall feature attribution into:
- **Value Importance (VI):** The marginal effect on prediction of injecting a feature value, averaged over possible positions.
- **Position Importance (PI):** The marginal effect on prediction of altering a feature's position, holding the value fixed.

This separation supplies diagnosis of whether a model's reliance on a sequence element arises due to its content, its location, or both.

## 2. Mathematical Definitions and Formalism

OrdShap models sequential attribution as a cooperative game on ordered coalitions. Let \( x = (x_1, ..., x_d) \) be a sequence, \( f(x) \) the model output, \( N = \{1, ..., d\} \) the feature set, and \(\mathfrak{S}_N\) the group of permutations. The central ingredient is a permutation-aware characteristic function:

\[
\omega_{f,x}(S,\sigma)
= \mathbb{E}_{x' \sim \mathcal{X}}
\left[ f(\text{permute}(x',\sigma)) \mid x'_{\sigma(i)} = x_i \; \forall\, i \in S \right]
\]

where “permute(x’,σ)” reorders coordinates according to σ, and features not in S are ablated (typically via sampling from a reference distribution).

The OrdShap value \(\gamma_{i, \ell}\) assigns to each input coordinate-position pair the marginal expected effect, averaged over all subsets and permutations where feature i occupies position \( \ell \):

\[
\gamma_{i,\ell}(N,\omega)
= \sum_{\substack{S \subseteq N,\, i \in S}}
    \sum_{\substack{\sigma \in \mathfrak{S}_N\\\sigma^{-1}(i) = \ell}}
        \frac{(|S|-1)!\,(d-|S|)!}{(d-1)!\,d!}
        \left[
            \omega(S, \sigma) - \omega(S \setminus \{i\}, \sigma)
        \right]
\]

This construction produces a \( d \times d \) matrix of attributions. Aggregating \(\gamma_{i,\ell}\) yields summary measures:
- **OrdShap-VI** (\(\overline{\gamma}_i\)): Feature i's average effect across all positions,
  \[
  \overline{\gamma}_i = \frac{1}{d} \sum_{\ell=1}^{d} \gamma_{i,\ell}
  \]
- **OrdShap-PI** (\(\beta_i\)): The signed slope from regressing attributions on position,
  \[
  (\gamma_{i,\ell} - \overline{\gamma}_i) \approx \beta_i \, (\ell - \bar{\ell}), \qquad \bar{\ell} = \frac{d+1}{2}
  \]
where \( \beta_i > 0 \) indicates growing importance in later positions.

## 3. Axiomatic Foundation: Sánchez-Bergantiños (SB) Value

The classical Shapley value applies axiomatic fairness to unordered feature sets. Sánchez-Bergantiños (1997) generalizes this to ordered coalitions, defining an SB value sensitive to insertion order:

\[
\varphi_i^{\text{SB}}(N,\omega) 
= \sum_{S \subseteq N\setminus\{i\}} \sum_{\sigma \in \mathfrak{S}_S}
    \frac{(d - |S| - 1)!}{d!\,(|S|+1)}
    \sum_{\ell=1}^{|S|+1} \left[
        \omega(S \cup \{i\}, \sigma_{0i,\ell}) - \omega(S, \sigma)
    \right] 
\]

where \( \sigma_{0i, \ell} \) inserts i into position \( \ell \) in \( \sigma \).

A critical result (Theorem 3.1 of [2507.11855]) establishes that the average OrdShap value for each feature (\(\overline{\gamma}_i\)) coincides with the SB value \(\varphi_i^{\mathrm{SB}}\) for an appropriately symmetrized game \(\hat{\omega}\). This connects OrdShap to a unique, order-aware extension of Shapley values that satisfies efficiency, symmetry, null-player, and additivity axioms in the context of input sequences.

## 4. Approximation Algorithms and Computational Considerations

Exact OrdShap computation is intractable for moderate \( d \), requiring \( O(d!\,2^d) \) model evaluations. Two model-agnostic estimators are proposed:

### Sampling-Based Approximation

For each feature-position pair \((i, \ell)\), random subsets of features \( S \subseteq N \) are sampled, along with permutations placing \( i \) at location \( \ell \). The corresponding marginal contributions are evaluated and averaged, using Shapley-style combinatorial weights.

- Complexity: \( O(d\,K\,L\,\delta_f) \), where \( K \) is the number of sampled subsets, \( L \) the permutation samples, and \( \delta_f \) the cost of a model call.

### Least-Squares Estimation for VI and PI

A more efficient estimator solves for the \( 2d \) parameters (\( \overline{\gamma}_i \), \( \beta_i \)) by regressing model response (relative to a baseline) against presence and positional offset of features over sampled sequences:

\[
f(x_{\text{masked by } (S, \sigma)}) - f(\mathbf{0}) \approx 
\sum_{i \in S} \overline{\gamma}_i + \sum_{i \in S} (\sigma^{-1}(i) - \bar{\ell}) \beta_i
\]

The optimal coefficients are obtained by solving the corresponding normal equations on weighted sampled data.

- Complexity: \( O(KL\,\delta_f + d^2KL + d^3) \), practical for low hundreds of features with thousands of samples.

## 5. Experimental Validation

**Empirical results** demonstrate OrdShap's practical relevance and superiority over traditional value-only attributions.

### Datasets
- **Health/EHR:** MIMIC-III and eICU clinical cohorts, using BERT-based models for mortality and length-of-stay prediction.
- **NLP:** IMDB reviews with sentence-level DistilBERT sentiment analysis.
- **Synthetic:** Controlled 10-token sequences across two regimes: a purely value-driven linear model and a position-sensitive nonlinear model.

### Evaluation and Baselines

Metric                             | Objective                     | Observation
:----------------------------------|:-----------------------------|:----------------------------------
Position Importance test           | PI's effect via permutation   | OrdShap-PI maintains/increases (AUC > 0.50), others degrade
Value Importance test (IncAUC, ExcAUC) | VI with/without random reordering | OrdShap-VI achieves high IncAUC on all models, competitive ExcAUC

Comparative methods: KernelSHAP, LIME, LOCO, Integrated Gradients, DeepLIFT, and Random.

### Results

- OrdShap-PI outperforms all baselines in PI-based permutation tests and separates token types in the synthetic regime, whereas conventional attributions intermingle types.
- OrdShap-VI reliably yields highest inclusion AUC in value tests.
- Qualitative case studies in clinical settings show OrdShap-VI and PI distinguish value-driven from position-driven features (e.g., potassium chloride's early vs. bedside glucose's late importance), whereas value-only methods confound the two.

## 6. Insights, Limitations, and Future Perspectives

### Key Insights

- OrdShap is the first post-hoc explainer to robustly disentangle value and position effects in sequential models.
- The approach generalizes established game-theoretic attributions (SB value) to capture ordering.
- The two-dimensional attribution (VI and PI) enables nuanced diagnosis of model reliance on content versus temporal location.

### Limitations

- Exact solution complexity is prohibitive (factorial in sequence length), necessitating approximation with many model queries.
- Assumes arbitrary permutation is permissible; does not immediately transfer to irregular series or constrained domains.

### Future Directions

- Leverage stratified sampling and low-rank approximations for scalability.
- Extend framework to continuous or irregular position spaces in time-series.
- Integrate with causal analysis to reflect structural constraints such as non-leakage in temporal prediction.
- Explore grouped feature attributions and their interplay with positional effects.
- Conduct user-facing evaluations for interpretability in clinical and financial applications.

OrdShap furnishes a principled, axiomatically justified, and empirically validated mechanism for order-sensitive attributions, elucidating both content and temporal effects in modern sequential modeling [2507.11855].

Source: https://www.emergentmind.com/topics/ordshap