'Test one batch, two beams - hibernating beam search.'

def test_ctc_decode_beam_search(self):

    depth = 6
    seq_len_0 = 5
    input_prob_matrix_0 = np.asarray([[0.30999, 0.309938, 0.0679938, 0.0673362, 0.0708352, 0.173908], [0.215136, 0.439699, 0.0370931, 0.0393967, 0.0381581, 0.230517], [0.199959, 0.489485, 0.0233221, 0.0251417, 0.0233289, 0.238763], [0.279611, 0.452966, 0.0204795, 0.0209126, 0.0194803, 0.20655], [0.51286, 0.288951, 0.0243026, 0.0220788, 0.0219297, 0.129878], [0.155251, 0.164444, 0.173517, 0.176138, 0.169979, 0.160671]], dtype=np.float32)
    inputs = ([input_prob_matrix_0[t, :][np.newaxis, :] for t in range(seq_len_0)] + (2 * [np.zeros((1, depth), dtype=np.float32)]))
    inputs = KTF.variable(np.asarray(inputs).transpose((1, 0, 2)))
    input_length = KTF.variable(np.array([seq_len_0], dtype=np.int32))
    log_prob_truth = np.array([0.584855, 0.389139], np.float32)[np.newaxis, :]
    decode_truth = [np.array([1, 0]), np.array([0, 1, 0])]
    beam_width = 2
    top_paths = 2
    (decode_pred_tf, log_prob_pred_tf) = KTF.ctc_decode(inputs, input_length, greedy=False, beam_width=beam_width, top_paths=top_paths)
    assert (len(decode_pred_tf) == top_paths)
    log_prob_pred = KTF.eval(log_prob_pred_tf)
    for i in range(top_paths):
        assert np.alltrue((decode_truth[i] == KTF.eval(decode_pred_tf[i])))
    assert np.allclose(log_prob_truth, log_prob_pred)
