End-To-End Memory Networks
- Paper: End-To-End Memory Networks
- Authors: Sainbayar Sukhbaatar, Arthur Szlam, Jason Weston, Rob Fergus
- Lab, year: New York University and Facebook AI Research, 2015 (NIPS 2015, now NeurIPS)
- Video: YouTube Short coming on 23 Dec 2026 on Backprop Daily
Summary
An End-To-End Memory Network (MemN2N) is a Memory Network with soft attention over its memories instead of a hard choice, so it can be trained by backpropagation from question-answer pairs alone, without labels for the supporting sentences (Abstract). Each sentence is embedded twice, as a key m_i and a value c_i; the question vector u attends over the keys, reads a weighted sum of the values and adds it to u, and this “hop” is repeated K times before the answer is predicted (Sections 2.1–2.2).
On the 20 bAbI question-answering tasks with 1,000 training examples each, its best version had a mean error of 12.4%, against 6.7% for the original Memory Network trained with supporting-fact labels and 51.3% for an LSTM (long short-term memory network; Table 1). The same model also does language modelling, reaching a test perplexity (how surprised the model is by the next word; lower is better) of 111 on Penn Treebank against 115 for an LSTM (Table 2).
What Problem Does It Solve
The original Memory Network needed to be told which sentences support each answer during training, because its memory lookup was a hard arg max that gradients cannot pass through. The authors’ version “is trained end-to-end, and hence requires significantly less supervision during training, making it more generally applicable in realistic settings” (Abstract). It also brings the multiple reasoning steps of Memory Networks to an attention model.
Core Idea
One hop computes p_i = softmax(uᵀ m_i), reads o = Σ_i p_i c_i and sets u ← u + o (Section 2.1, Eqs. 1–2 and 4). Stacking K hops lets the model look up one fact, then use what it found to look up the next. With adjacent weight tying, the output embedding of one hop is the input embedding of the next (A^{k+1} = C^k), the answer matrix is W^T = C^K and the question embedding is B = A^1 (Section 2.2).
Key Method Details
- Sentence representation: bag of words, or position encoding (PE), which weights each word by its position so that word order affects m_i (Section 4.1).
- Temporal encoding: a learned vector T_A(i) is added to memory i according to how far back the sentence is; adding 10% empty memories during training (“random noise”, RN) regularises it (Section 4.1).
- Training: SGD with learning rate 0.01 halved every 25 epochs up to 100 epochs, batch 32 with the cost not averaged, gradient norm clipped at 40, weights from N(0, 0.1²), and the 50 most recent sentences as memory. Linear start (LS) first trains without the softmax on the memories, at learning rate 0.005, until the validation loss stops falling (Section 4.2).
- bAbI results (1k examples, mean error over 20 tasks): 1, 2 and 3 hops with PE + LS and joint training gave 25.8%, 15.6% and 13.3%; PE improved over bag-of-words on tasks where word order matters (Section 4, Table 1). With 10k examples the best mean error was 6.6% against 3.2% for the strongly supervised Memory Network.
Simplifications in This Notebook
- Generated stories instead of bAbI: 4 actors, 3 objects and 5 rooms; “where is the person” questions (one supporting sentence) and “where is the object” questions (two supporting sentences, like bAbI task 2). 1,000 training, 100 validation and 200 test stories.
- Paper’s training recipe (SGD, halving schedule, summed cost, clipping, linear start, random noise, 3 hops, adjacent tying, temporal encoding) with embedding size 20.
- Comparisons: 1 hop vs 3 hops, PE vs bag-of-words, and a word-level LSTM (Adam, 30 epochs). No language-modelling experiment.
- Bugs fixed: the earlier notebook averaged the cost over the batch (32 times smaller steps than the paper’s summed cost), used only the first question of each story, asked about objects that had not been mentioned, and gave PE a fixed sentence length instead of each sentence’s own.
What the Notebook Result Shows
| Model | Actor | Actor+object | All |
|---|---|---|---|
| MemN2N, PE, 3 hops | 100.00% | 97.64% | 99.40% |
| MemN2N, PE, 1 hop | 100.00% | 33.62% | 83.16% |
| MemN2N, BoW, 3 hops | 100.00% | 97.43% | 99.35% |
| LSTM | 41.34% | 32.98% | 39.22% |
- More hops help, as in the paper: one hop solves the one-fact questions but only 33.62% of the two-fact ones; three hops reach 97.64%.
- The attention finds the right sentences without labels: the true supporting sentence was the most-attended memory at some hop for 100.00% of actor questions, and 97.22% of the supporting sentences of actor+object questions were.
- PE and bag-of-words tie (99.40% vs 99.35%) because word order is not needed in these sentences, so this run does not test PE.
- The LSTM baseline is weak (39.22%) and should not be read as a strong reference.
- Test set: 1,841 questions (1,374 actor, 467 actor+object), one seed; not comparable with the paper’s bAbI numbers.
Influence
OpenAlex lists about 2,400 citations (2,382 when checked on 3 December 2026). The soft key-value read over memories was developed further in Key-Value Memory Networks (Miller et al., 2016), and the bAbI tasks it was tested on come from Weston et al. (2015). Attention Is All You Need (Vaswani et al., 2017) cites end-to-end memory networks as recurrent-attention models that perform well on simple question answering and language modelling.
Resources
| File | Description |
|---|---|
| README.md | This overview — a 5-minute read covering the paper’s summary, core idea, key method details, influence, and a plain-English explanation of the problem it solves |
| solution.ipynb | From-scratch MemN2N with adjacent tying, position and temporal encoding, linear start and random noise, on generated stories, with 1-hop, bag-of-words and LSTM comparisons and attention plots |
| CODE_ARCHITECTURE.md | Section-by-section breakdown of the notebook — what each cell does, data flow, tensor shapes, and key design decisions |
| TALK.md | Press coverage, Q&A (answers from the paper), and common misconceptions about the paper |