## 3 Materials and Methods
### Model Architecture
#### 3.2.2 Bidirectional Cross-Attention for Local Alignment
\begin{array}{l}Q_{i}^{reshaped}=reshape(Q_{i},[batch,1,16,48])\rightarrow[ batch,16,1,48]\\ K_{i}^{reshaped}=reshape(K_{i},[batch,1,16,48])\rightarrow[batch,16,1,48]\\ V_{i}^{reshaped}=reshape(V_{i},[batch,1,16,48])\rightarrow[batch,16,1,48]\\ \end{array} \right. \tag{5}\]  
This step is crucial for leveraging the parallel computing capabilities of modern hardware, thereby enhancing the efficiency of the attention mechanism. (c) Attention Calculation: The attention weights are computed to determine the importance of different elements in the Key for the Query, and then the attention output is generated (Equation (6)):  
\[\left\{ \begin{array}{l}A_{i}=softmax\bigg{(}\frac{Q_{i}^{reshaped}K_{i}^{ reshaped}\gamma}{\sqrt{48}}\bigg{)}\rightarrow[batch,16,1,1]\\ Atnt_{i}=A_{i}V_{i}^{reshaped}\rightarrow[batch,16,1,48]\\ \end{array} \right. \tag{6}\]  
The division by \(\sqrt{48}\) (the head dimension) serves to stabilize the softmax operation by controlling the variance of the dot-product, ensuring more reliable attention weight calculations. For the Text \(\rightarrow\) Image (T \(\rightarrow\) I) attention process, let \(W_{t}^{Q}\in\mathbb{R}^{512\times 768}\), \(W_{i}^{K}\in\mathbb{R}^{512\times 768}\), and \(W_{i}^{V}\in\mathbb{R}^{512\times 768}\) be the projection matrices. The sequence of operations is analogous to the I \(\rightarrow\) T flow:  
(a) Query/Key/Value Projection (Equation (7)):  
\[\left\{ \begin{array}{l}Q_{t}=v_{t}W_{t}^{Q}\\ K_{t}=v_{t}W_{t}^{K}\\ V_{t}=v_{t}W_{i}^{V}\end{array} \right. \tag{7}\]  
where \(Q_{t},~{}K_{t},~{}V_{t}\in\mathbb{R}^{512\times 768}\). (b) Multi-Head Reshaping (Equation (8)):  
\[\left\{ \begin{array}{l}Q_{t}^{reshaped}=reshape(Q_{t},[batch,1,16,48]) \rightarrow[batch,16,1,48]\\ K_{t}^{reshaped}=reshape(K_{t},[batch,1,16,48])\rightarrow[batch,16,1,48]\\ V_{t}^{reshaped}=reshape(V_{t},[batch,1,16,48])\rightarrow[batch,16,1,48]\\ \end{array} \right. \tag{8}\]  
(c) Attention Calculation (Equation (9)):  
\[\left\{ \begin{array}{l}A_{t}=softmax\bigg{(}\frac{Q_{t}^{reshaped}K_{t}^{ reshaped}\gamma}{\sqrt{48}}\bigg{)}\rightarrow[batch,16,1,1]\\ Atnt_{t}=A_{t}V_{t}^{reshaped}\rightarrow[batch,16,1,48]\\ \end{array} \right. \tag{9}\]  
(3) Layer Normalization  
After each attention pathway, Layer Normalization is applied. The Layer Normalization operation is defined as (Equation (10)):  
\[LayerNorm(x)=\gamma\frac{x-\mu}{\sigma+\epsilon}+\beta \tag{10}\]  
where \(\mu\) and \(\sigma\) are the mean and standard deviation of the input tensor \(x\) computed over the appropriate dimensions, \(\epsilon\) is a small epsilon value (e.g., \(1~{}\times~{}10^{-5}\)) to avoid division by zero, and \(\gamma\) and \(\beta\) are learnable parameters. This operation stabilizes the training process by normalizing the input to each layer, reducing internal covariate shift and accelerating convergence. Subsequently, feature fusion is carried out. The attention outputs from both the Image \(\rightarrow\) Text (I \(\rightarrow\) T) and Text \(\rightarrow\) Image (T \(\rightarrow\) I) pathways are first reshaped back to a unified dimension and then combined. Let \(W^{O}\in\mathbb{R}^{768\times 512}\) be the output projection matrix. For the Image \(\rightarrow\) Text (I \(\rightarrow\) T) attention output Attn (Equation (11)):  
\[\left\{ \begin{array}{l}Attn_{i}^{\textit{resolved}}=reshape(Attn_{i},[ batch,1,768])\\ Attn_{i}^{\textit{projected}}=Attn_{i}^{\textit{resolved}}W^{O}\end{array} \right. \tag{11}\]  
Similarly, for the Text \(\rightarrow\) Image (T \(\rightarrow\) I) attention output Attn\({}_{t}\) (Equation (12)):  
\[\left\{ \begin{array}{l}Attn_{t}^{\textit{resolved}}=reshape(Attn_{t},[ batch,1,768])\\ Attn_{t}^{\textit{projected}}=Attn_{t}^{\textit{resolved}}W^{O}\end{array} \right. \tag{12}\]  
The resulting semantically refined outputs are forwarded to the gating module described in Section 3.2.3 for reliability-aware integration.