Matrix calculator

A transformer is mostly matrix multiplications: every token's vector times a weight matrix, queries times keys. Each number of the result is one row times one column: multiply them entry by entry and add up. Press Play and watch the result fill, cell by cell.

Playback speed

Your matrices

A: 3 × 2
B: 2 × 2

C = A B, row by row: 4, 2; 1, 1; 5, −1

The one rule

To multiply A by B, the rows of A must be as long as the columns of B: here the middle size. The result has as many rows as A and as many columns as B. Cell (i, j) of the result is row i of A times column j of B: the first entries multiplied, plus the second entries multiplied, and so on. That sum of products is the dot product, the same operation attention uses to compare a query with a key.

In the paper's model, every token's vector of 512 numbers is multiplied by weight matrices of 512 × 64 to make its query, key and value (section 3.2.2), and the feed-forward network multiplies by 512 × 2048 and back (section 3.3). Our model does the same with 64 numbers.

An unhandled error has occurred. Reload ๐Ÿ—™

Reconnecting…

Your connection to the Transformers and Attention Lab dropped, probably a Wi-Fi blip. Hold on while it reconnects.

The connection could not be restored. The page will reload in a few seconds.