Skip to content

Connectionist Temporal Classification (CTC) decoding algorithms: best path, beam search

Notifications You must be signed in to change notification settings

N-damo/CTCBeamSearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

CTCBeamSearch is a C++ 17 header only library meant for Connectionist Temporal Classification (CTC) decoding algorithms.

Usage

#include "beam_search.hpp"
#include <random>

using namespace std;



int main()
{
	string alphabet = "NACGT";
	size_t beam_size = 5;
	float beam_cut_threshold = 0.1f;
	bool collapse_repeats = true;
	pair<string, vector<int>> r;

	constexpr int n_steps_in = 1200;
	constexpr int alphabet_size = 5;

	float posteriors[n_steps_in][alphabet_size];

	//std::random_device rd;
	std::mt19937 gen(0);
	std::uniform_real_distribution<float> dis(0.0, 1.0);

	// Generate random posteriors
	for (int i = 0; i < n_steps_in; ++i) {
		for (int j = 0; j < alphabet_size; ++j) {
			posteriors[i][j] = dis(gen);
		}
	}

	clock_t start, end;

	start = clock();
	beam_search(posteriors[0], n_steps_in, alphabet, beam_size, beam_cut_threshold, collapse_repeats, r);
	end = clock();
	auto endtime = (double)(end - start) / CLOCKS_PER_SEC;
	cout << "Time:" << endtime * 1000000 << " us" << endl;

	if(r.first.size() != 0);
	{
		cout << r.first << endl;
		for (auto& d : r.second)
		{
			printf("%d,", d);
		}
		cout << endl;
	}
	return 0;
}

Licence and Copyright

CTCBeamSearch are revised based on fast_ctc_decode following MIT license. If a copy of the License was not distributed with this file, You can obtain one at https://github.com/nanoporetech/fast-ctc-decode/

About

Connectionist Temporal Classification (CTC) decoding algorithms: best path, beam search

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published