Skip to content

Add scaled dot-product self-attention (single head) #8

Description

@ThomasHartDev

The repo already covers autograd, linear/logistic regression, an MLP with hand-written backprop, activations/init, and first-order optimizers. The next building block toward a tiny transformer is the attention formula itself.

Goal

Implement scaled dot-product self-attention for a single head in numpy only: softmax(Q Kᵀ / √d_k) V, with optional causal masking, a SelfAttentionHead that projects the same sequence into Q/K/V, and pytest coverage for shapes, scale, masks, and edge cases (empty / single token).

Why

Attention is the core of modern transformers. Showing the math without a framework is the point of this lab.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions