Graph Your Own Prompt

Xi Ding, Lei Wang, Piotr Koniusz, Yongsheng Gao

TL;DR

Graph Your Own Prompt introduces Graph Consistency Regularization (GCR), a parameter-free, architecture-agnostic method that uses a model's own final predictions to guide and refine its intermediate features. By aligning batch-level feature similarity graphs with a class-masked prediction graph, GCR acts as an internal "self-prompting" mechanism that clears up noisy feature spaces and significantly boosts generalization across both CNNs and Vision Transformers.

What Problem Does This Paper Address?

While deep neural networks excel at classification, their internal feature representations are often messy and entangled. Intermediate layers frequently group samples from different classes together based on superficial visual similarities (e.g., a deer and a horse sharing similar brown fur or background textures), ignoring true semantic boundaries.

Existing methods like contrastive learning or graph-based regularizers attempt to structure these feature spaces, but they often require complex positive/negative sampling strategies, heavy architectural modifications (like Graph Neural Networks), or only operate at a single layer. The authors address a fundamental gap: how to enforce semantic consistency between geometric feature relationships and final prediction outputs across multiple depths of a network without adding any new parameters or altering the training pipeline.

Methods

The authors propose Graph Consistency Regularization (GCR), which introduces plug-and-play Graph Consistency Layers (GCLs) at arbitrary depths of a network.

The mechanism operates locally within each training batch through a few key steps:

  1. Feature Graph Construction: At any selected intermediate layer, a GCL computes a pairwise relational graph based on the cosine similarity of the feature activations.
  2. Masked Prediction Graph: A reference graph is built using the pairwise similarity of the model's final softmax predictions. To ensure the model focuses purely on semantically valid relationships, this graph is modulated via element-wise multiplication with a binary mask derived from ground-truth labels (retaining only intra-class relationships).
  3. Cross-Space Alignment: GCR minimizes the squared Frobenius norm between the upper triangular portions of the feature graph and the masked prediction graph.
  4. Adaptive Weighting: Instead of treating all layers equally, GCR dynamically assigns higher weights to layers exhibiting greater structural misalignment, allowing the network to selectively fix the most problematic representations.
Figure 2: Our parameter-free Graph Consistency Layer (GCL), highlighted in red, can be inserted after any micro-network block (e.g., Inception) or specific layer (e.g., fully connected). Each GCL constructs a relational graph from batch-level features using a similarity metric (e.g., cosine). A reference graph is generated from softmax predictions and masked by intra-class indicators: binary masks identifying semantically consistent pairs. Each GCL enforces alignment between masked prediction graph and the feature-level graphs. The resulting consistency signals are adaptively weighted, forming the Graph Consistency Regularization (GCR) framework, which integrates with the primary loss (e.g., cross-entropy), acting as a semantic regularizer to guide learning.

Datasets

The framework was validated across a diverse array of standard image classification benchmarks:

  • Kaggle Cats vs. Dogs
  • CIFAR-10
  • CIFAR-100
  • Tiny ImageNet
  • ImageNet-1K

While no new datasets were introduced, the method's robustness was extensively tested across ten distinct CNN backbones (e.g., MobileNet, ShuffleNet, ResNet, DenseNet) and multiple Transformer-based architectures (e.g., ViT, Swin, iFormer, ViG).

Key Insights and Ideas

  • Predictions as Structural Prompts: Rather than relying on external tokens or instructions, GCR treats the final prediction space as an implicit structural prompt that recursively refines earlier layers.
  • Implicit Attention Mechanism: Even though GCLs are entirely parameter-free, optimizing the GCR loss forces intermediate feature maps to localize more sharply on class-discriminative regions (like cat ears or dog noses) rather than background noise.
  • The Value of Adaptive Weighting: Naive layer aggregation can dilute regularization effects. Dynamically scaling layer importance based on graph discrepancy magnitudes ensures that the network prioritizes fixing the most chaotic layers.
  • Preserving Intra-Class Variation: By aligning features with soft prediction probabilities rather than rigid one-hot labels, GCR creates an information bottleneck that filters out nuisance factors while still allowing natural intra-class variations to persist.

Key Results

GCR consistently improved classification accuracy across all tested models and datasets without changing the underlying backbones:

  • CIFAR-100: Applying a "Late GCL" configuration boosted the baseline mean accuracy from 72.95% to 74.74% (a +1.79% absolute gain).
  • ImageNet-1K: GCR achieved notable performance jumps on large-scale tasks, boosting ViG-B from 82.3% to 84.0% (+1.7%) and iFormer-B from 84.6% to 86.1% (+1.5%).
  • Qualitative Improvements: Relational graph and t-SNE visualizations demonstrated that GCR successfully suppresses noisy inter-class affinities, resulting in much tighter intra-class clusters and distinct separation between semantically unrelated groups (such as clearly separating animals from vehicles).
Figure 1: Relational graph visualization using a batch of 64 samples from CIFAR-10 on (left) DenseNet-121 and (right) MobileNet. We compare the baselines with their counterparts augmented by our GCLs. Our method promotes richer, class-aware semantic representations by acting as a form of self-prompting. For DenseNet-121, the baseline feature relational graph tends to connect samples based on superficial visual similarity (e.g., deer, horse, and automobile), often ignoring semantic boundaries. In contrast, our GCL-enhanced model produces more semantically coherent groupings, clearly separating animals from vehicles. On MobileNet, the prediction relational graph further highlights the strength of our method, demonstrating cleaner, more distinct class relationships compared to the baseline. These improvements reflect the effectiveness of our model in aligning feature and prediction spaces with semantic structure, despite being lightweight and parameter-free.

Limitations and Future Work

The authors note a few key limitations and areas for future exploration:

  • Sensitivity to Label Noise: Because the prediction graph relies on ground-truth labels to construct its binary mask, highly noisy data or mislabeled examples can propagate errors and degrade feature quality.
  • Batch-Size Constraints: GCR computes relationships locally within each batch. In extremely small batches or highly imbalanced datasets, minority classes may lack sufficient representation to form stable, informative graphs.
  • Future Directions: Promising next steps include extending GCR to unsupervised or self-supervised settings by replacing the ground-truth mask with pseudo-labels or dynamic clustering assignments. The authors also suggest exploring more expressive graph metrics (like Earth Mover's Distance) and adapting the framework to other tasks like semantic segmentation and object detection.

Summary updated

BibTeX
@inproceedings{ding2025graph,
  author = {Xi Ding and Lei Wang and Piotr Koniusz and Yongsheng Gao},
  title = {{Graph Your Own Prompt}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=7tXGIbrIA5},
}
Figure