ArcPosteriorComputer Class Reference
Collaboration diagram for ArcPosteriorComputer:

Public Member Functions

 ArcPosteriorComputer (const CompactLattice &clat, BaseFloat min_post, bool print_alignment, const TransitionModel *trans_model=NULL)
 
int32 OutputPosteriors (const std::string &utterance, std::ostream &os)
 

Private Attributes

const CompactLatticeclat_
 
std::vector< double > alpha_
 
std::vector< double > beta_
 
std::vector< int32state_times_
 
BaseFloat min_post_
 
bool print_alignment_
 
const TransitionModeltrans_model_
 

Detailed Description

Definition at line 31 of file lattice-arc-post.cc.

Constructor & Destructor Documentation

◆ ArcPosteriorComputer()

ArcPosteriorComputer ( const CompactLattice clat,
BaseFloat  min_post,
bool  print_alignment,
const TransitionModel trans_model = NULL 
)
inline

Definition at line 34 of file lattice-arc-post.cc.

37  :
38  clat_(clat), min_post_(min_post), print_alignment_(print_alignment),
39  trans_model_(trans_model) { }
const CompactLattice & clat_
const TransitionModel * trans_model_

Member Function Documentation

◆ OutputPosteriors()

int32 OutputPosteriors ( const std::string &  utterance,
std::ostream &  os 
)
inline

Definition at line 42 of file lattice-arc-post.cc.

References ArcPosteriorComputer::alpha_, ArcPosteriorComputer::beta_, ArcPosteriorComputer::clat_, kaldi::CompactLatticeStateTimes(), kaldi::ComputeCompactLatticeAlphas(), kaldi::ComputeCompactLatticeBetas(), fst::ConvertToCost(), TransitionModel::IsFinal(), KALDI_ASSERT, ArcPosteriorComputer::min_post_, ArcPosteriorComputer::print_alignment_, ArcPosteriorComputer::state_times_, ArcPosteriorComputer::trans_model_, and TransitionModel::TransitionIdToPhone().

Referenced by main().

43  {
44  int32 num_post = 0;
46  return num_post;
48  return num_post;
49 
51  if (clat_.Start() < 0)
52  return 0;
53  double tot_like = beta_[clat_.Start()];
54 
55  int32 num_states = clat_.NumStates();
56  for (int32 state = 0; state < num_states; state++) {
57  for (fst::ArcIterator<CompactLattice> aiter(clat_, state);
58  !aiter.Done(); aiter.Next()) {
59  const CompactLatticeArc &arc = aiter.Value();
60  double arc_loglike = -ConvertToCost(arc.weight) +
61  alpha_[state] + beta_[arc.nextstate] - tot_like;
62  KALDI_ASSERT(arc_loglike < 0.1 &&
63  "Bad arc posterior in forward-backward computation");
64  if (arc_loglike > 0.0) arc_loglike = 0.0;
65  int32 num_frames = arc.weight.String().size(),
66  word = arc.ilabel;
67  BaseFloat arc_post = exp(arc_loglike);
68  if (arc_post <= min_post_) continue;
69  os << utterance << '\t' << state_times_[state] << '\t' << num_frames
70  << '\t' << arc_post << '\t' << word;
71  if (print_alignment_) {
72  os << '\t';
73  const std::vector<int32> &ali = arc.weight.String();
74  for (int32 frame = 0; frame < num_frames; frame++) {
75  os << ali[frame];
76  if (frame + 1 < num_frames) os << ',';
77  }
78  }
79  if (trans_model_ != NULL) {
80  // we want to print the phone sequence too.
81  os << '\t';
82  const std::vector<int32> &ali = arc.weight.String();
83  bool first_phone = true;
84  for (int32 frame = 0; frame < num_frames; frame++) {
85  if (trans_model_->IsFinal(ali[frame])) {
86  if (first_phone) first_phone = false;
87  else os << ' ';
88  os << trans_model_->TransitionIdToPhone(ali[frame]);
89  }
90  }
91  }
92  os << std::endl;
93  num_post++;
94  }
95  }
96  return num_post;
97  }
std::vector< int32 > state_times_
std::vector< double > alpha_
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
bool ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
double ConvertToCost(const LatticeWeightTpl< Float > &w)
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
std::vector< double > beta_
bool ComputeCompactLatticeAlphas(const CompactLattice &clat, vector< double > *alpha)
bool IsFinal(int32 trans_id) const
int32 TransitionIdToPhone(int32 trans_id) const
const CompactLattice & clat_
const TransitionModel * trans_model_

Member Data Documentation

◆ alpha_

std::vector<double> alpha_
private

Definition at line 100 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ beta_

std::vector<double> beta_
private

Definition at line 101 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ clat_

const CompactLattice& clat_
private

Definition at line 99 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ min_post_

BaseFloat min_post_
private

Definition at line 104 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ print_alignment_

bool print_alignment_
private

Definition at line 105 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ state_times_

std::vector<int32> state_times_
private

Definition at line 102 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().

◆ trans_model_

const TransitionModel* trans_model_
private

Definition at line 106 of file lattice-arc-post.cc.

Referenced by ArcPosteriorComputer::OutputPosteriors().


The documentation for this class was generated from the following file: