Text-Adaptive Multiple Visual Prototype Matching for Video-Text Retrieval
Abstract
Cross-modal retrieval between videos and texts has gained increasing research interest due to the rapid emergence of videos on the web.
Generally, a video contains rich instance and event information and the query text only describes a part of the information.
Thus, a video can correspond to multiple different text descriptions and queries.
We call this phenomenon the “Video-Text Correspondence Ambiguity” problem.
Current techniques mostly concentrate on mining local or multi-level alignment between contents of a video and text ( e.g. , object to entity and action to verb).
It is difficult for these methods to alleviate the video-text correspondence ambiguity by describing a video using only one single feature, which is required to be matched with multiple different text features at the same time.
To address this problem, we propose a Text-Adaptive Multiple Visual Prototype Matching model, which automatically captures multiple prototypes to describe a video by adaptive aggregation of video token features.
Given a query text, the similarity is determined by the most similar prototype to find correspondence in the video, which is termed text-adaptive matching.
To learn diverse prototypes for representing the rich information in videos, we propose a variance loss to encourage different prototypes to attend to different contents of the video.
Our method outperforms the state-of-the-art methods on four public video retrieval datasets.
Introduction
Cross-modal retrieval has gained popularity as a means of matching semantically similar samples across multiple modalities [1, 2, 3, 4].
With the rapid increase in the number of videos, Text-Video
Retrieval (TVR) has garnered a lot of interest.
Given a text description/video, we aim to retrieve the corresponding video/text description in the gallery.
TVR remains a challenging task since the video and text have different semantical descriptions which results in modality gap.
To overcome the modality gap issue, most existing methods generally follow a dual encoding network paradigm which encodes video and text through a visual encoder and a language encoder into the same embedding space, respectively [1, 2, 3, 5, 6].
And then they focus on learning a similarity function between the representations of text and video, which provides the basis for ranking the gallery video/text.
However, the modality gap issue is still not well solved due to the misalignment.
Motivation [Figure] Some methods aim to extract additional information from the video to get more fine-grained video features to be aligned with corresponding text features [5, 7, 8].
They focus on properly combining different video modalities, such as appearance, audio, speech, etc.
Some methods pay attention to multi-level alignment, including text entity to video object, text verb to video action, and text phrase to video event [6, 9].
However, most of them ignore the fact that a video contains rich instance and event information, while the query text only describes a part of the information, which leads to video-text correspondence ambiguity problem.
Concretely, as shown in Figure 1, due to the multiple characters in the video, the video has different text descriptions: “a woman does something”, “a man does something” or “a group does something”.
The text descriptions are very diverse and scattered in the feature space.
With diverse video contents , it is infeasible to align a single video feature with the diverse text features.
Neither additional information-based methods nor multi-level alignment-based methods consider such correspondence ambiguity since both of them match a single video feature with multiple text features.
In this work, we focus on video-text retrieval problem and aim to mine fine-grained and diverse event descriptions in a video and adaptively match them with multiple text descriptions to mitigate correspondence ambiguity issue for better alignment.
Specifically, we automatically capture multiple prototypes for each video to account for its rich instance and event information by aggregating on token features.
Based on multiple prototypes of a video, we aim at finding many-to-many correspondence between prototypes and text representations to reduce ambiguity.
To this end, we propose a Text-Adaptive Multiple Visual Prototype Matching Model.
We follow the dual encoding network paradigm as previous methods [3].
First, we input video into visual encoder to get the video token features.
Then we employ a token-adaptive aggregation method to generate several visual prototypes from the final video token features.
As shown in Figure 2, one prototype is the class token and the others are the linear combinations of all the token features.
The text feature encoded by the language encoder is matched with the most similar video prototype.
This text-adaptive matching can help find text-to-prototype correspondence in video and alleviate the correspondence ambiguity.
To further force the prototypes to represent rich information in the video, we propose a variance loss to enhance the diversity of prototypes to attend to different contents of the video.
Extensive experiments were conducted on the MSR-VTT [10], DIDEMO [11], MSVD [12], and
LSMDC [13] to evaluate video-text bi-directional retrieval performance.
Experimental results show that our proposed model can achieve state-of-the-art results on all the above datasets.
Ablation studies were carried out to evaluate the effectiveness of each single part of our model.
The main contributions of our work are three folds.
We propose to automatically generate multiple prototypes for video to account for its rich information and introduce a text-adaptive matching strategy to adaptively find correspondence between texts and prototypes.
We further design a variance loss to effectively encode diverse information into prototypes to attend to different contents in the video and boost alignment.
Our proposed model can achieve new state-of-the-art results on four benchmark datasets.
Extensive experiments demonstrate its effectiveness and generalization.
Related Work
Text-Video Retrieval.
The methods for text-video retrieval can be classified into three categories: pre-extracted feature based [8, 7, 6, 14, 15, 16], end-to-end training [3, 2] and adaptive matching methods.
Given the small size of most video-text retrieval datasets, the dominant paradigm for video retrieval has been to combine pre-extracted features from “expert” models, such as models trained for a variety of tasks and on multiple modalities such as face, scene, and object recognition, action classification, and sound classification.
CE [8] and MMT [5] compute the overall similarity for a video-text pair obtained as a weighted sum of each expert’s similarity with the text.
DMM [7] uses hierarchical video-text alignment to explore the diverse properties in multi-modal cues for finegrained alignment.
Another important paradigm is to first train on a large-scale vision-and-language dataset and then finetune on downstream dataset.
ClipBERT [2] proposes an efficient end-to-end technique based on sparse sampling and demonstrates that the pretrained model by image-language dataset enables superior video-text retrieval initialization.
Frozen [3] proposes an end-to-end trainable model that can benefit from large-scale image and video captioning datasets.
Some works focus on the matching of different modalities.
PCME [4] represents the samples from different modalities as probabilistic distributions in the common embedding space to capture one-to-many correspondences.
SSVR [17] highlights the issue of one-to-one assumption in evaluation of video retrieval methods and proposes a new evaluation metric to address this. MQVR [18] tackles the issue of imperfect annotations in existing video retrieval datasets by focusing on the less-studied setting of multi-query video retrieval.
Most of them, however, ignore the fact that a video contains rich instance and event information, whereas the query text only describes a portion of the information, resulting in video-text correspondence ambiguity.
We propose a Text-Adaptive Multiple Visual Prototype Matching Model to help mitigate this issue.
Vision Transformer.
Now vision transformer becomes the visual basic backbone in most of the state-of-the-are methods for vision-language tasks [19, 2, 3, 1].
BLIP [1] makes effective use of noisy web data by bootstrapping captions, in which a captioner generates synthetic captions and a filter removes the noisy ones.
The work of Frozen [1] makes a minor modification to the Divided Space-Time attention introduced by [20].
Our model is based on the dual framework of Frozen.
Our Method
A video, in general, contains a lot of rich instance and event information, and the text description only describes a portion of it.
A video can have many characters/events/actions, whereas a text typically only describes one character, action, or event.
So mining representation of multiple essential events facilitates the text-video matching by reducing the modality gap properly.
As a result, a model that generates multiple visual prototypes is better than that generates one feature.
With this rationale in mind , we propose our Text-Adaptive Multiple Visual Prototype Matching Model.
To generate several visual prototypes from video, we use a token-adaptive aggregation method on the final video token features.
Given a query text, the most similar prototype is used to find correspondence in the video, a process called as text-adaptive matching.
We also propose a variance loss to encourage different prototypes to attend to different contents of the video in order to learn diverse prototypes for representing the rich information in videos.
We define the problem in Section 3.1, present
Text-Adaptive Multiple Visual Prototype Matching Model in Section 3.2, describe our variance loss in Section 3.3, and explain our dual encoder in Section 3.4.
3.1 Problem Definition
For the video-text retrieval task, we are given M videos V =
{ V i } M − 1 i =0 and N text descriptions
T =
{ T i } N − 1 i =0 .
The goal of this task is to learn a similarity function S :
( T, V )
→ R .
It should maximize positive cross-modal sample similarity while minimizing negative cross-modal sample similarity.
In general, we fed video and text to into an vision encoder and language encoder to get normalized feature f v , f v .
Then the similarity function S is defined by
[Equation]
The similarity of text-video is calculated as the inner production of f v , f t .
[Figure]
⨂ ⨂ ⨂ ⨂ 0. MAX 0. TextProj VideoProj
Similarity ! [Figure] [Figure] 3.2 Text-Adaptive Multiple Visual Prototype Matching Model
The similarity function of Equation 1 ignores the Video-Text Correspondence Ambiguity problem: some videos have multiple different text descriptions and queries.
To furthermore illustrate this problem, we show the text descriptions diversity of videos by showing the inter-text similarity and the minimum of intra-similarity distribution in 3.
We define inter-text similarity as the similarity of different text descriptions for different videos, intra-text similarity as the similarity of different text descriptions for same video.
The less the minimum of intra-text similarity, the diversity of the text descriptions for a video.
As shown in Figure 3, at least one-third of the minimum of intra-text similarity is less than the mean of inter-text similarity on features from both models.
It demonstrates that many videos have diverse captions and contents.
So a single feature in some videos cannot be aligned with multiple text features at the same time.
As a result, using multiple visual prototypes to align with different text is critical.
An intuitive idea for producing multiple visual prototypes is to generate a feature for each frame/clip of video as a prototype.
However, one frame/clip can contain multiple characters and events at the same time.
So a better way is to generate many potential prototypes for each frame, then we aggregate them together into multiple visual prototypes.
Vision Transformer [3, 2] have shown it’s effectiveness on learning multi-modality shared representation.
So we take the final layer token features z ∈ R B × D of vision transformer as the potential prototypes.
B, D represents the number of tokens, the dimension of token feature.
There are many methods to aggregate the token features to produce multiple visual prototypes, such as transformer decoder, graph neural network, LSTM etc.
However, we find that the mask-based production of the prototypes is good enough.
The k th prototype
[Equation]
where z j , f mask represents the jth token feature of z , mask-generating function.
f mask is implemented by a linear layer, followed by relu function.
In general, the class token feature is regarded as the final output of vision transformer [3, 2].
So we expand p
k
+
=
z cls , which means we have
K + 1 visual prototypes.
For comparing visual prototypes and text feature on same embedding space, we input p to a projection linear layer, do normalization and get multiple vision features f ve ∈ R ( K +1)
× D .
Matching text to video becomes a matter of matching one text feature to multiple visual prototypes.
The text is aligned with the video if one of the prototypes is very close to it.
Based on this text-adaptive matching, we have new similarity function as
[Equation]
[Figure]
3.3 Variance Loss
Define mask m ji,k = f mask ( z j ) i,k , which represents the mask weight on j th token from k th prototype of i th sample .
It’s an intuitive idea to different prototypes of same video to attend to different contents and the masks have different attention on different tokens.
However, as shown in Figure 3,in some videos, the text descriptions are very similar.
The videos may be too short and only have a character, event or action.
The prototypes and masks are similar .
Instead, we’d like all masks of all videos to pay attention to different token positions.
Inspired by the variance loss on feature of [21], we design the variance loss on mask as
[Equation]
where D ( · , · ) is the regularized standard deviation defined by
[Equation]
5) where γ is a constant target value for standard deviation; ϵ is a small scalar to prevent numerical instabilities.
The variance loss forces the variance of all prototype mask values for each token to be large.
It also encourages diverse prototypes for representing the rich information in videos.
3.4 The Dual-Encoder Framework
We use a end-to-end training dual-encoder framework.
Frozen [3], a basic and successful dual-encoder architecture (separate visual encoder and text encoder), serves as our foundation in this study.
It’s designed for video-language pretraining to match raw-pixel video and raw text with a contrastive loss in dual-encoder framework.
The language and vision encoder is multi-layer bidirectional transformer and Timesformer [20] with some changes.
To train this dual-encoder framework, the matched text-video pairings in the batch are regarded as positive, while all other pairwise combinations in the batch are deemed negative.
Each video appears at most once in each batch to prevent duplicates.
With L text-video pairs in a batch, the symmetrical contrastive loss is calculated as follows
[Equation]
where τ is the temperature and s ii , s ij is the similarity of i th paired text-video, i th text to j th video.
Then the ranking of videos/texts is determined by this similarity calculation for single text/video query.
So overall loss is defined by
[Equation]
[Table]
[Table]
where α controls the weight of L var .
Experiment
We evaluate our model’s performance on several public datasets.
In the sections that follow, we first introduce the datasets and metrics for comparing results, as well as implementation details.
Then we demonstrating the overall performance of our model on the datasets.
Finally, we present ablation studies to evaluate the effectiveness of each component of our model.
4.1 Datasets and Metrics MSR-VTT
MSR-VTT [10] contains 10K YouTube videos, each of which is accompanied by 20 natural sentences that describe the video content.
Following [3], we train on 9K train+val videos and report results on the 1K-A test set.
MSVD
MSVD [12] consists of 80K English descriptions for 1,970 videos from YouTube, with each video containing 40 sentences each.
Following [3], we use the standard split of 1200, 100, and 670 videos for training, validation, and testing.
[Table] [Table]
DIDEMO [11] contains 10K Flickr videos annotated with 40K sentences.
Following [3], we evaluate paragraph- to-video retrieval, where all sentence descriptions for a video are concatenated into a single query.
LSMDC
LSMDC [13] consists of 118,081 video clips sourced from 202 movies.
The validation set contains 7,408 clips and evaluation is done on a test set of 1,000 videos from movies disjoint from the train and val sets.
This follows the protocol outlined in [33].
Metrics
We evaluate retrieval performance using common information retrieval metrics such as Recall at K (R@K and K=1, 5, 10) and Median Rank (MedR).
R@K is the proportion of test queries for which at least one relevant item is found among the top-K retrieved results.
The MedR calculates the median rank of correct items in the returned ranking list, with a lower score indicating a better model.
To reflect overall retrieval performance, we also take the sum of all R@K as SumR.
4.2 Implementation Details
We fintune the pretrained model from Frozen [3] on text-video retrieval dataset.
The visual encoder have 12 attention blocks, patch size P = 16 , sequence dimension D = 768 , and 12 heads.
The text encoder takes the architecture of DistilBERT base-uncased [39].
The dimensionality of the common text-video space is set to 256.
We take some training settings same with Frozen [3]: we use 8 frames per video when training model;
The temperature hyperparameter σ for the loss defined in
Equation (6) is set to 0.05; We randomly crop and horizontally flip during training and center crop the maximal square crop at test time for visual augmentation; All videos are resized to 224 × 224 as input;
We use text augmentation during training for paragraph-retrieval settings, randomly sampling and concatenating a variable number of corresponding captions per video;The optimizer is Adam.
We use a different learning rate scheduler: warmup for 5 epochs with a linearly growing learning rate from 0.0 to 0.00003, then use cosine decay scheduler to guide the learning rate from 0.00003 to 0.0 for other 45 epochs.
The batch size is set as 64.
The number of extra prototypes besides class token K is set as 3 .
The variance loss parameter γ, ϵ are set as 0.75, 1 e − 4 .
Variance loss weight α is set as 5.0.
4.3 Comparison to the State of the Art
Tables 1, 2, 3, 4 present the retrieval results of HiT on MSR-VTT, LSMDC, DIDEMO and MSVD.
We also compare TMVM with other state-of-the-art methods: improving the robustness of pretrained model [23, 14, 24, 25, 26]; designing better architecture or loss [27, 28, 29, 9, 30, 6, 34, 35, 31] on pre-extracted features; focusing on mining information of different visual modalities [5, 7, 32]; end-to-end trainable model [2, 3].
As demonstrated by the results, TMVM outperforms all comparison methods clearly.
We present video-to-text and text-to-video retrieval results for MSR-VTT and LSMDC.
For MSR-VTT, our retrieval performance at SumR, in particular, is 348.4, outperforming recent state-of-the-art methods [7] by a margin of 10.2.
For LSMDC, our retrieval performance at SumR also outperforms other methods by a clear margin.
It accurately reflects TMVM’s overall retrieval quality.
We report retrieval performance in terms of text-to-video retrieval for DIDEMO and MSVD.
TVMM continues to outperform comparison methods.
Our method doesn’t outperform R@10 of some other methods [Table] in Tables [Table]
It is possibly because the methods use multi modality information of video, such as speech, audio and appearance.
Our method is based on Frozen [3] and only uses the frames.
4.4 Ablation Study
We discover that the proposed components, such as Multiple Visual Prototypes and Variance Loss, help to improve retrieval performance.
We exhaustively and comprehensively ablate two components to demonstrate their effectiveness and robustness.
Production of Multiple Visual Prototypes.
As mentioned above, we use mask-based method to aggregate token features from the final layer.
In this section, we design two other variants to study whether this production is good enough.
• TVMM-Part.
We divide the token features into several parts according to the frame order.
The part’s feature centers are then treated as prototypes.
• TVMM-Decoder.
We use several embeddings as queries, and the token features as memory, then we throw query and memory into two-layer decoder to process the queries as visual prototypes.
Baseline is Frozen[3] with our training parameters.
TVMM-Mask is our method which is introduced in Section 2.
As shown in Table 5 ,TVMM-Mask outperforms TVMM-Part and TVMM-Decoder with a clear margin.
TVMM-Part improved little compared with the baseline, only 1.3 on SumR. It shows that TVMM-Part is very limited in its ability to model multiple prototypes.
The Number of Visual Prototypes.
As shown in Table 5, multiple prototypes is better than single prototype.
With K = 3 and its variance loss, TVMM-Mask outperforms the baseline with 5.3 on
RSum.
This reflects a video can contain rich instance and event information and the positive text only describes a part of it.
TVMM finds correspondence in the video with the help of multiple visual prototypes matching.
The choice of number of prototypes is critical.
K=3 is the best among 1,2,3, and 1569.
When K is greater than or equal to 3, as K gets larger, the performance continues to degrade.
A appropriate number of prototypes can assist the model in learning representative prototypes.
When there are too many prototypes, the learned prototypes become noise rather than representative.
The Number of Input Visual Frames.
In end-to-end training framework, the number of video frames is a parameter that has a big impact on performance.
As shown in Table 6, as the number of video frames increases, so does the performance.
It’s worth noting that even on single-frame input, our method also improves the baseline with 4.0 on SumR. It proves the importance of multiple prototype matching.
Some Retrieval Examples.
Each test video in the original MSR-VTT split has only one text description.
In this experiment, we take some samples from the training data set and add them to the test set to demonstrate the superiority of the method.
When compared to the baseline, our method
[Table] a car driving down a road goes from black and white video to colored video [Table] provides correct retrieval results for the two test text queries, as shown in Figure 4.
It is because our
TVMM model can alleviate the ambiguity problem in video-text correspondence.
Visualization of Multi Prototypes.
We choose a video and its three captions from MSR-VTT.
The captions are matched with the most similar prototype.
The heatmaps based on the mask values on the four sampled frames are then plotted to visualize the prototypes. The four frames show a serious man, a sad woman, a serious woman, and a pair conversing.
As you see in Figure 5, the three captions correspond well with the prototypes, which attend to different contents of the video.
[Figure]
Conclusion
In this paper we have proposed a Text-Adaptive Multiple Visual Prototype Matching Model.
It generates multiple prototypes for video automatically to account for its rich information, and we present a text-adaptive matching strategy to find correspondence between texts and videos.
Then, we propose a variance loss to encourage different prototypes to pay attention to different video contents.
Experimental results on four public video retrieval datasets demonstrate the advantages of our model.
Ablation studies are also carried out to verify the effectiveness of each part of our model.
Acknowledgement
This work was supported by the National Science Foundation for Young Scientists of China (62106288).
And it was in part supported by Foshan HKUST Projects (FSUST21-FYTRI01A,
FSUST21-FYTRI02A).
C. Shen’s participation was in part supported by a major grant from Zhejiang
Provincial Government