Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Letting the valves see the memory
In a standard LSTM the valves (gates) decide what to do from the input and the visible output, not from the memory itself. If the output valve is shut, the visible output is blank, and the valves cannot tell what is stored. A peephole is a small window from the memory to each valve. With it, a valve can open exactly when the stored count reaches a threshold, like a timer going off. The demo shows how gates control what survives in memory.
Precise timing matters in rhythm, speech prosody and control loops. Peepholes are a cheap option to try when a recurrent model must act at exact times.
- 1. A peephole connects…
- 2. Without peepholes, a closed output gate hides…
- 3. Peepholes were introduced for…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Equations: with diagonal peephole vectors p_i, p_f, p_o,
- i = σ(zWᵢ + bᵢ + p_i ⊙ cₜ₋₁);
- f = σ(zW_f + b_f + p_f ⊙ cₜ₋₁);
- cₜ = f ⊙ cₜ₋₁ + i ⊙ g;
- o = σ(zWₒ + bₒ + p_o ⊙ cₜ). The output gate sees the new cell.
- Cost: 3n extra parameters. For d = 10 and n = 32 that is 96 on top of 5504 (1.7%); for d = 100 and n = 512, 0.12%.
- Timer example:
- a cell adding 0.5 per step crosses 3.0 after 7 steps;
- an output gate with bias −4 and peephole 1 is σ(−4) = 0.018 at c = 0 and σ(2) = 0.88 at c = 6;
- it opens when the count is high.
- Without peepholes: when o ≈ 0, h = o·tanh(c) ≈ 0. Gates then receive no information about c, so a closed output gate cannot reopen based on the stored count alone.
- 1. Extra parameters for n = 32:
- 2. Which cell does the output-gate peephole see?
- 3. Steps for 0.5 per step to exceed 3.0:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Peepholes in code
Exercise 1.
- With peephole 1 and bias −4, the output gate stayed shut (below 0.05) for a cell at 0 and opened (above 0.85) for a cell at 6.
- The parameter count was 5600.
Practice.
- PyTorch’s
nn.LSTMhas no peepholes. Write a custom cell and lose cuDNN speed. - TensorFlow 1’s
LSTMCell(use_peepholes=True)had them, and so do some speech toolkits. - Initialise peephole weights near zero so the model starts as a standard LSTM.
- Given the evidence below, try peepholes only for timing-sensitive tasks, and measure.
class PeepholeLSTMCell(nn.Module):
def __init__(self, d, n):
super().__init__(); self.lin = nn.Linear(d + n, 4 * n); self.p = nn.Parameter(torch.zeros(3, n))
def forward(self, x, h, c):
a = self.lin(torch.cat([x, h], -1)); ai, af, ag, ao = a.chunk(4, -1)
i, f = torch.sigmoid(ai + self.p[0] * c), torch.sigmoid(af + self.p[1] * c)
c = f * c + i * torch.tanh(ag); o = torch.sigmoid(ao + self.p[2] * c)
return o * torch.tanh(c), c- 1. Does PyTorch's nn.LSTM support peepholes?
- 2. Peephole weights should start…
- 3. A custom cell loses…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
What peepholes add.
- Gates of a standard LSTM are functions of xₜ and hₜ₋₁ = oₜ₋₁ ⊙ tanh(cₜ₋₁).
- When oₜ₋₁ is small, hₜ₋₁ carries almost no information about the cell. The gates are then blind to the stored value and must decide from the input alone.
- Peepholes add p ⊙ c to the gate inputs, making each gate a direct function of its own cell, cheaply (diagonal, 3n weights).
When it matters.
- Gers and Schmidhuber showed peephole LSTMs learning to generate and measure precisely timed spikes, where standard LSTMs struggled.
- In practice a standard LSTM can often keep its output gate slightly open and count through h, which is enough on many tasks.
- In Greff et al.’s large comparison (speech, handwriting, music), removing peepholes did not significantly hurt, and they suggested dropping them for simplicity.
- 1. Standard gates see the cell only through…
- 2. Peephole weights are…
- 3. Greff et al. found removing peepholes…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Do peepholes help timing?
History.
- F. Gers and J. Schmidhuber introduced peephole connections (“Recurrent nets that time and count”, IJCNN 2000).
- F. Gers, N. Schraudolph and J. Schmidhuber developed precise-timing tasks (JMLR 2002).
- A. Graves’s speech and handwriting LSTMs used peepholes (2013).
- K. Greff and colleagues found them unnecessary on standard benchmarks (2017).
Exercise 2.
- Task: an 8-unit LSTM sees one pulse at t = 0 whose height encodes a delay d between 4 and 16. It must spike exactly at step d.
- Training: batches of 32 with Adam; the standard and peephole versions are trained identically.
- Measurement: exact-timing accuracy (the output’s peak at step d) on 500 test sequences after 100 and 200 steps, 3 seeds.
| model | after 100 steps | after 200 steps |
|---|---|---|
| standard LSTM | 0.838, 0.712, 0.188 | 0.768, 1.000, 0.936 |
| peephole LSTM | 1.000, 1.000, 1.000 | 1.000, 1.000, 0.936 |
- Peepholes speed up learning to time. After 100 steps every peephole run was exact, against a mean of 0.58 without.
- The advantage is mostly about speed here. By 200 steps the standard LSTM caught up on two seeds. In a longer 400-step run, both reached 1.0 on all three seeds.
- The result is fragile. With longer delays (8–32) and 200 steps, both versions were erratic across seeds, and no consistent ordering appeared. Treat peepholes as a cheap option to test on timing tasks, not a default.
Peepholes in AI, robotics and aerospace
- Rhythm and timing: music generation and speech prosody models have used peepholes for timing cues.
- Event timing in control: recurrent controllers that must trigger actions after measured intervals may benefit.
- Default choice: for most sensor and language tasks, a standard LSTM or GRU is simpler and as accurate.
References
- F. A. Gers, J. Schmidhuber (2000). “Recurrent nets that time and count.” Proc. IJCNN.
- F. A. Gers, N. N. Schraudolph, J. Schmidhuber (2002). “Learning precise timing with LSTM recurrent networks.” JMLR 3.
- K. Greff, R. K. Srivastava, J. Koutník, B. R. Steunebrink, J. Schmidhuber (2017). “LSTM: a search space odyssey.” IEEE TNNLS 28(10).