online-nnet2-decoding.cc
Go to the documentation of this file.
1 // online2/online-nnet2-decoding.cc
2 
3 // Copyright 2013-2014 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
21 #include "lat/lattice-functions.h"
23 
24 namespace kaldi {
25 
27  const OnlineNnet2DecodingConfig &config,
28  const TransitionModel &tmodel,
29  const nnet2::AmNnet &model,
30  const fst::Fst<fst::StdArc> &fst,
31  OnlineFeatureInterface *feature_pipeline):
32  config_(config),
33  feature_pipeline_(feature_pipeline),
34  tmodel_(tmodel),
35  decodable_(model, tmodel, config.decodable_opts, feature_pipeline),
36  decoder_(fst, config.decoder_opts) {
38 }
39 
42 }
43 
46 }
47 
49  return decoder_.NumFramesDecoded();
50 }
51 
52 void SingleUtteranceNnet2Decoder::GetLattice(bool end_of_utterance,
53  CompactLattice *clat) const {
54  if (NumFramesDecoded() == 0)
55  KALDI_ERR << "You cannot get a lattice if you decoded no frames.";
56  Lattice raw_lat;
57  decoder_.GetRawLattice(&raw_lat, end_of_utterance);
58 
60  KALDI_ERR << "--determinize-lattice=false option is not supported at the moment";
61 
64  tmodel_, &raw_lat, lat_beam, clat, config_.decoder_opts.det_opts);
65 }
66 
67 void SingleUtteranceNnet2Decoder::GetBestPath(bool end_of_utterance,
68  Lattice *best_path) const {
69  decoder_.GetBestPath(best_path, end_of_utterance);
70 }
71 
73  const OnlineEndpointConfig &config) {
74  return kaldi::EndpointDetected(config, tmodel_,
76  decoder_);
77 }
78 
79 
80 } // namespace kaldi
81 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void FinalizeDecoding()
Finalizes the decoding.
bool GetRawLattice(Lattice *ofst, bool use_final_probs=true) const
Outputs an FST corresponding to the raw, state-level tracebacks.
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
OnlineFeatureInterface * feature_pipeline_
kaldi::int32 int32
void FinalizeDecoding()
This function may be optionally called after AdvanceDecoding(), when you do not plan to decode any fu...
bool EndpointDetected(const OnlineEndpointConfig &config, int32 num_frames_decoded, int32 trailing_silence_frames, BaseFloat frame_shift_in_seconds, BaseFloat final_relative_cost)
This function returns true if this set of endpointing rules thinks we should terminate decoding...
void AdvanceDecoding()
advance the decoding as far as we can.
void InitDecoding()
InitDecoding initializes the decoding, and should only be used if you intend to call AdvanceDecoding(...
void GetBestPath(bool end_of_utterance, Lattice *best_path) const
Outputs an FST corresponding to the single best path through the current lattice. ...
void GetLattice(bool end_of_utterance, CompactLattice *clat) const
Gets the lattice.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
virtual BaseFloat FrameShiftInSeconds() const =0
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
fst::DeterminizeLatticePhonePrunedOptions det_opts
void AdvanceDecoding(DecodableInterface *decodable, int32 max_num_frames=-1)
This will decode until there are no more frames ready in the decodable object.
LatticeFasterDecoderConfig decoder_opts
OnlineFeatureInterface is an interface for online feature processing (it is also usable in the offlin...
SingleUtteranceNnet2Decoder(const OnlineNnet2DecodingConfig &config, const TransitionModel &tmodel, const nnet2::AmNnet &model, const fst::Fst< fst::StdArc > &fst, OnlineFeatureInterface *feature_pipeline)
bool GetBestPath(Lattice *ofst, bool use_final_probs=true) const
Outputs an FST corresponding to the single best path through the lattice.
nnet2::DecodableNnet2Online decodable_
bool EndpointDetected(const OnlineEndpointConfig &config)
This function calls EndpointDetected from online-endpoint.h, with the required arguments.
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...