End-To-End Memory Networks

A recurrent multi-hop attention architecture that reads an external memory several times before producing an answer.

Metadata

FieldValue
PaperEnd-To-End Memory Networks
AuthorsSainbayar Sukhbaatar, Arthur Szlam, Jason Weston, Rob Fergus
Year2015
VenueNeurIPS 2015
arXiv1503.08895
Statusverified

Question

An attention mechanism can retrieve one relevant memory in a single step. But many tasks require chained access: retrieve a fact, use it to form a better query, retrieve another fact, and only then answer. The paper asks whether repeated attention hops over an external memory can be trained end-to-end without requiring the model to expose intermediate reasoning labels.

The architecture separates:

  • an input representation for the query;
  • a memory representation for address keys;
  • an output representation for values;
  • a recurrent state updated after each hop;
  • a final prediction over the answer vocabulary.

This is a compact precursor to architectures that repeatedly retrieve context before generation.

Main Claim

The paper introduces a recurrent attention model over a possibly large external memory. Multiple computational hops improve performance on the reported question-answering tasks, while end-to-end training reduces the need for supervision about intermediate memory accesses.

The narrow claim is:

The model demonstrates learned multi-step retrieval under the paper’s data and task protocols. It does not prove that attention weights are faithful explanations or that more hops always improve reasoning.

Architecture Contract

ItemContract
Queryencoded input question
Memorya set or sequence of input facts
Address keysmemory embeddings
Valuesoutput embeddings
Readsoftmax attention over memory slots
Statequery representation updated after each hop
Hopsrepeated reads with shared or hop-specific parameters
Outputanswer distribution over a vocabulary

Let the query at hop be . The memory contains input vectors and output vectors . The attention probability for memory slot is:

The retrieved output is:

and the next state is:

The residual update preserves the original query while adding evidence retrieved at hop .

Input and Output Embeddings

The model can use separate matrices for addressing and answering:

where converts a sentence or fact into a bag-of-words or positional representation, produces address keys, and produces value vectors. The query is embedded with:

Using separate and is important. The representation that makes a fact easy to find need not be the same representation that should be returned after retrieval.

The final answer distribution can be:

where maps the final memory state to answer vocabulary logits.

A Single Hop

For one hop, the data flow is:

  1. encode the query as ;
  2. encode each memory item as an address key ;
  3. score every item with ;
  4. normalize scores into ;
  5. retrieve a weighted value vector ;
  6. add the retrieved vector to the query state;
  7. predict an answer from the updated state.

This is an attention read over an external memory. The memory can be a list of facts, sentences, or other discrete records; the architecture does not require those records to be part of the current hidden sequence in the same way as self-attention.

Multiple Hops

The key architectural extension is repetition:

At each hop, the updated state changes the attention scores:

The first hop may retrieve a subject or relation, while the second hop uses that result to find another supporting fact. The paper’s “hop” is a computational step, not automatically a human-interpretable reasoning step.

Parameter tying can make every hop use the same embedding and output matrices:

or different matrices can be used at different hops. Tying reduces parameters and encourages a repeated retrieval operation; untied hops permit stage-specific transformations but make capacity and interpretation different.

Temporal and Positional Encoding

If a memory item is a sentence or sequence, a bag-of-words representation loses word order. A positional encoding can weight token embeddings by their position:

where is the embedding of token and is a position-dependent vector. This allows the memory representation to preserve some local order without using a full recurrent encoder.

Temporal encoding can also distinguish memory slots that have similar content but occur at different positions. The general lesson is that an external memory still needs an explicit representation contract: “retrieve a sentence” is not enough if order or provenance affects the answer.

Supervision Boundary

The model is trained from the final answer loss:

Gradients flow through the output layer, every hop, every attention distribution, and the memory embeddings. Intermediate supporting facts do not need to be labeled for the architecture to learn useful retrieval patterns on the task distribution.

This is a useful distinction:

Training signalWhat it can teach
final answer onlyretrieval paths that help answer loss
answer plus supporting factsexplicit evidence selection constraints
answer plus hop supervisionmore controlled intermediate access
contrastive memory objectiveseparation of relevant and irrelevant slots

End-to-end optimization reduces annotation requirements, but it does not guarantee that every high-attention slot is causally sufficient evidence.

Relation to RNNsearch and Transformers

The paper describes multiple hops as an extension of attention-based sequence models. The comparison is useful:

ArchitectureMemory sourceNumber of readsState update
RNN encoder-decoder with attentionencoded source sequenceusually one read per decoder steprecurrent decoder state
End-to-End Memory Networkexternal memory recordsmultiple learned hopsresidual query update
Transformer self-attentioncurrent token statesone attention sublayer per blockresidual stream across layers
RAG-style systemretrieved documentsexternal retriever and generation readsdiscrete/system-level context update

The important axis is not only “attention or no attention.” It is where the memory comes from, how many access steps occur, and whether the memory can be written or only read.

Evidence

TaskWhat it probesPaper-level reading
synthetic question answeringmulti-fact retrieval and compositionmultiple hops can improve answer accuracy
language modelinguse of memory reads in next-token predictionmemory architecture can be used beyond QA
varying number of hopscomputational depth of retrievalextra hops are useful when the task requires chained access
comparison to Memory Networksend-to-end versus intermediate supervisionfinal-answer training can learn useful access patterns

The results support the multi-hop retrieval design under the reported benchmarks. They do not establish that attention maps are complete explanations of model reasoning.

Ablation and Reading Questions

QuestionWhat it isolates
Does performance improve from one hop to several?value of iterative retrieval
Are embeddings tied across hops?repeated operator versus stage-specific computation
Is positional encoding enabled?order sensitivity in memory representation
Are memory slots fixed or dynamically updated?read-only knowledge base versus writable state
Is the answer copied from memory or generated from state?retrieval versus synthesis boundary
Are supporting facts labeled?end-to-end learning versus explicit evidence supervision

When reproducing the model, match the number of hops, memory size, vocabulary, answer candidates, positional encoding, parameter tying, and random seed. A change in any of these can alter the effective reasoning depth or capacity.

Complexity and Systems Trade-offs

For memory slots, embedding dimension , and hops, dense memory lookup costs approximately:

per query, excluding the cost of encoding the memory and output projection. More hops increase computational depth and may improve compositional retrieval, but they also increase latency and create more opportunities for diffuse or incorrect attention.

Scaling axisBenefitCost or risk
memory slots larger searchable contextmore score computation and distractors
hops deeper retrieval compositionlatency, instability, and over-retrieval
embedding dimension richer keys and valuesmemory bandwidth and parameter count
separate value embeddingsdecoupled address/value rolesadditional capacity and mismatch risk
parameter tyinglower parameter countless hop-specific specialization

An external memory can be large in logical size while still being expensive to encode, move, and score. “Large memory” is not synonymous with cheap retrieval.

Limitations

  • Soft attention over a memory can mix multiple facts rather than retrieve a discrete record.
  • Multiple hops do not guarantee faithful or logically valid reasoning.
  • A final-answer objective may reward shortcut retrieval paths that correlate with the label.
  • The architecture is primarily read-oriented; persistence and write governance require additional components.
  • Synthetic QA tasks may not represent noisy documents, contradictory sources, or real retrieval distributions.
  • Scaling the memory increases both compute and the number of distractor slots.
  • The model’s memory representation and answer vocabulary constrain what can be retrieved or generated.
  • Later RAG systems add document retrieval, chunking, provenance, and generation policies that are outside this neural block.

Relation to Other Architecture Papers

PaperConnection
Memory Networksoriginal memory-plus-inference formulation for QA
Neural Turing Machinesdifferentiable external memory with explicit writes
Differentiable Neural Computermemory allocation and temporal-link traversal
Hopfield Networks is All You Needone-step associative retrieval and attention correspondence
Attention Is All You Needattention as the dominant token-mixing operation
Transformer-XLrecurrent segment-level context for longer sequences

Implementation Checklist

  • Define whether the memory is read-only, append-only, or writable.
  • Separate address embeddings from value embeddings when the roles differ.
  • Log attention entropy and top-k memory slots at every hop.
  • Test one-hop and multi-hop variants under matched compute.
  • Check whether supporting facts remain selected under paraphrase and distractors.
  • Evaluate memory size and hop count outside the training range.
  • Record parameter tying and positional encoding as part of the architecture configuration.
  • Treat retrieved evidence and final generated output as separate artifacts for verification.

Why It Matters

End-To-End Memory Networks make “reasoning by repeated retrieval” an explicit neural block:

This is a useful bridge from early external-memory networks to modern retrieval-augmented systems and agent workflows. It also gives the wiki a precise vocabulary for separating a model’s internal attention context from a system’s external knowledge store.

Connections