ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Scaled dot-product attention

Query-key dot products are divided by √dₖ, row-wise softmax converts them into weights that sum to one, and those weights average the value vectors. The code implements these stages with maximum subtraction for numerical stability. Compatible nonempty query/key widths…

Implementation mathematicsSource recovered; runtime not executed
Learn with the Atlas

Understand the scale

See what normalization changes and which assumptions it introduces.

Open guided lesson
gh-eq-c0778786b7e82cf5source-comment-equation
Attention(Q,K,V)=softmax(QKT/√dk)VAttention(Q,K,V) = softmax(QK^T/√d_k)V

Read the equation

Query-key dot products are divided by √dₖ, row-wise softmax converts them into weights that sum to one, and those weights average the value vectors. The code implements these stages with maximum subtraction for numerical stability. Compatible nonempty query/key widths and matching key/value counts are needed for the standard interpretation.

This exact expression also occurs in another recovered revision. Its mathematical annotation is shared; the source references below preserve this occurrence.

Terms & definitions

TermMeaning in this source
Q

Query matrix

K

Key matrix

V

Value matrix

d_k

Query/key feature width

How it works

Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.

Assumptions & limits

Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.

Original context

Read the surrounding source passage
template<size_t SEQ_LEN, size_t DIM>
struct Attention {
    // Attention weights after softmax
    float weights[SEQ_LEN][SEQ_LEN];

    // Compute attention
    // Attention(Q,K,V) = softmax(QK^T/√d_k)V
    void compute(const float Q[][DIM], const float K[][DIM], const float V[][DIM],
                 float output[][DIM]) {
        float scale = 1.0f / std::sqrt(static_cast<float>(DIM));

        // Compute QK^T
        for (size_t i = 0; i < SEQ_LEN; ++i) {
            for (size_t j = 0; j < SEQ_LEN; ++j) {
                float dot = 0.0f;
                for (size_t k = 0; k < DIM; ++k) {
                    dot += Q[i][k] * K[j][k];
Exact original notation
Attention(Q,K,V) = softmax(QK^T/√d_k)V

Related builds

Related mathematical records

Sources & provenance

02
Go mathematical helpers
Lines 399–399 · 33aa84f2aa61

Search equations, builds, manuscript text, and recovered sources.