liveBook · Manning

Dot-product attention

As explained in Deep Learning with R, Third Edition

Dot-product attention computes attention relevance scores from the dot products of query-like and source-like vectors and uses them to form a weighted representation.

Dot-product attention scores each source vector against the current target vector, normalizes those scores with softmax, and combines source vectors into a relevance-weighted representation. In translation, it lets each predicted token focus on the most useful source words instead of carrying all information through a long recurrent loop. section 15.3.1

A complete attention step

For target and source sequences, compute every target–source dot product, normalize across source positions, then form weighted source sums: scores <- op_einsum("btd,bsd->bts", target, source) scores <- op_softmax(scores, axis = -1) combined <- op_einsum("bts,bsd->btd", scores, source) The score matrix has one row per target position; each row distributes one target token’s attention across the source sequence.

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains dot products, softmax normalization, weighted sums, sequence-shaped score matrices, and tensor implementation.
Examples
Demonstrates translation prediction, source-target score matrices, and image retrieval through query-key matching.
What it assumes
Assumes vector sequences and softmax, while motivating the mechanism through GRU-based source and target representations.
What you can do after
Build it from scratch using tensor contractions, softmax scores, and weighted source representations.
How it connects
Connects query-like targets and source vectors with softmax, weighted sums, recurrent networks, and multi-head attention.

Also explained in

Compare how 2 books explain dot-product attention →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.