NumPy allowed · plain Python earns 10 bonus points
Q · Kᵀ / √d scores normalized with softmax
Implement WordPiece's real greedy longest-match-first tokenization algorithm (used by BERT), splitting an out-of-vocabulary word into known subword pieces.
Implement wordpiece_tokenize(word, vocab, unk_token). Starting from position 0, greedily find the LONGEST prefix of the remaining substring that's in vocab (for positions after the first, the candidate must be prefixed with '##' before checking vocab membership). If no valid piece is found at any position, return [unk_token] for the WHOLE word (not partial pieces).
wordpiece_tokenize(word: str, vocab: set, unk_token: str) -> list[str]