Beyond Post-Quantization: Native Hash Learning with a Dedicated HASH Token

Xinze Liu, Ding Wang, Dayan Wu, Hengjie Zhu, Peng Fu, Zheng Lin, Weiping WangarXiv 2026

TL;DR

HashViT introduces a novel paradigm for deep image hashing by embedding a dedicated HASH token directly into a Vision Transformer (ViT) backbone. Instead of abruptly binarizing continuous features at the network's output, HashViT progressively refines a discrete-oriented representation across layers, significantly reducing the feature-to-code discrepancy and achieving state-of-the-art image retrieval performance with negligible computational overhead.

What Problem Does This Paper Address?

Large-scale image retrieval relies heavily on deep image hashing—mapping high-dimensional images into compact binary codes (e.g., 16 to 64 bits) to enable lightning-fast similarity searches in Hamming space.

However, almost all existing deep hashing methods suffer from a post-quantization dilemma. They use a standard backbone (CNN or ViT) to learn rich, continuous visual features, and then abruptly force these features into binary values at the very last layer using a projection head or a sign function (sgn). This creates a severe feature-to-code discrepancy: the internal layers of the network are optimized for continuous geometric spaces, completely unaware of the discrete constraints required at the output. Forcing a sudden binarization step at the end either discards vital semantic information or severely distorts the learned feature space.

Methods

HashViT solves this by making hash learning a native, internal process within the transformer backbone.

Fig. 2. Overview of HashViT. The CLS token captures continuous visual semantics, while the HASH token learns native hash representations. Text-guided semantic hash centers, similarity distillation, and quantization regularization jointly supervise discriminative and binary-friendly hash learning.

The framework introduces several key architectural and optimization innovations:

  1. Dual-Token Design: Alongside the standard class (CLS) token that captures continuous global semantics, HashViT inserts a dedicated HASH token into the input sequence. This token participates in self-attention across all layers, evolving alongside the visual patch tokens.
  2. Structural Decomposition: To prevent strict binary constraints from destroying the token's representational capacity, the HASH token is split into two subspaces:
  3. Hash Register: A low-dimensional space explicitly aligned with the target bit length, used to generate the final binary code.
  4. Semantic Workspace: A higher-dimensional space that retains continuous auxiliary semantics.
  5. Hash Refinement Adapter (HRA): After each transformer block, a lightweight, parameter-shared linear layer uses the continuous information from the Semantic Workspace to apply a residual correction to the Hash Register. This allows the register to progressively polarize without disrupting the rest of the network.
  6. Unified Optimization Objective: The model is trained end-to-end using three complementary losses:
  7. Learnable Semantic Hash Center Loss: Class anchors in the hash space are initialized using text embeddings from a frozen CLIP model and optimized dynamically.
  8. Similarity Distillation Loss: Fine-grained, instance-level relationships are distilled from the continuous CLS token space into the HASH token space.
  9. Quantization Loss: An auxiliary regularizer that gently nudges the register values toward $\{-1, +1\}$.

Datasets

The authors evaluated HashViT on three widely accepted image retrieval benchmarks:

  • CIFAR-10: A single-label dataset containing 60,000 images across 10 classes.
  • NUS-WIDE: A multi-label web image dataset containing nearly 270,000 images annotated with 81 concept labels.
  • ImageNet (ILSVRC 2015): A 100-class subset containing over 130,000 images, serving as a rigorous large-scale benchmark.

Key Insights and Ideas

  • Native Hashing vs. Terminal Readout: Hashing shouldn't be treated as a post-processing step. By allowing the retrieval state to interact with patch tokens from the very first layer, the backbone learns features that are inherently "binary-friendly."
  • Progressive Polarization: Visualization of the Hash Register reveals that its distribution gradually shifts from a standard continuous bell curve in early layers to a stark, bimodal distribution (concentrated at -1 and +1) in the final layers. This gradual transition preserves semantic integrity far better than a single terminal projection.
  • The Power of Text Priors: Initializing hash centers using language-derived semantics (via CLIP text embeddings) provides a structurally superior starting point for organizing the Hamming space compared to random or purely mathematical initializations (like Hadamard matrices).

Key Results

HashViT-S (built on a compact ViT-Small backbone) achieves state-of-the-art or highly competitive mean Average Precision (mAP) across all datasets and code lengths.

Performance comparison of deep hashing methods
  • Outperforming Massive Models: On CIFAR-10, HashViT-S achieves 96.36% mAP (at 64 bits), outperforming TransHash, which relies on a massive ViT-Large backbone containing more than 13 times the parameters (292.9M vs 21.7M).
  • ImageNet Superiority: On the challenging ImageNet benchmark, HashViT-S hits 91.06% mAP (at 64 bits), outperforming its closest transformer baseline (FTH-DeiT-S) by nearly 6%.
  • Negligible Overhead: Adding the single HASH token increases the self-attention sequence length by just one, resulting in a mere ~1.0% increase in attention computation. The HRA module adds only about 20,000 parameters, making it incredibly lightweight.

Limitations and Future Work

  • Dependence on Text Encoders: The text-guided initialization strategy relies on a pre-trained CLIP text encoder. If the target dataset contains highly abstract or domain-specific categories that CLIP struggles to represent, the initialization quality might degrade.
  • Architecture Specificity: The current formulation is tightly coupled with the token-based nature of Vision Transformers. Adapting this concept of "native internal hash evolution" to pure CNN architectures or newer state-space models (like Mamba) remains an open research question.

Summary updated

BibTeX
@misc{liu2026beyond,
  author = {Xinze Liu and Ding Wang and Dayan Wu and Hengjie Zhu and Peng Fu and Zheng Lin and Weiping Wang},
  title = {{Beyond Post-Quantization: Native Hash Learning with a Dedicated HASH Token}},
  year = {2026},
  eprint = {2607.03328},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.03328},
}
Figure