Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      73 of 88

      Distance, not place

      Attention scores how much one word listens to another with a dot product: the first word’s query (what it looks for) times the other’s key (what it offers), as in “Who should “it” listen to?”. On their own they don’t say where the words are. Write tag(vector, position): change a 2D query or key so it includes its word’s position, such that the score between a query at i and a key at j depends only on how far apart they are, not on where in the sentence they sit.

      a query
      xy
      21
      a key
      xy
      12
      their score: 2·1 + 1·2
      4
      solution.pyLoading Python
      ← Word order mattersSoftmax on the go →