Counterfactual Peptide Editing for Causal TCR--pMHC Binding Inference
Abstract
Neural models for TCR-pMHC binding prediction are susceptible to shortcut learning: they exploit spurious correlations in training data -- such as peptide length bias or V-gene co-occurrence -- rather than the physical binding interface. This renders predictions brittle under family-held-out and distance-aware evaluation, where such shortcuts do not transfer. We introduce Counterfactual Invariant Prediction (CIP), a training framework that generates biologically constrained counterfactual peptide edits and enforces invariance to edits at non-anchor positions while amplifying sensitivity at MHC anchor residues. CIP augments the base classifier with two auxiliary objectives: (1) an invariance loss penalizing prediction changes under conservative non-anchor substitutions, and (2) a contrastive loss encouraging large prediction changes under anchor-position disruptions. Evaluated on a curated VDJdb-IEDB benchmark under family-held-out, distance-aware, and random splits, CIP achieves AUROC 0.831 and counterfactual consistency (CFC) 0.724 under the challenging family-held-out protocol -- a 39.7% reduction in shortcut index relative to the unconstrained baseline. Ablations confirm that anchor-aware edit generation is the dominant driver of OOD gains, providing a practical recipe for causally-grounded TCR specificity modeling.
Figures & tables
| Split | Train | Val | Test | Pos. rate |
|---|---|---|---|---|
| Random | 118 742 | 16 963 | 33 927 | 0.050 |
| Family-HO | 92 314 | 11 082 | 21 843 | 0.042 |
| Distance-aware | 87 508 | 10 501 | 19 624 | 0.039 |
| Split | Method | AUROC | AUPRC | ECE | BS | NLL |
|---|---|---|---|---|---|---|
| FHO | Baseline | 0.779 | 0.421 | 0.138 | 0.091 | 0.219 |
| +Edit Aug | 0.798 | 0.447 | 0.112 | 0.084 | 0.197 | |
| CIP (ours) | 0.831 | 0.491 | 0.083 | 0.073 | 0.171 | |
| DA | Baseline | 0.758 | 0.399 | 0.151 | 0.097 | 0.234 |
| +Edit Aug | 0.779 | 0.428 | 0.121 | 0.089 | 0.211 | |
| CIP (ours) | 0.812 | 0.463 | 0.095 | 0.079 | 0.186 |
| Method | OOD AUROC | SI | CFC | AFR |
|---|---|---|---|---|
| Baseline | 0.741 | 0.412 | 0.518 | 0.231 |
| +Edit Aug | 0.768 | 0.311 | 0.634 | 0.287 |
| CIP (ours) | 0.803 | 0.249 | 0.724 | 0.401 |
| Configuration | AUROC | AUPRC | CFC | AFR |
|---|---|---|---|---|
| CIP (full) | 0.831 | 0.491 | 0.724 | 0.401 |
| w/o | 0.816 | 0.473 | 0.701 | 0.264 |
| w/o | 0.808 | 0.461 | 0.591 | 0.388 |
| w/o anchor masking | 0.819 | 0.477 | 0.662 | 0.319 |
| w/o BLOSUM constraint | 0.822 | 0.479 | 0.689 | 0.371 |
| Baseline (no auxiliary loss) | 0.779 | 0.421 | 0.518 | 0.231 |
Counterfactual Data Augmentation
Counterfactual data augmentation creates plausible examples by changing a chosen feature while preserving relevant context, helping models learn robust distinctions.
See all 38 papers