Papers
Topics
Authors
Recent
Search
2000 character limit reached

Inside–Outside Algorithm Overview

Updated 5 March 2026
  • Inside–Outside algorithm is a dynamic programming method that computes inside (content) and outside (context) vector representations for each span in a sequence.
  • It uses bottom-up and top-down passes along with neural composition functions to score binary splits and induce latent tree structures efficiently.
  • The algorithm’s parallelizable dynamic programming framework underpins neural models like DIORA, achieving competitive results in unsupervised syntactic parsing tasks.

The inside–outside algorithm is a dynamic programming technique central to probabilistic and neural approaches for latent tree induction, structure prediction, and unsupervised syntactic parsing. It computes, for every subsequence (“span”) of an input sequence, two vector-valued representations: an “inside” representation capturing the content of the span itself, and an “outside” representation capturing the remainder of the sequence excluding that span. Classical forms arise in parsing algorithms for probabilistic context-free grammars. Recent neural instantiations, such as the deep inside–outside recursive autoencoder (DIORA) framework, generalize the principle by incorporating highly parameterized composition functions, enabling unsupervised induction of constituent structure while simultaneously learning span representations in a differentiable manner (Drozdov et al., 2019).

1. Vector-Valued Inside and Outside Representations

Given an input sequence x0,,xT1x_0,\dots,x_{T-1} with learned or pre-trained embeddings viRdv_i\in\mathbb R^d, the inside–outside algorithm works over chart cells (i,j)(i,j) representing spans xi,,xj1x_i,\dots,x_{j-1} (0i<jT0\leq i<j\leq T). For each chart cell, the following are computed:

  • Inside representation I(i,j)=aˉ(i,j)RhI(i,j)=\bar a(i,j)\in\mathbb R^h: encodes the content of xi,,xj1x_i,\dots,x_{j-1}.
  • Outside representation O(i,j)=bˉ(i,j)RhO(i,j)=\bar b(i,j)\in\mathbb R^h: encodes all content outside xi,,xj1x_i,\dots,x_{j-1} in the sequence.
  • Scalar compatibility scores e^(i,j)\hat e(i,j) and viRdv_i\in\mathbb R^d0 for inside and outside, respectively.

These representations form the basis for soft-structured learning of trees and for modeling token-level conditional distributions.

2. Dynamic Programming for Inside and Outside Passes

The computation proceeds via two passes:

2.1. Inside Pass (Bottom-Up)

  • For length-1 spans: viRdv_i\in\mathbb R^d1, viRdv_i\in\mathbb R^d2, typically using a one-layer neural network.
  • For larger spans viRdv_i\in\mathbb R^d3, all binary splits (viRdv_i\in\mathbb R^d4) are considered, applying a composition function (e.g., a two-layer MLP or TreeLSTM) to merge subspan representations.
  • The score for a split viRdv_i\in\mathbb R^d5 is given by

viRdv_i\in\mathbb R^d6

where viRdv_i\in\mathbb R^d7 is a learned bilinear form and viRdv_i\in\mathbb R^d8 contains trainable parameters.

  • Normalized weights viRdv_i\in\mathbb R^d9 are obtained by softmax over splits.
  • The inside representation (i,j)(i,j)0 and expected score (i,j)(i,j)1 are weighted sums over splits.

2.2. Outside Pass (Top-Down)

  • The root outside vector (i,j)(i,j)2 is initialized as a learned vector; (i,j)(i,j)3.
  • For each non-root span (i,j)(i,j)4, each context pair (i,j)(i,j)5 (where (i,j)(i,j)6 is one child of parent span (i,j)(i,j)7 and (i,j)(i,j)8 is the sibling span) is considered.
  • The context score is

(i,j)(i,j)9

followed by a softmax normalization to obtain weights xi,,xj1x_i,\dots,x_{j-1}0 over valid parent–sibling configurations.

  • The outside representation xi,,xj1x_i,\dots,x_{j-1}1 and score xi,,xj1x_i,\dots,x_{j-1}2 are computed as expected values over contexts using a composition function.

This framework allows parallel and differentiable computation of all span and context representations.

3. Span-Conditional Training Objectives

After both passes, each terminal cell xi,,xj1x_i,\dots,x_{j-1}3 has associated xi,,xj1x_i,\dots,x_{j-1}4 and xi,,xj1x_i,\dots,x_{j-1}5 vectors. DIORA adopts a masked language modeling loss in which, for every position xi,,xj1x_i,\dots,x_{j-1}6, the model is trained to distinguish the true token xi,,xj1x_i,\dots,x_{j-1}7 from sampled negatives xi,,xj1x_i,\dots,x_{j-1}8, using the dot product of inside and outside vectors:

xi,,xj1x_i,\dots,x_{j-1}9

An equivalent probabilistic formulation applies a softmax to yield the conditional probability of observing 0i<jT0\leq i<j\leq T0 given the outside representation, enabling unsupervised induction of tree structure (Drozdov et al., 2019).

4. CKY-Style Decoding for Tree Recovery

At test time, the algorithm extracts the single highest-scoring binary tree over the sequence, with split scores given by 0i<jT0\leq i<j\leq T1. A CKY-style Viterbi dynamic program is employed:

  • For every cell 0i<jT0\leq i<j\leq T2 and possible split 0i<jT0\leq i<j\leq T3,

0i<jT0\leq i<j\leq T4

and the split yielding the maximum is recorded.

  • Backtracking from the root yields the optimal binary parse tree.

This method ensures exact or near-gold parses for sentences in unsupervised settings, leveraging the learned composition parameters (Drozdov et al., 2019).

5. Computational Complexity and Parallelization

Critical computational bottlenecks are addressed by efficiently structuring the DP recurrences:

  • Chart filling for inside and outside passes over 0i<jT0\leq i<j\leq T5 tokens requires 0i<jT0\leq i<j\leq T6 serial steps but is highly parallelizable. All “soft” split operations can be batched—permitting 0i<jT0\leq i<j\leq T7 wall-clock time with modern GPU hardware.
  • The CKY decoding phase also scales as 0i<jT0\leq i<j\leq T8 in serial but can achieve 0i<jT0\leq i<j\leq T9 parallel time.
  • The masked LM loss is I(i,j)=aˉ(i,j)RhI(i,j)=\bar a(i,j)\in\mathbb R^h0 for I(i,j)=aˉ(i,j)RhI(i,j)=\bar a(i,j)\in\mathbb R^h1 negatives and can be parallelized over batch dimensions.
  • Empirically, DIORA with an 800-dimensional composition MLP handles sentences of length up to I(i,j)=aˉ(i,j)RhI(i,j)=\bar a(i,j)\in\mathbb R^h2–I(i,j)=aˉ(i,j)RhI(i,j)=\bar a(i,j)\in\mathbb R^h3, with full training completed in several days on standard GPUs.

This parallelism is essential for scaling latent tree induction in neural architectures (Drozdov et al., 2019).

6. Significance and Extensions

The inside–outside algorithm, instantiated as in DIORA, provides a foundation for unsupervised syntax discovery and constituent representation learning. By jointly learning to compose, score, and reconstruct all possible tree structures, it can outperform prior approaches in F1 constituency parsing metrics on standard benchmarks such as WSJ and MultiNLI. The approach’s capacity to consider all binary trees and its compatibility with end-to-end neural training distinguish it from earlier non-neural or non-differentiable frameworks.

A plausible implication is that such architectures may generalize to any structured prediction task where latent tree or segmentation structure is relevant, provided suitable composition and scoring functions can be defined. The dynamic programming structure underlying the approach is essential for tractably considering the exponential space of possible trees, demonstrating the durability and significance of the inside–outside algorithm in modern deep learning (Drozdov et al., 2019).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Inside–Outside Algorithm.