text stringlengths 0 2.2M |
|---|
// remap actual, predicted targets for evaluating edit distance error
|
auto ltrPred = tknPrediction2Ltr(
|
viterbipath,
|
tokenDict,
|
FLAGS_criterion,
|
FLAGS_surround,
|
false, /* isSeq2seqCrit */
|
FLAGS_replabel,
|
FLAGS_usewordpiece,
|
FLAGS_wordseparator);
|
auto ltrTgt = tknTarget2Ltr(
|
tgtraw,
|
tokenDict,
|
FLAGS_criterion,
|
FLAGS_surround,
|
false, /* isSeq2seqCrit */
|
FLAGS_replabel,
|
FLAGS_usewordpiece,
|
FLAGS_wordseparator);
|
auto wrdPred = tkn2Wrd(ltrPred, FLAGS_wordseparator);
|
auto wrdTgt = tkn2Wrd(ltrTgt, FLAGS_wordseparator);
|
mtr.tknEdit.add(ltrPred, ltrTgt);
|
mtr.wrdEdit.add(wrdPred, wrdTgt);
|
}
|
};
|
auto test = [&evalOutput](
|
std::shared_ptr<fl::Module> ntwrk,
|
std::shared_ptr<SequenceCriterion> crit,
|
std::shared_ptr<fl::Dataset> validds,
|
DatasetMeters& mtrs) {
|
ntwrk->eval();
|
mtrs.tknEdit.reset();
|
mtrs.wrdEdit.reset();
|
mtrs.loss.reset();
|
auto curValidset = loadPrefetchDataset(
|
validds, FLAGS_nthread, false /* shuffle */, 0 /* seed */);
|
for (auto& batch : *curValidset) {
|
auto output = fl::pkg::runtime::forwardSequentialModuleWithPadMask(
|
fl::input(batch[kInputIdx]), ntwrk, batch[kDurationIdx]);
|
auto loss =
|
crit->forward({output, fl::Variable(batch[kTargetIdx], false)})
|
.front();
|
mtrs.loss.add(loss.array());
|
evalOutput(output.array(), batch[kTargetIdx], mtrs);
|
}
|
};
|
int64_t curEpoch = startEpoch;
|
auto train = [&meters,
|
&test,
|
&logStatus,
|
&saveModels,
|
&evalOutput,
|
&validds,
|
&curEpoch,
|
&startUpdate,
|
reducer](
|
std::shared_ptr<fl::Module> ntwrk,
|
std::shared_ptr<SequenceCriterion> crit,
|
std::shared_ptr<fl::Dataset> trainset,
|
std::shared_ptr<fl::FirstOrderOptimizer> netopt,
|
double initlr,
|
int64_t nbatches) {
|
if (reducer) {
|
fl::distributeModuleGrads(ntwrk, reducer);
|
}
|
meters.train.loss.reset();
|
meters.train.tknEdit.reset();
|
meters.train.wrdEdit.reset();
|
std::shared_ptr<fl::Module> saug;
|
if (FLAGS_saug_start_update >= 0) {
|
saug = std::make_shared<fl::SpecAugment>(
|
FLAGS_filterbanks,
|
FLAGS_saug_fmaskf,
|
FLAGS_saug_fmaskn,
|
FLAGS_saug_tmaskt,
|
FLAGS_saug_tmaskp,
|
FLAGS_saug_tmaskn);
|
}
|
fl::allReduceParameters(ntwrk);
|
auto resetTimeStatMeters = [&meters]() {
|
meters.runtime.reset();
|
meters.stats.reset();
|
meters.sampletimer.reset();
|
meters.fwdtimer.reset();
|
meters.critfwdtimer.reset();
|
meters.bwdtimer.reset();
|
meters.optimtimer.reset();
|
meters.timer.reset();
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.