Unigram Tokenization with Viterbi

hard
Unit 29 · Safety0/0 to milestone

SentencePiece's Unigram tokenizer (used by T5, ALBERT and XLNet) gives each vocabulary piece a log-probability, and tokenizes a string by choosing the segmentation with the highest total log-probability. Finding it is a shortest-path problem solved with the Viterbi algorithm.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Unigram Tokenization with Viterbi · TechGradify