We use a bidirectional long-short-term-memory network (LSTM) to encode each text description into a sentence-level feature vector \({s}\in \mathbb {R}^{d}\)  and a convolution network to encode each image into an image-level feature vector \( {f} \in \mathbb {R}^{d} \) . To train these two feature extractors, we adopt a contrastive loss that maximizes the image-text similarity among a batch of training samples.
Following AttnGAN [1]}, we first calculate the similarity matrix for all possible text-image pairs by
\({M}=\left[s_1, s_2,\ldots ,s_n\right]^{\mathrm {T}}\left[f_1,f_2,\ldots ,f_n\right],\) 
