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

      Merge the most common pair

      Language models read text as symbols, and a tokenizer invents them: it starts with single letters and keeps gluing two neighbours into a new symbol, so common chunks of text take fewer symbols. Write merge_once(tokens): add one new symbol, two neighbouring symbols glued together, chosen to make the text as short as possible, and glue it everywhere it fits, left to right. If two pairs would do equally well, take the one that shows up first in the text.

      “hug_pug_hugs” is 12 symbols. Glue one kind of neighbour pair into a new symbol, everywhere it fits, and the text gets shorter. Watch two pairs tried, then try your own: which pair leaves the fewest symbols?

      The text, as 12 single-letter symbols. Glue one kind of neighbour pair into a new symbol.the text · 12 symbolshug_pug_hugswhich pair leaves the fewest symbols? “? ?”
      Your functionmerge_once(tokens)
      tokensa list of symbols, like ["h", "u", "g", "_", "p", "u", "g"] glue ONE kind of neighbour pair into a new symbol, everywhere it fitse.g. ["a"]
      returnsthe new list of symbols
      solution.pyLoading Python
      Sign in for an AI hint
      ← Find the patchWho should “it” listen to? →