Bidirectional Beam Search: Forward-Backward Inference in Neural Sequence Models for Fill-in-the-Blank Image Captioning

Qing Sun, Stefan Lee, Dhruv Batra

Abstract

We develop the first approximate inference algorithm for 1-Best (and M-Best) decoding in bidirectional neural sequence models by extending Beam Search (BS) to reason about both forward and backward time dependencies. Beam Search (BS) is a widely used approximate inference algorithm for decoding sequences from unidirectional neural sequence models. Interestingly, approximate inference in bidirectional models remains an open problem, despite their significant advantage in modeling information from both the past and future. To enable the use of bidirectional models, we present Bidirectional Beam Search (BiBS), an efficient algorithm for approximate bidirectional inference. To evaluate our method and as an interesting problem in its own right, we introduce a novel Fill-in-the-Blank Image Captioning task which requires reasoning about both past and future sentence structure to reconstruct sensible image descriptions. We use this task as well as the Visual Madlibs dataset to demonstrate the effectiveness of our approach, consistently outperforming all baseline methods.

Introduction

Recurrent Neural Networks (RNNs) have become the standard for sequence generation tasks like image captioning. However, standard decoding techniques—most notably Beam Search (BS)—are inherently unidirectional, typically processing text from left to right. While effective for generating captions from scratch, this approach has a significant "blind spot" when applied to sequence completion tasks, such as filling in a missing segment of a sentence.

Figure 3: Comparison of Unidirectional vs. Bidirectional models on a fill-in-the-blank task. Standard Beam Search (A) fails to account for future context, leading to nonsensical results, while BiBS (B) produces a seamless description.

Consider the example: "A man on [_] how to ski." A standard unidirectional model only considers the "past" (the words before the blank). Without knowledge of the "future" (the words after the blank), it might generate "a ski slope with a", resulting in the grammatically incorrect "A man on a ski slope with a how to ski." Bidirectional RNNs (BiRNNs) theoretically solve this by looking both ways, but decoding from them has historically been computationally difficult (NP-hard) due to complex dependencies.

Methodology: Bidirectional Beam Search (BiBS)

To bridge this gap, we introduce Bidirectional Beam Search (BiBS), an efficient algorithm for approximate bidirectional inference. The core innovation lies in treating the BiRNN as a combination of two calibrated but independent Unidirectional RNNs (URNNs)—one moving forward in time and one moving backward.

Figure 2: Architectural comparison between a standard Unidirectional RNN (A) and the Bidirectional RNN (B) utilized by BiBS.

The BiBS Algorithm

BiBS approximates the joint probability of a sequence by combining the scores from both the forward and backward models. The algorithm operates through an iterative process known as coordinate descent:

  1. Forward Pass: The algorithm performs a forward beam search while keeping the "future" beams from the backward model fixed.
  2. Backward Pass: It then performs a backward beam search while keeping the "past" beams from the forward model fixed.
  3. Iteration: This process repeats, allowing the model to refine its predictions based on the updated context from both directions.

This approach is highly efficient, requiring only $2BMT$ RNN steps (where $B$ is beam width, $M$ is the number of update rounds, and $T$ is sequence length), making it practical for real-world applications. Most importantly, it ensures that the generated text "plugs in" correctly to the existing sentence structure, eliminating jarring transitions at the boundaries of blanks.

Experimental Evaluation

We evaluated BiBS on two primary benchmarks designed to test contextual reasoning:

  • Fill-in-the-Blank COCO: We modified the Microsoft COCO image captioning dataset by removing 25%, 50%, or 75% of the words from the middle of captions.
  • Visual Madlibs: This dataset contains targeted image descriptions with blanks in the middle of sentences, requiring models to describe object affordances or relationships between people.

Key Results

BiBS consistently outperformed all baseline methods, including standard Beam Search and sophisticated reranking approaches. On the COCO 25% blank task, BiBS achieved a 7.12 CIDEr score, significantly higher than the 6.54 achieved by the standard forward-only model.

Qualitative analysis revealed that the "future" context acts as a powerful constraint. Interestingly, we found that a purely backward-moving model often outperformed a forward-moving one in image captioning. This suggests that the end of a sentence (often containing specific objects) can be easier to predict than the beginning (which often starts with generic grounding like "A man on...").

Conclusion

Bidirectional Beam Search (BiBS) provides a robust framework for decoding from bidirectional neural models. By treating the future as a constraint rather than an unknown, BiBS enables models to produce grammatically seamless and contextually accurate text in complex sequence completion tasks. Future work may extend these bidirectional inference principles to more complex recursive neural architectures beyond standard RNNs.

Summary updated

BibTeX
@inproceedings{sun2017bidirectional,
  author = {Qing Sun and Stefan Lee and Dhruv Batra},
  title = {{Bidirectional Beam Search: Forward-Backward Inference in Neural Sequence Models for Fill-in-the-Blank Image Captioning}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2017},
  url = {https://openreview.net/forum?id=H1bixa-OZH},
}
Figure