Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-200

CTC Greedy Decode

Problem

Greedily decode CTC frames: take the argmax index of each frame with ties keeping the lowest index, collapse consecutive repeats, and remove every blank_index token.

Return the remaining indices as a list. An empty frame list decodes to an empty list.

Hint

Collapse after taking argmax, and treat a blank between repeats as a separator.

Test cases

case 1
in: [[[0.1,0.7,0.2],[0.1,0.8,0.1],[0.1,0.2,0.7],[0.9,0.05,0.05]]]
expected: [1,2]
case 2
in: [[[0.1,0.6,0.3]]]
expected: [1]
case 3
in: [[[0.9,0.1,0],[0.8,0.1,0.1]]]
expected: []
case 4
in: [[]]
expected: []
case 5
in: [[[0.1,0.2,0.7],[0.1,0.7,0.2],[0.1,0.7,0.2]]]
expected: [2,1]
Starter codePython
def ctc_greedy_decode(frames, blank_index=0):
    # Your code here
    pass

5 test cases · run your code against them in the editor