All problems
Greedy Decoding
Problem
Decode one token per probability row by taking the argmax, breaking ties toward the smallest vocabulary index.
Stop before appending eos when the argmax token is eos, and return the generated tokens. An empty probability list yields an empty result.
Hint
Ties keep the earlier vocabulary index because only strictly greater values replace the best.
Test cases
case 1
in: [["a","b","</s>"],[[0.1,0.7,0.2],[0.6,0.3,0.1],[0.1,0.1,0.8]],"</s>"]
expected: ["b","a"]
case 2
in: [["a","b","</s>"],[[0.1,0.2,0.7]],"</s>"]
expected: []
case 3
in: [["a","b","</s>"],[[0.5,0.5,0],[0.2,0.6,0.2]],"</s>"]
expected: ["a","b"]
case 4
in: [["x","y"],[],"z"]
expected: []
Starter codePython
def greedy_decode(vocab, probs, eos):
# Your code here
pass4 test cases · run your code against them in the editor