## 3 Materials and Methods
### Patch-Based Transformer Model
#### 3.2.2 Patch Encoding and Transformer Block  
To adapt the transformer architecture for image classification, the input images must be transformed from their standard 2D spatial format to a 1D sequence format suitable for transformer processing, as originally proposed by [PERSON] et al. [62]. This is accomplished through a patch extraction mechanism, which divides each image into fixed-size, non-overlapping patches. Each patch is then flattened and linearly projected into a vector representation. The mathematical formulation of this transformation is given in Equations (5) and (6), and its implementation is visually depicted in Figure 7.  
\[Number\,patches\ =\ \frac{width\times height}{patchsize^{2}}patchsize^{2} \tag{5}\]  
\[(width,\,length,\,channel)\Rightarrow(number\,patches,\,patchsize^{2} \times channel) \tag{6}\]  
Each projected patch is augmented with a positional encoding to maintain spatial coherence across the image sequence [62]. These encoded patches serve as inputs to the transformer block, as illustrated in Figure 7.  
To enable the model to capture long-range dependencies between image regions, each transformer block applies a multi-head self-attention mechanism, which computes attention scores based on the query (\(Q\)), key (\(K\)), and value (\(V\)) matrices. The operation is defined by the attention formula in Equation (7) [66]:  
\[Attention(Q,K,V)\ =\ softmax\bigg{(}\frac{QK^{T}}{\sqrt{d_{k}}}\bigg{)}V \tag{7}\]  
In Equation (7), \(d_{k}\) denotes the dimensionality of the key vectors. In practice, the original patch embeddings are extended with an additional dimension to support multi-head attention, enabling the model to attend to multiple subspaces of representation in parallel [66]. The resulting shape of the encoded patches, considering the projection dimension and the number of attention heads, is given in Equation (8):  
\[(number\,patches,\,patchsize^{2}\times channel+\frac{project\_dimension}{num\_ heads}) \tag{8}\]  
Following the self-attention operation, layer normalization is applied both before and after the attention and feed-forward sublayers, adhering to the pre-normalization  
Figure 6: Applying edge detection filter to matrix. Figure 7: Encoding image matrix to transformer-processable format. strategy, which has been shown to improve model stability and convergence [67]. A residual connection (Add) is used to facilitate better gradient flow, and dropout layers are included to prevent overfitting [68; 69]. The final layer of the transformer block applies a dense feed-forward network, and the entire sequence of blocks is repeated as per the model's configuration. After the last transformer block, the sequence is flattened and passed through further dense and dropout layers to refine the representation. For classification, a sigmoid-activated output layer is used, as described in Equation (9), where \(x\) denotes the input to the final neuron before activation (i.e., the output of the raw logit score by the model):  
\[\sigma(x)\ =\ \frac{1}{1+e^{-x}} \tag{9}\]  
Importantly, rather than relying on a conventional binary output, our approach defines two output neurons without an activation function, selecting the neuron with the highest score as the predicted class [70]. This allows for a smoother, probabilistic interpretation of the model's decision boundaries. A summary of the complete encoding and transformer process is presented in Algorithm 1, which provides a high-level overview of the PV-ISM pipeline. By combining patch-level tokenization with attention-based contextual learning, the PV-ISM architecture efficiently learns global and local features necessary for robust discrimination between real and synthetic imagery.