online-nnet3-decoding.cc
Go to the documentation of this file.
1 // online2/online-nnet3-decoding.cc
2 
3 // Copyright 2013-2014 Johns Hopkins University (author: Daniel Povey)
4 // 2016 Api.ai (Author: Ilya Platonov)
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
22 #include "lat/lattice-functions.h"
24 #include "decoder/grammar-fst.h"
25 
26 namespace kaldi {
27 
28 template <typename FST>
30  const LatticeFasterDecoderConfig &decoder_opts,
31  const TransitionModel &trans_model,
33  const FST &fst,
34  OnlineNnet2FeaturePipeline *features):
35  decoder_opts_(decoder_opts),
36  input_feature_frame_shift_in_seconds_(features->FrameShiftInSeconds()),
37  trans_model_(trans_model),
38  decodable_(trans_model_, info,
39  features->InputFeature(), features->IvectorFeature()),
40  decoder_(fst, decoder_opts_) {
41  decoder_.InitDecoding();
42 }
43 
44 template <typename FST>
46  decoder_.InitDecoding();
47  decodable_.SetFrameOffset(frame_offset);
48 }
49 
50 template <typename FST>
52  decoder_.AdvanceDecoding(&decodable_);
53 }
54 
55 template <typename FST>
57  decoder_.FinalizeDecoding();
58 }
59 
60 template <typename FST>
62  return decoder_.NumFramesDecoded();
63 }
64 
65 template <typename FST>
67  CompactLattice *clat) const {
68  if (NumFramesDecoded() == 0)
69  KALDI_ERR << "You cannot get a lattice if you decoded no frames.";
70  Lattice raw_lat;
71  decoder_.GetRawLattice(&raw_lat, end_of_utterance);
72 
74  KALDI_ERR << "--determinize-lattice=false option is not supported at the moment";
75 
78  trans_model_, &raw_lat, lat_beam, clat, decoder_opts_.det_opts);
79 }
80 
81 template <typename FST>
83  Lattice *best_path) const {
84  decoder_.GetBestPath(best_path, end_of_utterance);
85 }
86 
87 template <typename FST>
89  const OnlineEndpointConfig &config) {
90  BaseFloat output_frame_shift =
94  output_frame_shift, decoder_);
95 }
96 
97 
98 // Instantiate the template for the types needed.
101 
102 } // namespace kaldi
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
kaldi::int32 int32
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...
SingleUtteranceNnet3DecoderTpl(const LatticeFasterDecoderConfig &decoder_opts, const TransitionModel &trans_model, const nnet3::DecodableNnetSimpleLoopedInfo &info, const FST &fst, OnlineNnet2FeaturePipeline *features)
void InitDecoding(int32 frame_offset=0)
Initializes the decoding and sets the frame offset of the underlying decodable object.
const LatticeFasterDecoderConfig & decoder_opts_
void GetLattice(bool end_of_utterance, CompactLattice *clat) const
Gets the lattice.
bool EndpointDetected(const OnlineEndpointConfig &config)
This function calls EndpointDetected from online-endpoint.h, with the required arguments.
You will instantiate this class when you want to decode a single utterance using the online-decoding ...
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
void GetBestPath(bool end_of_utterance, Lattice *best_path) const
Outputs an FST corresponding to the single best path through the current lattice. ...
nnet3::DecodableAmNnetLoopedOnline decodable_
fst::DeterminizeLatticePhonePrunedOptions det_opts
LatticeFasterOnlineDecoderTpl< FST > decoder_
OnlineNnet2FeaturePipeline is a class that&#39;s responsible for putting together the various parts of th...
void AdvanceDecoding()
Advances the decoding as far as we can.
When you instantiate class DecodableNnetSimpleLooped, you should give it a const reference to this cl...
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...
void SetFrameOffset(int32 frame_offset)
Sets the frame offset value.
void FinalizeDecoding()
Finalizes the decoding.