text
stringlengths 0
2.2M
|
---|
// ctc expects the blank label last
|
if (FLAGS_criterion == kCtcCriterion) {
|
tokenDict.addEntry(kBlankToken);
|
} else {
|
LOG(FATAL) << "CTC-trained model required for VAD-CTC.";
|
}
|
int numClasses = tokenDict.indexSize();
|
LOG(INFO) << "Number of classes (network): " << numClasses;
|
fl::lib::text::Dictionary wordDict;
|
text::LexiconMap lexicon;
|
if (!FLAGS_lexicon.empty()) {
|
lexicon = text::loadWords(FLAGS_lexicon, FLAGS_maxword);
|
wordDict = text::createWordDict(lexicon);
|
LOG(INFO) << "Number of words: " << wordDict.indexSize();
|
wordDict.setDefaultIndex(wordDict.getIndex(text::kUnkToken));
|
}
|
/* ===================== Create Dataset ===================== */
|
fl::lib::audio::FeatureParams featParams(
|
FLAGS_samplerate,
|
FLAGS_framesizems,
|
FLAGS_framestridems,
|
FLAGS_filterbanks,
|
FLAGS_lowfreqfilterbank,
|
FLAGS_highfreqfilterbank,
|
FLAGS_mfcccoeffs,
|
kLifterParam /* lifterparam */,
|
FLAGS_devwin /* delta window */,
|
FLAGS_devwin /* delta-delta window */);
|
featParams.useEnergy = false;
|
featParams.usePower = false;
|
featParams.zeroMeanFrame = false;
|
FeatureType featType =
|
getFeatureType(FLAGS_features_type, FLAGS_channels, featParams).second;
|
TargetGenerationConfig targetGenConfig(
|
FLAGS_wordseparator,
|
FLAGS_sampletarget,
|
FLAGS_criterion,
|
FLAGS_surround,
|
false /* isSeq2SeqCrit */,
|
FLAGS_replabel,
|
true /* skip unk */,
|
FLAGS_usewordpiece /* fallback2LetterWordSepLeft */,
|
!FLAGS_usewordpiece /* fallback2LetterWordSepLeft */);
|
auto inputTransform = inputFeatures(
|
featParams,
|
featType,
|
{FLAGS_localnrmlleftctx, FLAGS_localnrmlrightctx},
|
{});
|
auto targetTransform = targetFeatures(tokenDict, lexicon, targetGenConfig);
|
auto wordTransform = wordFeatures(wordDict);
|
int targetpadVal = kTargetPadValue;
|
int wordpadVal = kTargetPadValue;
|
auto ds = createDataset(
|
{FLAGS_test},
|
FLAGS_datadir,
|
1,
|
inputTransform,
|
targetTransform,
|
wordTransform,
|
std::make_tuple(0, targetpadVal, wordpadVal),
|
0,
|
1);
|
LOG(INFO) << "[Dataset] Dataset loaded.";
|
/* ===================== Build LM ===================== */
|
std::shared_ptr<text::LM> lm;
|
if (!FLAGS_lm.empty()) {
|
if (FLAGS_lmtype == "kenlm") {
|
lm = std::make_shared<text::KenLM>(FLAGS_lm, wordDict);
|
if (!lm) {
|
throw std::runtime_error(
|
"[LM constructing] Failed to load LM: " + FLAGS_lm);
|
}
|
} else {
|
throw std::runtime_error(
|
"[LM constructing] Invalid LM Type: " + FLAGS_lmtype);
|
}
|
}
|
/* ===================== Test ===================== */
|
int cnt = 0;
|
auto prefetchds =
|
loadPrefetchDataset(ds, FLAGS_nthread, false /* shuffle */, 0 /* seed */);
|
for (auto& sample : *prefetchds) {
|
auto rawEmission = fl::pkg::runtime::forwardSequentialModuleWithPadMask(
|
fl::input(sample[kInputIdx]), network, sample[kDurationIdx]);
|
auto sampleId = readSampleIds(sample[kSampleIdx]).front();
|
LOG(INFO) << "Processing sample ID " << sampleId;
|
// Hypothesis
|
auto tokenPrediction =
|
afToVector<int>(criterion->viterbiPath(rawEmission.array()));
|
auto letterPrediction = tknPrediction2Ltr(
|
tokenPrediction,
|
tokenDict,
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.