Skip to content

Commit

Permalink
Parallelizing FST construction.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673078224
  • Loading branch information
agutkin authored and copybara-github committed Sep 10, 2024
1 parent 41bf645 commit a3f05ab
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions nisaba/translit/fst/pairlm_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,11 +993,18 @@ StdVectorFst PairLMDecoder::BuildTransliterationFst(
const std::vector<std::string> input_words = absl::StrSplit(
input_line, utf8::Utf8WhitespaceDelimiter(), absl::SkipEmpty());
std::vector<StdVectorFst> translit_fsts(input_words.size());
// TODO: Fix parallelization.
{
ThreadPool pool(max_parallel_tokens_);
pool.StartWorkers();
for (int i = 0; i < input_words.size(); ++i) {
translit_fsts[i] = TransliterateWord(input_words[i], word_k_best,
fst_params);
pool.Schedule([this, i, word_k_best, &translit_fsts, &input_words,
&fst_params] {
translit_fsts[i] = TransliterateWord(input_words[i], word_k_best,
fst_params);
});
}
// Wait until all threads are complete.
}

// Loop through the fsts produced, joining them into a sentence lattice.
for (int i = 0; i < input_words.size(); ++i) {
Expand Down

0 comments on commit a3f05ab

Please sign in to comment.