githubharald / CTCDecoder

Connectionist Temporal Classification (CTC) decoding algorithms: best path, beam search, lexicon search, prefix search, and token passing. Implemented in Python.
https://towardsdatascience.com/3797e43a86c
MIT License
817 stars 182 forks source link

beam_search with a beam_width=1 #26

Closed skalinin closed 2 years ago

skalinin commented 2 years ago

Hi! Could you please tell, why does a beam_search with a beam_width equal to 1 not give the same result as best_path?

For example

import numpy as np
from ctc_decoder import best_path, beam_search

chars = 'ab'
mat = np.array([[0.8, 0, 0.2], [0.4, 0.0, 0.6], [0.8, 0, 0.2]])

print(f'Best path: "{best_path(mat, chars)}"')
print(f'Beam search: "{beam_search(mat, chars, beam_width=1)}"')

Gives: Best path: "aa" Beam search: "a"

Thanks!

githubharald commented 2 years ago

because it's not the same algorithm and is not expected to give the same results (even though TF says so in its documentation, which is wrong, see here: https://github.com/tensorflow/tensorflow/issues/21051).

skalinin commented 2 years ago

Thanks for the answer!