lattice-functions.h File Reference
#include <vector>
#include <map>
#include "base/kaldi-common.h"
#include "hmm/posterior.h"
#include "fstext/fstext-lib.h"
#include "hmm/transition-model.h"
#include "lat/kaldi-lattice.h"
#include "itf/decodable-itf.h"
Include dependency graph for lattice-functions.h:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

void GetPerFrameAcousticCosts (const Lattice &nbest, Vector< BaseFloat > *per_frame_loglikes)
 This function extracts the per-frame log likelihoods from a linear lattice (which we refer to as an 'nbest' lattice elsewhere in Kaldi code). More...
 
int32 LatticeStateTimes (const Lattice &lat, std::vector< int32 > *times)
 This function iterates over the states of a topologically sorted lattice and counts the time instance corresponding to each state. More...
 
int32 CompactLatticeStateTimes (const CompactLattice &clat, std::vector< int32 > *times)
 As LatticeStateTimes, but in the CompactLattice format. More...
 
BaseFloat LatticeForwardBackward (const Lattice &lat, Posterior *arc_post, double *acoustic_like_sum=NULL)
 This function does the forward-backward over lattices and computes the posterior probabilities of the arcs. More...
 
bool ComputeCompactLatticeAlphas (const CompactLattice &lat, std::vector< double > *alpha)
 
bool ComputeCompactLatticeBetas (const CompactLattice &lat, std::vector< double > *beta)
 
template<typename LatticeType >
double ComputeLatticeAlphasAndBetas (const LatticeType &lat, bool viterbi, std::vector< double > *alpha, std::vector< double > *beta)
 
void TopSortCompactLatticeIfNeeded (CompactLattice *clat)
 Topologically sort the compact lattice if not already topologically sorted. More...
 
void TopSortLatticeIfNeeded (Lattice *clat)
 Topologically sort the lattice if not already topologically sorted. More...
 
BaseFloat CompactLatticeDepth (const CompactLattice &clat, int32 *num_frames)
 Returns the depth of the lattice, defined as the average number of arcs crossing any given frame. More...
 
void CompactLatticeDepthPerFrame (const CompactLattice &clat, std::vector< int32 > *depth_per_frame)
 This function returns, for each frame, the number of arcs crossing that frame. More...
 
void CompactLatticeLimitDepth (int32 max_arcs_per_frame, CompactLattice *clat)
 This function limits the depth of the lattice, per frame: that means, it does not allow more than a specified number of arcs active on any given frame. More...
 
void LatticeActivePhones (const Lattice &lat, const TransitionModel &trans, const std::vector< int32 > &sil_phones, std::vector< std::set< int32 > > *active_phones)
 Given a lattice, and a transition model to map pdf-ids to phones, outputs for each frame the set of phones active on that frame. More...
 
void ConvertLatticeToPhones (const TransitionModel &trans_model, Lattice *lat)
 Given a lattice, and a transition model to map pdf-ids to phones, replace the output symbols (presumably words), with phones; we use the TransitionModel to work out the phone sequence. More...
 
template<class LatticeType >
bool PruneLattice (BaseFloat beam, LatticeType *lat)
 Prunes a lattice or compact lattice. More...
 
void ConvertCompactLatticeToPhones (const TransitionModel &trans_model, CompactLattice *clat)
 Given a lattice, and a transition model to map pdf-ids to phones, replace the sequences of transition-ids with sequences of phones. More...
 
bool LatticeBoost (const TransitionModel &trans, const std::vector< int32 > &alignment, const std::vector< int32 > &silence_phones, BaseFloat b, BaseFloat max_silence_error, Lattice *lat)
 Boosts LM probabilities by b * [number of frame errors]; equivalently, adds -b*[number of frame errors] to the graph-component of the cost of each arc/path. More...
 
BaseFloat LatticeForwardBackwardMpeVariants (const TransitionModel &trans, const std::vector< int32 > &silence_phones, const Lattice &lat, const std::vector< int32 > &num_ali, std::string criterion, bool one_silence_class, Posterior *post)
 This function implements either the MPFE (minimum phone frame error) or SMBR (state-level minimum bayes risk) forward-backward, depending on whether "criterion" is "mpfe" or "smbr". More...
 
BaseFloat LatticeForwardBackwardMmi (const TransitionModel &trans, const Lattice &lat, const std::vector< int32 > &num_ali, bool drop_frames, bool convert_to_pdf_ids, bool cancel, Posterior *arc_post)
 This function can be used to compute posteriors for MMI, with a positive contribution for the numerator and a negative one for the denominator. More...
 
bool CompactLatticeToWordAlignment (const CompactLattice &clat, std::vector< int32 > *words, std::vector< int32 > *begin_times, std::vector< int32 > *lengths)
 This function takes a CompactLattice that should only contain a single linear sequence (e.g. More...
 
bool CompactLatticeToWordProns (const TransitionModel &tmodel, const CompactLattice &clat, std::vector< int32 > *words, std::vector< int32 > *begin_times, std::vector< int32 > *lengths, std::vector< std::vector< int32 > > *prons, std::vector< std::vector< int32 > > *phone_lengths)
 This function takes a CompactLattice that should only contain a single linear sequence (e.g. More...
 
void CompactLatticeShortestPath (const CompactLattice &clat, CompactLattice *shortest_path)
 A form of the shortest-path/best-path algorithm that's specially coded for CompactLattice. More...
 
void AddWordInsPenToCompactLattice (BaseFloat word_ins_penalty, CompactLattice *clat)
 This function add the word insertion penalty to graph score of each word in the compact lattice. More...
 
bool RescoreCompactLattice (DecodableInterface *decodable, CompactLattice *clat)
 This function *adds* the negated scores obtained from the Decodable object, to the acoustic scores on the arcs. More...
 
int32 LongestSentenceLength (const Lattice &lat)
 This function returns the number of words in the longest sentence in a CompactLattice (i.e. More...
 
int32 LongestSentenceLength (const CompactLattice &lat)
 This function returns the number of words in the longest sentence in a CompactLattice, i.e. More...
 
bool RescoreCompactLatticeSpeedup (const TransitionModel &tmodel, BaseFloat speedup_factor, DecodableInterface *decodable, CompactLattice *clat)
 This function is like RescoreCompactLattice, but it is modified to avoid computing probabilities on most frames where all the pdf-ids are the same. More...
 
bool RescoreLattice (DecodableInterface *decodable, Lattice *lat)
 This function *adds* the negated scores obtained from the Decodable object, to the acoustic scores on the arcs. More...
 
void ComposeCompactLatticeDeterministic (const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat)
 This function Composes a CompactLattice format lattice with a DeterministicOnDemandFst<fst::StdFst> format fst, and outputs another CompactLattice format lattice. More...
 
void ComputeAcousticScoresMap (const Lattice &lat, unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > *acoustic_scores)
 This function computes the mapping from the pair (frame-index, transition-id) to the pair (sum-of-acoustic-scores, num-of-occurences) over all occurences of the transition-id in that frame. More...
 
void ReplaceAcousticScoresFromMap (const unordered_map< std::pair< int32, int32 >, std::pair< BaseFloat, int32 >, PairHasher< int32 > > &acoustic_scores, Lattice *lat)
 This function restores acoustic scores computed using the function ComputeAcousticScoresMap into the lattice. More...