Skip to main content
QUICK REVIEW

[Paper Review] Rethinking Query, Key, and Value Embedding in Vision Transformer under Tiny Model Constraints

Jaesin Ahn, Jiuk Hong|arXiv (Cornell University)|Nov 18, 2021
Machine Learning and ELMComputer Science2 citations
TL;DR

This paper proposes three novel non-linear, shared, and code-based query (Q), key (K), and value (V) embedding structures for Vision Transformers (ViT) under tiny model constraints. By replacing standard linear projections with learnable non-linear mappings—especially via shared layers and trainable code parameters—the method improves image classification accuracy with significantly fewer parameters, achieving 71.4% top-1 accuracy on ImageNet-1k with only 3.1M parameters, outperforming the original XCiT-N12 model.

ABSTRACT

A vision transformer (ViT) is the dominant model in the computer vision field. Despite numerous studies that mainly focus on dealing with inductive bias and complexity, there remains the problem of finding better transformer networks. For example, conventional transformer-based models usually use a projection layer for each query (Q), key (K), and value (V) embedding before multi-head self-attention. Insufficient consideration of semantic $Q, K$, and $V$ embedding may lead to a performance drop. In this paper, we propose three types of structures for $Q$, $K$, and $V$ embedding. The first structure utilizes two layers with ReLU, which is a non-linear embedding for $Q, K$, and $V$. The second involves sharing one of the non-linear layers to share knowledge among $Q, K$, and $V$. The third proposed structure shares all non-linear layers with code parameters. The codes are trainable, and the values determine the embedding process to be performed among $Q$, $K$, and $V$. Hence, we demonstrate the superior image classification performance of the proposed approaches in experiments compared to several state-of-the-art approaches. The proposed method achieved $71.4\%$ with a few parameters (of $3.1M$) on the ImageNet-1k dataset compared to that required by the original transformer model of XCiT-N12 ($69.9\%$). Additionally, the method achieved $93.3\%$ with only $2.9M$ parameters in transfer learning on average for the CIFAR-10, CIFAR-100, Stanford Cars datasets, and STL-10 datasets, which is better than the accuracy of $92.2\%$ obtained via the original XCiT-N12 model.

Motivation & Objective

  • To address the performance drop in tiny Vision Transformers caused by insufficient consideration of semantic Q, K, and V embedding.
  • To improve ViT performance under strict parameter constraints by rethinking the Q, K, and V embedding mechanism.
  • To explore knowledge sharing among Q, K, and V via shared non-linear layers and learnable code parameters.
  • To demonstrate that non-linear and shared QKV embedding structures enhance both ImageNet classification and transfer learning performance.

Proposed method

  • Introduces a two-layer ReLU-based non-linear embedding for Q, K, and V, transforming input tokens into separate non-linear spaces.
  • Proposes a one-layer shared structure where a single non-linear layer is shared across Q, K, and V to encourage knowledge transfer.
  • Develops a two-layer shared structure with trainable code parameters (Cq, Ck, Cv) that define the embedding transformation for Q, K, and V.
  • Uses back-propagation to jointly train the code parameters to minimize ViT classification loss.
  • Employs F-SNE visualization to analyze code similarity and orthogonality, confirming that codes learn distinct, task-agnostic features.
  • Evaluates performance on ImageNet-1k and transfer learning benchmarks (CIFAR-10, CIFAR-100, Stanford Cars, STL-10) under parameter constraints.

Experimental results

Research questions

  • RQ1Can replacing linear QKV projections with non-linear mappings improve ViT performance under tiny model constraints?
  • RQ2Does sharing non-linear layers among Q, K, and V enhance feature learning and classification accuracy?
  • RQ3Can learnable code parameters that jointly define Q, K, and V embeddings lead to better performance than independent projections?
  • RQ4How does the performance of the proposed QKV embedding structures compare to state-of-the-art models like XCiT-N12 on ImageNet and transfer learning tasks?

Key findings

  • The proposed method achieved 71.4% top-1 accuracy on ImageNet-1k with only 3.1 million parameters, outperforming the original XCiT-N12 model, which achieved 69.9%.
  • On transfer learning, the method achieved an average accuracy of 93.3% across CIFAR-10, CIFAR-100, Stanford Cars, and STL-10, surpassing the 92.2% accuracy of the original XCiT-N12 model.
  • The code-based shared structure with trainable parameters showed strong performance, particularly on CIFAR-100 and STL-10, indicating effective feature learning across tasks.
  • F-SNE visualization confirmed that the learned codes (Cq, Ck, Cv) exhibit near-orthogonality, suggesting they learn distinct, task-agnostic representations.
  • The l2-norm of the codes remained consistent across datasets (ImageNet, Cars, STL-10), but differed for CIFAR-10 and CIFAR-100, indicating dataset-specific code adaptation.
  • A code size of 8 achieved optimal performance for nano models, while 16 was optimal for tiny models, suggesting that code size should scale with embedding dimension.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.