The advent of social networks has brought about a plethora of opportunities for everyone to share information online in the forms of text, image, video and so forth. As a result, there is a vast amount of raw data on the Net which could be helpful in dealing with many challenges in natural language processing and image recognition. Matching pictures with their textual descriptions is one of these challenges in which the research interest has been growing(Wang and Chan, 2018; Eisenschtat and Wolf, 2017; Faghri et al., 2017; Lee et al., 2018).
The goal in image-text matching is, given an image, to automatically retrieve a natural language description of this image. In addition, given a caption (textual image description), we want to match it with the most related image found in our dataset as shown in Fig. 1. The process involves modeling the relationship between images and texts or captions used to describe them. This defines the semantics of a language by grounding it to the visual world.
Many studies have explored the task of cross-modal retrieval on the level of sentence and image regions (Wang and Chan, 2018; Niu et al., 2017; Karpathy and Fei-Fei, 2015; Liu et al., 2017). Karpathy et al. (2014) work on matching parts of an image objects with phrases by using dependency tree relations for sentence fragments and finding a common space for representing fragments. Huang et al. (2017) propose a sm-LSTM where they utilize a multimodal context-modulated global attention scheme and LSTM to predict the salient instance pairs. Recently, many researchers (Huang et al., 2018; Yan and Mikolajczyk, 2015; Zheng et al., 2017; Donahue et al., 2015; Lev et al., 2016; Mao et al., 2014; Gu et al., 2018)
introduced a neural network model for image caption retrieval consists of RNNs, CNNs, and additional multimodal layers. Practically, one of the reasons that these deep learning approaches have been on the rise is the availability of abundant information on the Web. The next section describes the proposed model.
In this work, we introduce an end-to-end multimodal neural network for learning image and text representations simultaneously. The architecture is illustrated in Fig. 2. It consists of two main subnets, a CNN for input image representation with an embedding and an LSTM to map the captions into the new space. The purpose of the model is to find a mapping from the text and image to a common space in order to represent them with similar embeddings. In this space, an image (text) will have a similar representation to its text (image) but a different one from other texts (images). Once the model is trained, by feeding an image (text) to the network, we find the most similar text (image).
2.1 Image representation
For our initial model, after removing the fully-connected layer from ResNet-50 (Xie et al., 2017)
which has been pre-trained on ImageNet(Russakovsky et al., 2015), we treat the remaining layers as an image feature extractor. The inputs of the network are images and the output is a
feature vector. Therefore, a dense layer with the size of text domain is added to the end of the network. With the rest of the network, this layer which is now part of the model, is trained to produce image representations. If we call this vector, which is a representation of the input image, then is a visual descriptor that is the result of forward pass in the network. The forward pass is denoted by , which is a non-linear function and is defined as . Conventionally, the image model is considered as one part of our network with its pre-trained weights to avoid computing a large number of learnable parameters which is a time-consuming process. Then, we add two fully-connected layers to transform to an image feature vector () computed by = + .
2.2 Text representation
Each input text () is first represented by an matrix, with being its length and being the size of the dictionary. To build the dictionary, stop words and punctuation marks are removed and all the words are stemmed using porter stemmer. In addition, the removal of the special characters is carried out and the remaining words are all in lowercase format. Each word in the final dictionary is represented by a one-hot dimensional vector and every word can ﬁnd an index l in the dictionary. Therefore, for an input sentence with words, there is a matrix as the following:
where and .
Based on this definition, each text should have a fixed length. In this study, since two datasets with various distributions are employed, the length of each sentence is considered a fixed number. In order to meet this criterion, when there are several sentences for one image, we concatenate all the words and build a long description for that image. When the length grows to be more than the expected length, the extra words are removed and when there are fewer words, zero-padding is applied. Therefore, we will have adimension space for the representation of the sentences.
The input of the text representation model is a sequence of integer numbers. In the next step, a word embedding is used to reduce the number of semantically similar words or to remove the words with low frequency, which are non-existent in the dictionary, resulting in a new embedding space. Since the vocabulary size is very large, the reduction is helpful in increasing the network’s generalizability. The new embeddings are then fed into an LSTM (Gers et al., 2000)
to learn a probability distribution over the above-mentioned sequence in order to predict the next word. The output of the LSTM is not used for word-level labeling. Instead, for the representation of the whole text, only the last hidden state is utilized. Therefore, for the input sentence T, its text descriptor denoted byand using the function , is computed as . The final word feature vector () is defined by .
|Task||Sentence Retrieval||Image Retrieval|
|Method||R@1||R@5||R@10||Med r||R@1||R@5||R@10||Med r||1K test images|
|GMM-FV (2015)||17.3||39.0||50.2||10||10.8||28.3||40.1||17||5K test images|
2.3 Alignment Objective
Having an aligned collection of image-text pairs, the goal is to learn the image-text similarity score denoted by which is defined as follows:
where and are the same-size image and text representations which have been projected onto a partial order visual-semantic embedding space. The penalty paid for every true pair of points that disagree is .
To compute the training loss, the image and text output vectors have been forced to be in the . By merging the image and text embedded models as illustrated in Fig. 2
, we achieve the desired visual-semantic model. To learn an order encoding function, we considered a hinge-based triplet loss function which encourages positive examples to have zero penalty, and negative examples to have penalty greater than a margin:
where , the similarity score function, is as described above while and are inferred from the ground truth by matching contrastive images with each caption and the reverse.
is discrete variance written as. For computational efficiency, rather than summing over all the negative samples, we assumed only the negatives in a mini-batch.
The proposed method has been implemented with the TensorFlow(Abadi et al., 2016), and Python ran on a machine with GeForce GTX 1080 Ti. For initialization, the GloVe (Pennington et al., 2014) word embeddings, trained on Twitter with 1.2 million vocabulary size, 27 billion tokens and 2 billion tweets, are employed. The training phase starts with an Adam optimizer with learning rate of 0.1 and a batch size of 16 and continues as long as the amount of loss does not change. When it happens, the learning rate is divided by 2. This continues until the learning rate becomes . Then, the batch size is doubled and the learning rate is reset to 0.1. We repeat this process to optimize the model. During the training, a grid search over all the hyper-parameters is carried out in order to conduct a model selection. For efficiency, the training is performed in batches which allows us to do real-time data augmentation on images in CPU in parallel with training the model in GPU.
Given a sentence (image), all the images (captions) of the test set are retrieved and listed based on their penalty in an increasing order. Then we report the results using Recall and Median Rank. Recall is a metric for assessing how well a system retrieves information to a query. It is computed by dividing the number of relevant retrieved results by the total number of instances. In , the top results are treated as the output and the Recall is computed accordingly. Med is the middle number in a sorted sequence of the retrieved instances.
To address this issue, other metrics can be taken into account since the existing measures can be intrinsically problematic (Bernardi et al., 2016). For instance, the retrieval of the exact image (text) is not guaranteed. In these cases, since the exact matches have not been retrieved, its score is considered although similar ones have been matched.
3.3 Data Collection and Results
Several datasets have been published for image-sentence retrieval task (Rashtchian et al., 2010; Ordonez et al., 2011; Young et al., 2014; Hu et al., 2017; Farhadi et al., 2010). We collect a dataset, as a proof of concept, for evaluating and analyzing our method to better showcase its ability to generalize as well as for demonstrating the extensibility of this type of solution to conversational texts and unusual images. Moreover, we used MS-COCO (Lin et al., 2014) to train and test the proposed model. This dataset contains 123,287 images and 616,767 descriptions (Lin et al., 2014). Each image contains 5 textual descriptions on average which collected by crowdsourcing on AMT. The average caption length is 8.7 words after rare word removal. We follow the protocol in (Karpathy et al., 2014) and use 5000 images for both validation and testing, and also report results on a subset of 1000 testing images in Table 1.
We collected 13751 tweets with 14415 images by a crawler based on the Twitter API. To make sure that the collection is diverse, we first created a list of seed users. Then, the followers of the seed accounts were added to the list. Next, the latest tweets of the users in our list were extracted and saved in the dataset. To make the data appropriate for our task, we removed retweets, the tweets with no images, non-English tweets and the ones that had less than three words. This led the dataset to have a relatively long description for each image and at least one image for every tweet. At the final step, the dataset was examined by two professionals and unrelated content was removed by them. Fig. 1 shows samples of the extracted dataset. This collection is different from currently existing ones due to varied domains, informal texts and high level correlation between text and image. For instance, the tweets may contain abbreviations, initialisms, hashtags or URLs. On collected tweets, our model improves sentence retrieval by 14.3% relatively and image retrieval by 16.4% relatively based on . The dataset has been available.111Dataset, source codes and model will be publicly available after publishing the paper.
We propose a multi-modal image-text matching model using a convolutional neural network and a long short-term memory along with fully-connected layers. They are employed to map image and text inputs into a shared feature space, where their representations can be compared, to find the closest pairs. Additionally, a new dataset of images and tweets extracted from Twitter is introduced, with the aim of having a characteristically different collection from the benchmarks. Whereas the descriptions in the benchmarks are well-organized, our dataset has not been standardized and the image-text pairs can contain high semantic correlations. Also, because of a varied number of domains existent in the extracted dataset, the task of image-text matching becomes even more challenging. Therefore, it can be used to carry out new research and assess the robustness of the proposed frameworks. Our experiments on MS-COCO yield improved results over some previously proposed architectures.
Tensorflow: a system for large-scale machine learning. In 12th Symposium on Operating Systems Design and Implementation, pp. 265–283. Cited by: §3.1.
Automatic description generation from images: a survey of models, datasets, and evaluation measures.
Journal of Artificial Intelligence Research55, pp. 409–442. Cited by: §3.2.
- Long-term recurrent convolutional networks for visual recognition and description. In , pp. 2625–2634. Cited by: §1.
- Linking image and text with 2-way nets. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 4601–4611. Cited by: §1, Table 1.
- Vse++: improving visual-semantic embeddings with hard negatives. arXiv preprint arXiv:1707.05612. Cited by: §1, Table 1.
- Every picture tells a story: generating sentences from images. In European conference on computer vision, pp. 15–29. Cited by: §3.3.
- Learning to forget: continual prediction with lstm. Neural Comput. 12 (10), pp. 2451–2471. External Links: Cited by: §2.2.
- Look, imagine and match: improving textual-visual cross-modal retrieval with generative models. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 7181–7189. Cited by: §1.
- Twitter100k: a real-world dataset for weakly supervised cross-media retrieval. IEEE Transactions on Multimedia 20 (4), pp. 927–938. Cited by: §3.3.
- Instance-aware image and sentence matching with selective multimodal lstm. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 2310–2318. Cited by: §1, Table 1.
- Learning semantic concepts and order for image and sentence matching. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 6163–6171. Cited by: §1.
- Deep visual-semantic alignments for generating image descriptions. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 3128–3137. Cited by: §1, Table 1.
- Deep fragment embeddings for bidirectional image sentence mapping. In Advances in neural information processing systems, pp. 1889–1897. Cited by: §1, §3.3.
- Skip-thought vectors. In Advances in neural information processing systems, pp. 3294–3302. Cited by: Table 1.
- Associating neural word embeddings with deep image representations using fisher vectors. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 4437–4446. Cited by: Table 1.
- Stacked cross attention for image-text matching. In Proceedings of the European Conference on Computer Vision (ECCV), pp. 201–216. Cited by: §1, Table 1.
- Rnn fisher vectors for action recognition and image annotation. In European Conference on Computer Vision, pp. 833–850. Cited by: §1.
- Microsoft coco: common objects in context. In European conference on computer vision, pp. 740–755. Cited by: §3.3.
- Leveraging visual question answering for image-caption ranking. In European Conference on Computer Vision, pp. 261–277. Cited by: Table 1.
- Learning a recurrent residual fusion network for multimodal matching. In Proceedings of the IEEE International Conference on Computer Vision, pp. 4107–4116. Cited by: §1, Table 1.
- Multimodal convolutional neural networks for matching image and sentence. In Proceedings of the IEEE international conference on computer vision, pp. 2623–2631. Cited by: Table 1.
Deep captioning with multimodal recurrent neural networks (m-rnn). arXiv preprint arXiv:1412.6632. Cited by: §1, Table 1.
- Hierarchical multimodal lstm for dense visual-semantic embedding. In Proceedings of the IEEE International Conference on Computer Vision, pp. 1881–1889. Cited by: §1, Table 1.
- Im2text: describing images using 1 million captioned photographs. In Advances in neural information processing systems, pp. 1143–1151. Cited by: §3.3.
- Glove: global vectors for word representation. In Proceedings of the 2014 conference on empirical methods in natural language processing (EMNLP), pp. 1532–1543. Cited by: §3.1.
- Collecting image annotations using amazon’s mechanical turk. In Proceedings of the NAACL HLT 2010 Workshop on Creating Speech and Language Data with Amazon’s Mechanical Turk, pp. 139–147. Cited by: §3.3.
- Imagenet large scale visual recognition challenge. International journal of computer vision 115 (3), pp. 211–252. Cited by: §2.1.
- Learning deep structure-preserving image-text embeddings. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 5005–5013. Cited by: Table 1.
- CNN+ cnn: convolutional decoders for image captioning. arXiv preprint arXiv:1805.09019. Cited by: §1, §1.
- Aggregated residual transformations for deep neural networks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 1492–1500. Cited by: §2.1.
- Deep correlation for matching images and text. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 3441–3450. Cited by: §1.
- From image descriptions to visual denotations: new similarity metrics for semantic inference over event descriptions. Transactions of the Association for Computational Linguistics 2, pp. 67–78. Cited by: §3.3.
- Dual-path convolutional image-text embedding with instance loss. arXiv preprint arXiv:1711.05535. Cited by: §1.