githubharald / CTCWordBeamSearch

Connectionist Temporal Classification (CTC) decoder with dictionary and language model.

Home Page:https://harald-scheidl.medium.com/b051d28f3d2e

Repository from Github https://github.comgithubharald/CTCWordBeamSearchRepository from Github https://github.comgithubharald/CTCWordBeamSearch

Getting Top-N results from Beam Search

amitbcp opened this issue · comments

I had a slightly different usecase, where I wanted the Top-N results from Beam Search and not just the best one.
I was trying to modify the word_beam_search CPP implementation as I am using the Numpy (Python Implementation)

Can you please help me on the changes so that I can get top N(N=beamwidth) results, when I use : wbs.compute() function ?

  1. instead of just taking the single best beam, return the best N beams, i.e. last.getBestBeams(N), and change the function signature to std::vector<std::vector<uint32_t>> ..., which means a list of beams, each containing the decoded characters:
    https://github.com/githubharald/CTCWordBeamSearch/blob/master/cpp/src/WordBeamSearch.cpp#L65

  2. here's the line where the return value passed to Python is built - you need a std::vector<std::vector<std::vector<uint32_t>>> both in the function signature and in the res variable, that is a list of batches of beams of characters:
    https://github.com/githubharald/CTCWordBeamSearch/blob/master/cpp/src/NPWordBeamSearch.cpp#L94

Thanks for the help. I will make the changes as per your suggestions and updated the issue.

I'll close this issue for now because of inactivity - but you can re-open it if needed.