Constrained Decoding with a Token Trie

hard
Unit 28 · Tokenization0/0 to milestone

To guarantee an LLM outputs one of a fixed set of labels ("positive", "negative", "neutral"), constrained decoding masks out every token that can't lead to a valid answer.

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
Constrained Decoding with a Token Trie · TechGradify