Graph Your Own Prompt

Xi Ding, Lei Wang, Piotr Koniusz, Yongsheng Gao

Abstract

Deep neural networks often suffer from a disconnect between their internal feature representations and their final semantic predictions. While a model may correctly classify an input, its intermediate layers frequently capture noisy or entangled patterns that do not align with the target class structure. This paper introduces Graph Consistency Regularization (GCR), a parameter-free, model-agnostic method that treats a network's final predictions as a "self-prompt" to guide and clean its internal feature space. By enforcing structural consistency between feature-level and prediction-level graphs, GCR significantly improves generalization across various architectures, including CNNs and Vision Transformers.

Introduction

Despite the success of deep learning, the internal "thinking" process of neural networks remains notoriously messy. Even when a model achieves high accuracy, its intermediate feature representations—the mathematical patterns extracted at various depths—can be influenced by superficial visual cues such as background textures or lighting rather than core semantic features. For instance, a model might correctly identify both a "horse" and a "car," yet in its internal feature space, these distinct objects may appear confusingly similar due to shared environmental contexts.

This lack of alignment between features (what the model sees) and semantics (what the model predicts) limits a model's ability to generalize to unseen data and complicates interpretability. To bridge this gap, we propose Graph Consistency Regularization (GCR). GCR ensures that if two inputs are predicted to belong to the same semantic class, their internal representations should reflect a corresponding similarity, effectively "cleaning" the feature space during training.

Methodology: The Graph Consistency Layer

The primary mechanism of GCR is the Graph Consistency Layer (GCL). These lightweight modules are inserted at various depths within an existing network architecture. The GCL operates through a four-step process within each training batch:

  1. Feature Graph Construction: The GCL calculates the pairwise similarity between the features of every image in a training batch, generating a "feature graph" that represents the model's current internal organization.
  2. Masked Prediction Graph: Simultaneously, the model examines its final softmax predictions to create a "prediction graph." To ensure the model reinforces correct relationships, a mask using ground-truth labels is applied, focusing the alignment only on samples that belong to the same class.
  3. Alignment via Frobenius Norm: The model is trained to minimize the discrepancy between the feature graph and the prediction graph using the Frobenius norm. In this setup, the final prediction acts as a "prompt" that instructs earlier layers to organize their features according to the final semantic output.
  4. Adaptive Weighting: Recognizing that not all layers require the same degree of correction, GCR employs a dynamic weighting mechanism. This prioritizes layers with the highest misalignment, allowing the model to focus its learning efforts where feature noise is most prevalent.

Crucially, GCR is entirely parameter-free. It does not alter the model's architecture or increase the number of trainable parameters; rather, it changes how the model is regularized during the optimization process.

Theoretical Insights

GCR is grounded in the concept of Spectral Alignment. By aligning the Laplacian properties of the feature and prediction spaces, GCR ensures that the "clusters" identified in the internal features match the semantic clusters of the final decisions. Furthermore, by utilizing "soft" predictions (probabilities) rather than "hard" labels, the method maintains an Information Bottleneck. This forces the network to focus on essential class-discriminative features—such as the specific shape of an object—while allowing for natural intra-class variations like color or orientation.

Experimental Results

The effectiveness of GCR was validated across several standard computer vision benchmarks, including CIFAR-10/100, Tiny ImageNet, and ImageNet-1K. The results demonstrate consistent improvements across diverse architectures:

  • Accuracy Gains: On CIFAR-100, GCR improved the mean accuracy of various models by approximately 1.79%. On the large-scale ImageNet-1K dataset, it boosted the iFormer-S architecture from 83.4% to 84.8%.
  • Improved Clustering: Quantitative analysis using Silhouette scores confirmed that GCR-augmented models produce better-separated and more organized feature clusters.
  • Architectural Versatility: The method proved effective for both traditional Convolutional Neural Networks (e.g., ResNet, DenseNet) and modern Vision Transformers (e.g., ViT, Swin), highlighting its broad applicability.
  • Feature Visualization: Qualitative assessments indicate that GCR leads to cleaner feature maps. The model's "attention" becomes more localized on the actual objects of interest rather than being distracted by background noise.

Limitations and Future Work

While GCR provides a robust framework for self-correction, certain limitations remain. The current implementation relies on ground-truth labels to mask the prediction graph, which limits its use in purely unsupervised settings. Future research may explore pseudo-labeling or unsupervised clustering to extend GCR to self-supervised learning. Additionally, because the graphs are constructed at the batch level, the method may be sensitive to very small batch sizes. Finally, extreme class imbalance in datasets could lead to majority classes dominating the alignment process.

Conclusion

Graph Your Own Prompt (GCR) offers a novel perspective on regularization by treating a model's high-level semantic understanding as a guide for its low-level feature extraction. By enforcing graph consistency, GCR provides a simple, parameter-free path toward more robust, generalized, and organized neural networks.

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