Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Implementing Multi-Head Attention | Section
Transformer Architecture

bookChallenge: Implementing Multi-Head Attention

Sveip for å vise menyen

Task

You have all the building blocks: scaled dot-product attention from the previous challenge, and the intuition behind multiple heads from the last chapter. Now put them together.

Implement a MultiHeadAttention module as an nn.Module class. It should:

  1. Accept d_model and num_heads as constructor arguments – assert that d_model % num_heads == 0;
  2. Define separate linear projections for Q, K, V, and a final output projection;
  3. In forward(x), split the projections into num_heads heads of dimension d_model // num_heads;
  4. Run scaled dot-product attention independently per head;
  5. Concatenate the head outputs and pass through the output projection.

Implement the module locally.

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 5

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 1. Kapittel 5
some-alt