Pragmatically Informative Image Captioning with Character-Level Inference
Reuben Cohn-Gordon, Noah Goodman, Christopher Potts
Introduction
The success of automatic image captioning Farhadi et al. (2010); Mitchell et al. (2012); Karpathy and Fei-Fei (2015); Vinyals et al. (2015) demonstrates compellingly that end-to-end statistical models can align visual information with language. However, high-quality captions are not merely true, but also pragmatically informative in the sense that they highlight salient properties and help distinguish their inputs from similar images. Captioning systems trained on single images struggle to be pragmatic in this sense, producing either very general or hyper-specific descriptions.
In this paper, we present a neural image captioning systemThe code is available at https://github.com/reubenharry/Recurrent-RSA that is a pragmatic speaker as defined by the Rational Speech Acts (RSA) model Frank and Goodman (2012); Goodman and Stuhlmüller (2013). Given a set of images, of which one is the target, its objective is to generate a natural language expression which identifies the target in this context. For instance, the literal caption in Figure 1 could describe both the target and the top two distractors, whereas the pragmatic caption mentions something that is most salient of the target. Intuitively, the RSA speaker achieves this by reasoning not only about what is true but also about what it’s like to be a listener in this context trying to identify the target.
This core idea underlies much work in referring expression generation Dale and Reiter (1995); Monroe and Potts (2015); Andreas and Klein (2016); Monroe et al. (2017) and image captioning Mao et al. (2016a); Vedantam et al. (2017), but these models do not fully confront the fact that the agents must reason about all possible utterances, which is intractable. We fully address this problem by implementing RSA at the level of characters rather than the level of utterances or words: the neural language model emits individual characters, choosing them to balance pragmatic informativeness with overall well-formedness. Thus, the agents reason not about full utterances, but rather only about all possible character choices, a very small space. The result is that the information encoded recurrently in the neural model allows us to obtain global pragmatic effects from local decisions. We show that such character-level RSA speakers are more effective than literal captioning systems at the task of helping a reader identify the target image among close competitors, and outperform word-level RSA captioners in both efficiency and accuracy.
Bayesian Pragmatics for Captioning
In applying RSA to image captioning, we think of captioning as a kind of reference game. The speaker and listener are in a shared context consisting of a set of images , the speaker is privately assigned a target image , and the speaker’s goal is to produce a caption that will enable the listener to identify . is the set of possible utterances. In its simplest form, the literal speaker is a conditional distribution assigning equal probability to all true utterances and to all others. The pragmatic listener is then defined in terms of this literal agent and a prior over possible images:
The pragmatic speaker is then defined in terms of this pragmatic listener, with the addition of a rationality parameter governing how much it takes into account the distribution when choosing utterances. is here taken to be a uniform distribution over :
As a result of this back-and-forth, the speaker is reasoning not merely about what is true, but rather about a listener reasoning about a literal speaker who reasons about truth.
To illustrate, consider the pair of images 2a and 2b in Figure 2. Suppose that . Then the literal speaker is equally likely to produce bus and red bus when the left image 2a is the target. However, breaks this symmetry; because red bus is false of the right bus, and . The speaker therefore ends up favoring red bus when trying to convey 2a, so that and .
Applying Bayesian Pragmatics to a Neural Semantics
To apply the RSA model to image captioning, we first train a neural model with a CNN-RNN architecture Karpathy and Fei-Fei (2015); Vinyals et al. (2015). The trained model can be considered an -style distribution on top of which further listeners and speakers can be built. (Unlike the idealized described above, a neural will assign some probability to untrue utterances.)
The main challenge for this application is that the space of utterances (captions) will be very large for any suitable captioning system, making the calculation of intractable due to its normalization over all utterances. The question, therefore, is how best to approximate this inference. The solution employed by Monroe et al. (2017) and Andreas and Klein (2016) is to sample a small subset of probable utterances from the , as an approximate prior upon which exact inference can be performed. While tractable, this approach has the shortcoming of only considering a small part of the true prior, which potentially decreases the extent to which pragmatic reasoning will be able to apply. In particular, if a useful caption never appears in the sampled prior, it cannot appear in the posterior.
Inspired by the success of the ‘‘emittor-suppressor’’ method of Vedantam et al. (2017), we propose an incremental version of RSA. Rather than performing a single inference over utterances, we perform an inference for each step of the unrolling of the utterance.
We use a character-level LSTM, which defines a distribution over characters , where pc (‘‘partial caption’’) is a string of characters constituting the caption so far and is the next character of the caption. This is now our : given a partially generated caption and an image, it returns a distribution over which character should next be added to the caption. The advantage of using a character-level LSTM over a word-level one is that is much smaller for the former ( vs. ), making the ensuing RSA model much more efficient.
We use this to define an which takes a partial caption and a new character, and returns a distribution over images. The , in turn, given a target image , performs an inference over the set of possible characters to determine which is best with respect to the listener choosing .
At timestep of the unrolling, the listener takes as its prior over images the posterior from timestep . The idea is that as we proceed with the unrolling, the priors on which image is being referred to may change, which in turn should affect the speaker’s actions. For instance, the speaker, having made the listener strongly in favor of the target image, is less compelled to continue being pragmatic.
2 Model Definition
In our incremental RSA, speaker models take both a target image and a partial caption pc. Thus, is a neurally trained conditional distribution , where is the current timestep of the unrolling and is a character.
We define the in terms of the as follows, where ip is a distribution over images representing the prior:
Given an and , we define and as:
To perform greedy unrolling (though in practice we use a beam search) for either or , we initialize the state as a partial caption consisting of only the start token and a uniform prior over the images . Then, for , we use our incremental speaker model or to generate a distribution over the subsequent character , and add the character with highest probability density to , giving us . We then run our listener model on , to obtain a distribution over images that the can use at the next timestep.
This incremental approach keeps the inference itself very simple, while placing the complexity of the model in the recurrent nature of the unrolling.The move from standard to incremental RSA can be understood as a switching of the order of two operations; instead of unrolling a character-level distribution into a sentence level one and then applying pragmatics, we apply pragmatics and then unroll. This generalizes to any recursive generation of utterances. While our is character-level, the same incremental RSA model works for a word-level , giving rise to a word-level . We compare character and word s in section 4.2.
As well as being incremental, these definitions of and differ from the typical RSA described in section 2 in that and draw their priors from and respectively. This generalizes the scheme put forward for by Andreas and Klein (2016). The motivation is to have Bayesian speakers who are somewhat constrained by the language model. Without this, other methods are needed to achieve English-like captions, as in Vedantam et al. (2017), where their equivalent of the is combined in a weighted sum with the .
Evaluation
Qualitatively, Figures 1 and 2 show how the captions are more informative than the , as a result of pragmatic considerations. To demonstrate the effectiveness of our method quantitatively, we implement an automatic evaluation.
To evaluate the success of as compared to , we define a listener , where is the total probability of incrementally generating caption given image. In other words, uses Bayes’ rule to obtain from the posterior probability of each image given a full caption .
The neural used in the definition of must be trained on separate data to the neural used for the model which produces captions, since otherwise this production model effectively has access to the system evaluating it. As Mao et al. (2016b) note, ‘‘a model might ‘communicate’ better with itself using its own language than with others’’. In evaluation, we therefore split the training data in half, with one part for training the used in the caption generation model and one part for training the used in the caption evaluation model .
We say that the caption succeeds as a referring expression if the target has more probability mass under the distribution than any distractor.
We train our production and evaluation models on separate sets consisting of regions in the Visual Genome dataset Krishna et al. (2017) and full images in MSCOCO Chen et al. (2015). Both datasets consist of over 100,000 images of common objects and scenes. MSCOCO provides captions for whole images, while Visual Genome provides captions for regions within images.
Our test sets consist of clusters of 10 images. For a given cluster, we set each image in it as the target, in turn. We use two test sets. Test set 1 (TS1) consists of 100 clusters of images, 10 for each of the 10 most common objects in Visual Genome.Namely, man, person, woman, building, sign, table, bus, window, sky, and tree.
Test set 2 (TS2) consists of regions in Visual Genome images whose ground truth captions have high word overlap, an indicator that they are similar. We again select 100 clusters of 10. Both test sets have 1,000 items in total (10 potential target images for each of 100 clusters).
Captioning System
Our neural image captioning system is a CNN-RNN architecturehttps://github.com/yunjey/pytorch-tutorial/tree/master/tutorials/03-advanced/image_captioning adapted to use a character-based LSTM for the language model.
Hyperparameters
We use a beam search with width 10 to produce captions, and a rationality parameter of for the .
2 Results
As shown in Table 1, the character-level obtains higher accuracy (68% on TS1 and 65.9% on TS2) than the (48.9% on TS1 and 47.5% on TS2), demonstrating that is better than at referring.
We also observe that 66% percent of the times in which the caption is referentially successful and the caption is not, for a given image, the caption is not one of the top 50 captions, as generated by the beam search unrolling at . This means that in these cases the non-incremental RSA method of Andreas and Klein (2016) could not have generated the S1 caption, if these top 50 captions were the support of the prior over utterances.
Comparison to Word-Level RSA
We compare the performance of our character-level model to a word-level model.Here, we use greedy unrolling, for reasons of efficiency due to the size of for the word-level model, and set from tuning on validation data. For comparison, we note that greedy character-level achieves an accuracy of 61.2% on TS1. This model is incremental in precisely the way defined in section 3.2, but uses a word-level LSTM so that are words and is a vocabulary of English. It is evaluated with an model that also operates on the word level.
Though the word performs better on both test sets than the character , the character outperforms the word , demonstrating the advantage of a character-level model for pragmatic behavior. We conjecture that the superiority of the character-level model is the result of the increased number of decisions where pragmatics can be taken into account, but leave further examination for future research.
Variants of the Model
We further explore the effect of two design decisions in the character-level model. First, we consider a variant of which has a prior over utterances determined by an LSTM language model trained on the full set of captions. This achieves an accuracy of 67.2% on TS1. Second, we consider our standard but with unrolling such that the prior is drawn uniformly at each timestep rather than determined by the posterior at the previous step. This achieves an accuracy of 67.4% on TS1. This suggests that neither this change of nor priors has a large effect on the performance of the model.
Conclusion
We show that incremental RSA at the level of characters improves the ability of the neural image captioner to refer to a target image. The incremental approach is key to combining RSA with language models: as utterances become longer, it becomes exponentially slower, for a fixed , to subsample % of the utterance distribution and then perform inference (non-incremental approach). Furthermore, character-level RSA yields better results than word-level RSA and is far more efficient.
Acknowledgments
Many thanks to Hiroto Udagawa and Poorvi Bhargava, who were involved in early versions of this project. This material is based in part upon work supported by the Stanford Data Science Initiative and by the NSF under Grant No. BCS-1456077. This work is also supported by a Sloan Foundation Research Fellowship to Noah Goodman.