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

      Softmax on the go

      Softmax (“Scores into chances”) divides each exp(score) by the total of them all. Scores now arrive one at a time and can’t be kept, so keep a small state instead: [biggest, total], the biggest score so far and total = Σ exp(score − biggest) over the scores so far, measured from that biggest one so nothing overflows. Before the first score the state is None. Write update(state, score): the new state after one more score arrives.

      Scores arrive one at a time and drop off the end: they can’t be kept. All that stays is a two-slot memory, the biggest score so far and a running total. Watch the scores go by, then say what the total should hold.

      Score undefined is gone. Biggest so far: null. Next: undefined.scores, one at a time →off the end: gone for good2−1gone by: 2, −1memory: all you can keepbiggest so far—total?update(state, score), score after score: what’s the total after the 3rd score?
      Your functionupdate(state, score)
      state[biggest score so far, total of exp(s - biggest)], or None at the starte.g. None
      scorethe score that just arrivede.g. 3
      returnsthe new state
      solution.pyLoading Python
      Sign in for an AI hint
      ← Distance, not placeThe greedy trap →