Language-Driven Region Pointer Advancement for Controllable Image Captioning (2020)

Abstract: Controllable Image Captioning is a recent sub-field in the multi-modal task of Image Captioning wherein constraints are placed on which regions in an image should be described in the generated natural language caption. This puts a stronger focus on producing more detailed descriptions, and opens the door for more end-user control over results. A vital component of the Controllable Image Captioning architecture is the mechanism that decides the timing of attending to each region through the advancement of a region pointer. In this paper, we propose a novel method for predicting the timing of region pointer advancement by treating the advancement step as a natural part of the language structure via a NEXT-token, motivated by a strong correlation to the sentence structure in the training data. We find that our timing agrees with the ground-truth timing in the Flickr30k Entities test data with a precision of 86.55% and a recall of 97.92%. Our model implementing this technique improves the state-of-the-art on standard captioning metrics while additionally demonstrating a considerably larger effective vocabulary size.

## introduction image captioning brings together the two fields of computer vision and natural language generation into a task where the model needs to translate an input image into an appropriate natural language text description. the task leaves some ambiguity regarding which parts of the image should be mentioned and which ones can be excluded. this has led to a common problem where models tend to generate overly generic descriptions that seem to focus more on the category of the image than on its individual content @xcite . recently, @xcite introduced controllable image captioning as a new sub-task of image captioning with a stronger focus on image details. in this task, the input to the model is an image along with bounding box coordinates for a sequence of regions (where each region can consist of one or more bounding boxes) that must be explicitly described in the candidate caption. thus, in contrast to standard image captioning, a generic candidate caption would not meet the criteria of a suitable caption even if it contained no factual errors; this is reflected in the evaluation process where the candidate caption is only compared to those ground-captions that share the same sequence of regions. fig. 1 shows an image and two corresponding captions from the flickr30k dataset @xcite along with complementary data from flickr30k entities @xcite which provides annotations that link entities in the captions to region bounding boxes in the corresponding image. in terms of practical use, a controllable image captioning model provides more flexibility and usercontrol over the generated captions, without having to retrain the model. since the region selection process is not entangled with the caption generation components, the former can be swapped out to adapt to different scenarios (e.g. when applied to social media images, it could target regions where a facial recognition system has tagged friends of the user). furthermore, it opens up the possibility of adhering to individual user preferences regarding the amount and type of details to describe -this is a feature that could provide real benefits to blind and low-vision users @xcite . @xcite with regions and text annotations from flickr30k entities @xcite . square brackets indicate entity annotations. some entity regions consist of multiple bounding boxes. when it comes to model architecture, a key component in controllable image captioning is the mechanism that advances the region pointer at the appropriate time so that each requested region is sufficiently described. in previous work, this has been approached as its own prediction task in parallel to the prediction of the next word @xcite . however, in this paper, we demonstrate that the timing of the region pointer advancement is strongly linked to the sentence structure in the ground-truth and thus could likely be predicted as if it were a natural language token. hence, we propose a novel approach to the region pointer advancement mechanism that directly leverages the language model to generate a unique next-token as part of the caption generation process. we implement this in a controllable image captioning model where we demonstrate its effectiveness by measuring how often the next-token is predicted in agreement with the ground-truth. furthermore, we measure the model's overall performance on standard image captioning metrics where it outperforms the current state-of-the art on the flickr30k @xcite benchmark test. additionally, we observe that our model demonstrates a considerably larger effective vocabulary size than the current state of the art model, thus enabling our model to describe a greater variety of visual content. we make our code and trained model publicly available for future work to build on. foot_0 ## related work controllable image captioning builds directly on the standard image captioning task and thus involves a similar set of components, with the main difference being the role of visual attention. in the early neural models for image captioning, visual information was typically extracted into a fixed-size vector representation of the full image, which would be provided as input either at the start or at each recurrent timestep in the generation process (e.g. @xcite , @xcite ). these early neural models were found to produce largely generic captions with output similar to retrievalbased models @xcite . in recent years, dynamically generated attention has become the standard method to mitigate generic captions through enhanced visual grounding by providing the model with only the visual information relevant to the current timestep; multiple variations of dynamic attention have been explored, from the soft and hard attention proposed by @xcite to the region proposal network used by @xcite . in controllable image captioning, the locations of the regions of interest are included in the input to the model (as shown in fig. 1 ). to extract meaningful features from these regions, previous work in controllable image captioning has successfully used the region features from @xcite that were developed for the standard captioning task but whose object-focused training method corresponds well to the object-focused region annotations in the flickr30k entities dataset @xcite . since the selection and ordering of the regions is fixed, the challenge instead lies in predicting the appropriate timing of attending to each region. since the current task requires that the output incorporates exactly the requested regions, the model must ensure that each part of the generated caption is sufficiently grounded in its corresponding visual region and that the generated sequence of words is not terminated before the complete region sequence has been described. to predict the timing of attending to each region, @xcite implement a region pointer along with a mechanism to predict, at each timestep, whether this pointer should be incremented or not. the prediction follows a multi-step process that includes an additional lstm layer to model the attention state of the current caption chunk, extended with an additional output layer to model the end of this chunk, as well as a chunk-shifting gate module that outputs the probability of incrementing the region pointer, based on: the chunk's attention state, the chunk's end state and the visual features for each of the requested regions. a potential weakness in this implementation is the structure of connection between the word prediction lstm, the attention lstm and the sampling of the next word: the chunk-shifting gate (which comprises an earlier step in this module) must make its decision before the next word has been sampled. thus, it must predict whether the next word is going to be the last word of the chunk rather than predicting whether the current word is the end of the chunk. this complicates the task of the chunk-shifting gate which must rely on incomplete information about the chunk when predicting its end-point. furthermore, it would be difficult for the chunk-shifting gate to anticipate the result of any non-deterministic method for sampling the next word. in the following section, we argue that a more elegant solution for advancing the region pointer is not only possible but also preferable. ## region pointer advancement region pointer advancement training relies on separating full captions into chunks that each relate to a visual region. we use the same chunking method as @xcite on the flickr30k entities @xcite captions, meaning that each chunk starts with the word immediately following the end of the previous chunk, and ends with the last word in the following entity annotation that has at least one bounding box associated with it; entity annotations without bounding boxes are not taken into account. fig. 1 shows two example captions with entity annotations enclosed in brackets, where each entity annotation includes an entity id, an entity type and the noun phrase associated with that entity. after chunking, example a consists of three chunks: 1) a child, 2) walking and leaving a trail and 3) behind them. the visual region associated with each chunk refers to the average-pooled features of all bounding boxes associated with its entity. since the third chunk does not have an associated entity, we associate it with the empty (zero-vector) region during training. since the end of a chunk is related to the position of its entity's noun phrase, it seems reasonable to suspect that the end of a chunk is correlated to parts-of-speech (pos). we explore two potential correlations after employing automatic pos tagging on the training data, using the python implementation of the brill tagger @xcite found in the textblob foot_1 library. fig. 2a shows the frequency of each pos tag assigned to the last word of a chunk; unsurprisingly, the last word of a chunk is most commonly tagged as a noun. further, fig. 2b shows the positive predictive value (i.e. precision, which takes into account how often each pos tag appears in the training data) for indicating the end of a chunk among the top five most predictive pos tags. again, nouns are most commonly associated with ending a chunk, though their positive predictive value varies from 81.6% for plural nouns (nns) to 20.0% for singular proper nouns (nnp). from the statistics shown in fig. 2 , it is clear that the end of a chunk (and thus, the region pointer advancement timing) is correlated to the sentence structure. thus, we propose to inject a special language token (next) to mark the end-of-chunk events, treating it in a similar way to the beginning-of-sequence (bos) and end-of-sequence (eos) events. the two examples in fig. 1 thus become: (a) bos a child next walking and leaving a trail next behind them eos, and (b) bos a child next in a striped shirt next walks by some red chairs next eos. with the added next-tokens, our model no longer requires additional steps or learnable layers to predict the region advancement timing since this is treated as a natural language property and predicted by the language model (as any other word). unlike the method used by @xcite (described in section 2), our prediction mechanism has access to the most recently generated word regardless of sampling method. additionally, during the immediately following timestep, the next-token becomes the previous word, and thus our language model is explicitly informed that a new chunk should begin. to evaluate our proposed region pointer advancement method, we implement it as part of a controllable image captioning model (described in section 4) and test it on the region sequence scenario @xcite where each example's candidate caption is compared only to those ground-truth captions that share the same region sequence (i.e. the same regions in the same order). ## model architecture our architecture, shown in fig. 3 , is similar to a typical image captioning model based on the encoderdecoder design with visual attention. the recurrent unit is a two-layer long short-term memory (lstm) @xcite module with a hidden size of 1024 units (using the implementation details of @xcite ). the input i t at each timestep t is the weighted concatenation of the previous word embedding w t-1 and the current visual region's embedding v t , with the weight balance α t between them being generated according to equations 1-2: our word embeddings are randomly initialized learned vector representations of size 1024, while the visual embedding is a vector of size 2053. the first 2048 features are extracted from the final pooling layer (pool5) of a bottom-up network @xcite where the region's bounding box(es) are used as the region proposals; in the case where a region is made up of multiple bounding boxes, we average-pool their features into a single vector representation of size 2048. the last 5 features consist of: the count of bounding boxes that made up this region, as well as the bounding boxes' maximum and minimum x and y coordinates relative to the total image size. a full-image sized bounding box is used to extract the overall visual features of the image; these features are passed through two separate learnable linear layers to initialize the lstm's hidden and cell states respectively. (these initialization steps are not featured in fig. 3 .) after extracting the visual features from the bottom-up network and initializing the lstm's hidden state and cell state (as described above), the model recursively generates a caption word-by-word until the eos-token is produced. the process for a single step in this recursion is as follows: the lstm's previous hidden state is passed through a single linear layer with a sigmoid activation unit to produce the α t weight according to equation 1; this weight (and its complement) decides how much attention the model should pay to the text input and visual input respectively. the text input at each timestep is the learned word embedding for the previously generated token (or the bos-token for the first step), while the visual input consists of the features representing the region currently indicated by the region pointer. the region pointer initially points to the first region in the requested region sequence, and is subsequently incremented each time the next-token is produced by the model; if the next-token is generated when no further requested regions remain, the region pointer instead points to a zero-vector region (i.e. the empty region). once the text and visual parts of the input have been concatenated according to equation 2, the resulting full input is passed through the lstm module, followed by a single linear layer to produce the logits over the full training vocabulary from which the next word is sampled. this process continues until the eos-token is produced which marks the end of the caption. due to the discrete-valued region pointer, the model will only receive visual input from a single region at any one timestep. however, since the lstm's memory states are not reset between chunks, it is possible for the model to retain information about previous regions along with information about the word embeddings of previously generated words when transitioning from one chunk to the next within a single caption. during training, the previous token refers to the ground truth token of the previous step rather than the previously generated token. the special tokens next and eos are trained in the same way as the word tokens in the vocabulary; however, the region pointer advancement follows the ground-truth next-tokens only, and generating eos early will not prevent the model from training on the remaining part of the caption. ## experiments in our experiments, we use the karpathy splits @xcite of the flickr30k @xcite dataset, giving us 29,000 images for training, 1014 for validation and 1000 for the test set; each image is associated with 5 human-annotated captions. in controllable image captioning, a unique example is defined by an image along with a unique sequence of regions; thus, each image in the flickr30k dataset corresponds to between 1 and 5 unique examples in our experiments (at most 1 per caption if they all use different region sequences). thus, while the number of unique images remain the same, the number of examples in our splits become: 120,667 examples for training, 4208 for validation and 4148 for testing. we follow the standard procedure for pre-processing captions: all captions were lower-cased and stripped of punctuation, and we replace rare words (less than 5 occurrences in the training set) by an unk token in the training data; no words were replaced in the test set. the captions were then split into chunks based on the human-annotated entity annotations (as described in section 3), where each chunk ends with a visually grounded entity's associated noun phrase (or the last word of the caption respectively). during test time, each example consists of an image, a (possibly empty) sequence of regions and one or more ground-truth captions to measure success against. the bottom-up network @xcite used for the visual embeddings was trained on a custom split of the visual genome @xcite dataset (after standard pre-training on imagenet @xcite ) to avoid an overlap between the images in the bottom-up net's training set and the images from our model's test set. the weights of the bottom-up net were frozen and remained fixed during training while the word embedding features were learned end-to-end along with the rest of the model. we implement our model (described in section 4) using the pytorch foot_2 framework. we use a batch size of 100, a learning rate of 1e - foot_4 and a dropout of 0.7 for both the previous word embedding and the lstm's layer connections. 4 to prevent overfitting, the model was evaluated on the validation set every 10 epochs, and the checkpoint with the best cider @xcite metric was selected. during inference on the test set for the final results, the models were prevented from generating the unk token by setting its probability to zero. if the end-of-sequence (eos) token was generated before all regions had been used, it was instead interpreted as a next-token. if there were no more regions when a next-token was generated, the visual input was referred to the empty (zero-vector) region. all learned parameters were trained using the cross-entropy loss over the generated word sequence, to minimize the negative log probability of the ground-truth words from each caption, per equation 3: ## results and analysis to test our full model's ability to learn the appropriate timing of the region pointer advancement using our proposed method, we measure how often the next-token is predicted in agreement with the groundtruth from the test set when guiding the model with the correct previous word from the ground-truth data at each timestep (i.e. in the teacher-guided scenario). we find that our model generates the next-token in agreement with the ground-truth to a precision of 86.55% and a recall of 97.92%, thus establishing that our region pointer advancement method works well in practice and as such is likely to contribute to the successful training of our model. in the rest of our experiments, the ground-truth captions are not known during inference, and the previous word refers to the model's previously sampled word. to evaluate how our model performs on the controllable image captioning task, we measure the model's performance on the standard captioning metrics: bleu @xcite , rouge-l @xcite , meteor @xcite , cider @xcite and spice @xcite , using the implementation from the speaksee foot_5 tool. the first four of these are ngram based metrics, with cider being developed specifically for image captioning, while the other three have been borrowed from the machine translation and summarization fields. among this class of metrics, cider and meteor have been associated with the highest correlation to human evaluation scores on the standard image captioning task @xcite ; they provide a measure of both the fluency and content agreement of the generated captions in relation to the ground truth. like cider, spice was also developed as an image captioning metric, but instead measures the overlap between inferred scene graph tuples from the candidate and ground-truth captions, and is thus intended to measure the accuracy of the objects and their relations in the candidate captions. we compare our results to the show control and tell (sct) model from @xcite who introduced the controllable image captioning task. we compare to three versions of the sct model: sct (ce), sct (cider) and sct (cider nw). sct (ce) is trained with the standard cross-entropy loss, while the other two are first trained on the cross-entropy loss and then further finetuned using reinforcement learning. sct (cider) is finetuned towards the cider metric, while sct (cider nw) is finetuned on a combination of cider and a region alignment score (defined by equation 13 from @xcite ) based on word embedding similarity between nouns of corresponding caption chunks. all three sct models use beam sampling with a beam size of 5. we present the results from our model using argmax sampling and standard cross-entropy loss training and leave further finetuning up to individual applications. for our full model we report the mean across 6 runs along with 95% confidence intervals. while the standard captioning metrics provide us with a measure of the fluency and content overlap @xcite 92.06 98.07 502 11.4 with the ground-truth, they do not directly penalize a model's tendency towards repetitive captions @xcite . we expect a model with a well-functioning region pointer advancement timing to encourage more diverse and detailed captions due to better alignment with the visual input -in comparison, if the pointer advancement lags behind the language-driven transition to the next chunk, then it would be necessary for the language model to start generating the next chunk of words without access to the relevant visual input, possibly by relying more on word co-occurrence rates in the text. to test this, we employ three metrics proposed by @xcite : diversity (proportion of distinct candidate captions), novelty (proportion of candidate captions not found in the training set) and effective vocabulary size (total number of unique words across all candidate captions). from finally, from our ablation test we can tell that the average-pooled features combined with knowledge about the appropriate number of chunks is sufficient to produce acceptable results, despite using the same visual features at each timestep. however, while the average-pooled model performs acceptably, our full model is still clearly ahead on the standard captioning metrics. thus, the results indicate that our full model does indeed learn a region pointer advancement timing that is useful for learning to generate visually grounded language. a possible explanation for the relatively good results of the average-pooled ablation model could be that the average-pooled model learns to internally keep track of the current chunk number along with memorizing a typical sentence structure (e.g. by learning to describe people in the first chunk, followed by their attributes, and describing their activity in a later chunk). another possibility is that it learns a type of content planning similar to older encoder-decoder models without attention, with the nexttoken aiding in learning the sentence structure and with the additional benefit of having the empty region input indicating when to end the sequence. fig 4 shows the generated captions for three different region sequences on the same image. (more examples can be found in the appendix.) overall, we found that all models were capable of producing reasonable and detailed descriptions, but that the sct models seemed more likely to produce commonsense relationship errors (e.g. playing a crowd from the bottom example in fig 4 ). this difference can likely be explained as an effect of our model's region pointer advancement timing being strictly tied to the sentence structure, thus allowing it to attend to the next region before generating the words that tie the two regions together. in contrast, if the model was to delay its region pointer advancement with as little as a single timestep, it would need to start generating relationship words based solely on the first of the two regions with no knowledge of the second. ## conclusion and future work based on the strong correlation between sentence structure and region-related chunks in the training data's captions, we proposed a language-driven method of region pointer advancement in controllable image captioning. we have implemented our proposed method in a controllable image captioning model where it demonstrates a precision of 86.55% and a recall of 97.92%. our full model outperforms the current state of the art model on the standard metrics, including cider, despite using only the crossentropy loss whereas the current state-of-the-art relies on finetuning towards the cider metric. additionally, we find that our model has an effective vocabulary size that is more than double that of the current state-of-the-art, suggesting that our model is more capable of learning and generating uncommon words. we have demonstrated that our method for region pointer advancement works well in the vision-totext context. however, its implementation could be applied to any sequence-to-sequence tasks where structural chunks in the input data (e.g. image regions) can be related to structural chunks in the output (e.g. natural language sentence chunks); some possible applications would be speech-to-text, machine translation or the standard image captioning task when combined with a region selection and sorting mechanism. for the task of controllable image captioning, we would encourage future work to consider complementary metrics such as caption diversity and effective vocabulary size (alongside the standard captioning metrics) to better understand a model's capacity to generate unique descriptions for each unique input. additional metrics to specifically measure the adherence to an ordered region sequence would be welcome.