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
      85 of 102

      Don’t peek

      Like in “Who should “it” listen to?”, a word scores how well every word’s key matches its query and turns the scores into shares of its attention. But now the text is being written one word at a time, left to right: when the word at position reads, the words after it don’t exist yet. Write listen(query, keys, position): one share per word in the whole sentence, future words included.

      The text is written one word at a time. When “sat” (position 1) reads, it looks for a place, [0, 1], and “mat” hasn’t been written yet. How should it share out its attention, one share per word in the whole sentence?

      The text is written one word at a time, left to right.·?not written yet?not written yet··?not written yet“sat” has 100% of its attention to share out: how much to each word?
      Your functionlisten(query, keys, position)
      querywhat the word at `position` is looking fore.g. [0, 1]
      keysone row per word of the sentence, what each word ise.g. [[2, 0], [0, 0], [0, 2]]
      positionwhich word is reading (0 = the first word)e.g. 1
      returnsone share per word, future words included
      solution.pyLoading Python
      Sign in for an AI hint
      ← Listen and collectWord order matters →