LatticeLexiconWordAligner Class Reference
Collaboration diagram for LatticeLexiconWordAligner:

Classes

class  ComputationState
 
struct  Tuple
 
struct  TupleEqual
 
struct  TupleHash
 

Public Types

enum  Freshness { kNotFresh, kFresh, kAllFresh }
 
typedef CompactLatticeArc::StateId StateId
 
typedef CompactLatticeArc::Label Label
 
typedef WordAlignLatticeLexiconInfo::ViabilityMap ViabilityMap
 
typedef WordAlignLatticeLexiconInfo::LexiconMap LexiconMap
 
typedef WordAlignLatticeLexiconInfo::NumPhonesMap NumPhonesMap
 
typedef unordered_map< Tuple, StateId, TupleHash, TupleEqualMapType
 

Public Member Functions

StateId GetStateForTuple (const Tuple &tuple)
 
void ProcessTransition (StateId prev_output_state, const Tuple &next_tuple, CompactLatticeArc *arc)
 
void ProcessEpsilonTransitions (const Tuple &tuple, StateId output_state)
 
void ProcessWordTransitions (const Tuple &tuple, StateId output_state)
 
void PossiblyAdvanceArc (const Tuple &tuple, StateId output_state)
 
bool ProcessFinal ()
 Process all final-probs (normal case, no forcing-out). More...
 
bool HasNonEpsArcsOut (StateId output_state)
 This function returns true if the state "output_state" in the output lattice has arcs out that have either a non-epsilon symbol or transition-ids in the string of the weight. More...
 
void ProcessFinalForceOut ()
 Creates arcs from all the tuples that were final in the original lattice but have no arcs out of them in the output lattice that consume words or phones– does so by "forcing out" any words and phones there are pending in the computation states. More...
 
void ProcessFinalWrapper ()
 
void ProcessQueueElement ()
 
 LatticeLexiconWordAligner (const CompactLattice &lat, const TransitionModel &tmodel, const WordAlignLatticeLexiconInfo &lexicon_info, int32 max_states, int32 partial_word_label, CompactLattice *lat_out)
 
void RemoveEpsilonsFromLattice ()
 
bool AlignLattice ()
 

Static Public Member Functions

static void AppendVectors (std::vector< std::vector< int32 > >::const_iterator input_begin, std::vector< std::vector< int32 > >::const_iterator input_end, std::vector< int32 > *output)
 

Public Attributes

CompactLattice lat_in_
 
const TransitionModeltmodel_
 
const WordAlignLatticeLexiconInfolexicon_info_
 
int32 max_states_
 
CompactLatticelat_out_
 
std::vector< std::pair< Tuple, StateId > > queue_
 
std::vector< std::pair< Tuple, StateId > > final_queue_
 
MapType map_
 
int32 partial_word_label_
 
bool error_
 

Detailed Description

Definition at line 35 of file word-align-lattice-lexicon.cc.

Member Typedef Documentation

◆ Label

typedef CompactLatticeArc::Label Label

Definition at line 38 of file word-align-lattice-lexicon.cc.

◆ LexiconMap

◆ MapType

typedef unordered_map<Tuple, StateId, TupleHash, TupleEqual> MapType

Definition at line 195 of file word-align-lattice-lexicon.cc.

◆ NumPhonesMap

◆ StateId

typedef CompactLatticeArc::StateId StateId

Definition at line 37 of file word-align-lattice-lexicon.cc.

◆ ViabilityMap

Member Enumeration Documentation

◆ Freshness

Constructor & Destructor Documentation

◆ LatticeLexiconWordAligner()

LatticeLexiconWordAligner ( const CompactLattice lat,
const TransitionModel tmodel,
const WordAlignLatticeLexiconInfo lexicon_info,
int32  max_states,
int32  partial_word_label,
CompactLattice lat_out 
)
inline

Definition at line 285 of file word-align-lattice-lexicon.cc.

References fst::CreateSuperFinal(), and LatticeLexiconWordAligner::lat_in_.

290  :
291  lat_in_(lat), tmodel_(tmodel), lexicon_info_(lexicon_info),
292  max_states_(max_states),
293  lat_out_(lat_out),
294  partial_word_label_(partial_word_label == 0 ?
295  kTemporaryEpsilon : partial_word_label),
296  error_(false) {
297  // lat_in_ is after PhoneAlignLattice, it is not deterministic and contains epsilons
298 
299  fst::CreateSuperFinal(&lat_in_); // Creates a super-final state, so the
300  // only final-probs are One(). Note: the member lat_in_ is not a reference.
301 
302  }
Arc::StateId CreateSuperFinal(MutableFst< Arc > *fst)
const int kTemporaryEpsilon
const WordAlignLatticeLexiconInfo & lexicon_info_

Member Function Documentation

◆ AlignLattice()

bool AlignLattice ( )
inline

Definition at line 317 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::error_, LatticeLexiconWordAligner::GetStateForTuple(), KALDI_WARN, LatticeLexiconWordAligner::lat_in_, LatticeLexiconWordAligner::lat_out_, LatticeLexiconWordAligner::max_states_, LatticeLexiconWordAligner::ProcessFinalWrapper(), LatticeLexiconWordAligner::ProcessQueueElement(), LatticeLexiconWordAligner::queue_, and LatticeLexiconWordAligner::RemoveEpsilonsFromLattice().

Referenced by kaldi::WordAlignLatticeLexicon().

317  {
318  lat_out_->DeleteStates();
319  if (lat_in_.Start() == fst::kNoStateId) {
320  KALDI_WARN << "Trying to word-align empty lattice.";
321  return false;
322  }
323  ComputationState initial_comp_state;
324  Tuple initial_tuple(lat_in_.Start(), initial_comp_state);
325  StateId start_state = GetStateForTuple(initial_tuple);
326  lat_out_->SetStart(start_state);
327 
328  while (!queue_.empty()) {
329  if (max_states_ > 0 && lat_out_->NumStates() > max_states_) {
330  KALDI_WARN << "Number of states in lattice exceeded max-states of "
331  << max_states_ << ", original lattice had "
332  << lat_in_.NumStates() << " states. Returning empty lattice.";
333  lat_out_->DeleteStates();
334  return false;
335  }
337  }
339 
341 
342  return !error_;
343  }
StateId GetStateForTuple(const Tuple &tuple)
std::vector< std::pair< Tuple, StateId > > queue_
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ AppendVectors()

void AppendVectors ( std::vector< std::vector< int32 > >::const_iterator  input_begin,
std::vector< std::vector< int32 > >::const_iterator  input_end,
std::vector< int32 > *  output 
)
static

Definition at line 363 of file word-align-lattice-lexicon.cc.

Referenced by LatticeLexiconWordAligner::ComputationState::TakeForcedTransition(), and LatticeLexiconWordAligner::ComputationState::TakeTransition().

366  {
367  size_t size = 0;
368  for (std::vector<std::vector<int32> >::const_iterator iter = input_begin;
369  iter != input_end;
370  ++iter)
371  size += iter->size();
372  output->clear();
373  output->reserve(size);
374  for (std::vector<std::vector<int32> >::const_iterator iter = input_begin;
375  iter != input_end;
376  ++iter)
377  output->insert(output->end(), iter->begin(), iter->end());
378 }

◆ GetStateForTuple()

StateId GetStateForTuple ( const Tuple tuple)
inline

Definition at line 198 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::lat_out_, LatticeLexiconWordAligner::map_, and LatticeLexiconWordAligner::queue_.

Referenced by LatticeLexiconWordAligner::AlignLattice(), LatticeLexiconWordAligner::PossiblyAdvanceArc(), LatticeLexiconWordAligner::ProcessFinalForceOut(), and LatticeLexiconWordAligner::ProcessTransition().

198  {
199  MapType::iterator iter = map_.find(tuple);
200  if (iter == map_.end()) { // not in map.
201  StateId output_state = lat_out_->AddState();
202  map_[tuple] = output_state;
203  queue_.push_back(std::make_pair(tuple, output_state));
204  return output_state;
205  } else {
206  return iter->second;
207  }
208  }
std::vector< std::pair< Tuple, StateId > > queue_

◆ HasNonEpsArcsOut()

bool HasNonEpsArcsOut ( StateId  output_state)

This function returns true if the state "output_state" in the output lattice has arcs out that have either a non-epsilon symbol or transition-ids in the string of the weight.

Definition at line 531 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::lat_out_.

Referenced by LatticeLexiconWordAligner::ProcessFinalForceOut(), and LatticeLexiconWordAligner::ProcessTransition().

531  {
532  for (fst::ArcIterator<CompactLattice> aiter(*lat_out_, output_state);
533  !aiter.Done(); aiter.Next()) {
534  const CompactLatticeArc &arc = aiter.Value();
535  if (arc.ilabel != 0 || arc.olabel != 0 || !arc.weight.String().empty())
536  return true;
537  }
538  return false;
539 }
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42

◆ PossiblyAdvanceArc()

void PossiblyAdvanceArc ( const Tuple tuple,
StateId  output_state 
)

Definition at line 488 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::ComputationState::Advance(), LatticeLexiconWordAligner::Tuple::comp_state, LatticeLexiconWordAligner::GetStateForTuple(), LatticeLexiconWordAligner::Tuple::input_state, LatticeLexiconWordAligner::lat_in_, LatticeLexiconWordAligner::lat_out_, LatticeLexiconWordAligner::lexicon_info_, LatticeLexiconWordAligner::tmodel_, WordAlignLatticeLexiconInfo::viability_map_, and LatticeLexiconWordAligner::ComputationState::ViableIfAdvanced().

Referenced by LatticeLexiconWordAligner::ProcessQueueElement(), and LatticeLexiconWordAligner::ProcessTransition().

489  {
490  if (tuple.comp_state.ViableIfAdvanced(lexicon_info_.viability_map_)) {
491  for(fst::ArcIterator<CompactLattice> aiter(lat_in_, tuple.input_state);
492  !aiter.Done(); aiter.Next()) {
493  const CompactLatticeArc &arc_in = aiter.Value();
494  Tuple next_tuple(arc_in.nextstate, tuple.comp_state);
495  LatticeWeight arc_weight;
496  next_tuple.comp_state.Advance(arc_in, tmodel_, &arc_weight);
497  // Note: GetStateForTuple will add the tuple to the queue,
498  // if necessary.
499 
500  StateId next_output_state = GetStateForTuple(next_tuple);
501  CompactLatticeArc arc_out(0, 0,
502  CompactLatticeWeight(arc_weight,
503  std::vector<int32>()),
504  next_output_state);
505  lat_out_->AddArc(output_state,
506  arc_out);
507  }
508  }
509 }
StateId GetStateForTuple(const Tuple &tuple)
fst::CompactLatticeWeightTpl< LatticeWeight, int32 > CompactLatticeWeight
Definition: kaldi-lattice.h:35
fst::LatticeWeightTpl< BaseFloat > LatticeWeight
Definition: kaldi-lattice.h:32
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
const WordAlignLatticeLexiconInfo & lexicon_info_

◆ ProcessEpsilonTransitions()

void ProcessEpsilonTransitions ( const Tuple tuple,
StateId  output_state 
)

Definition at line 380 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::Tuple::comp_state, LatticeLexiconWordAligner::Tuple::input_state, KALDI_ERR, LatticeLexiconWordAligner::kAllFresh, LatticeLexiconWordAligner::kFresh, LatticeLexiconWordAligner::lexicon_info_, WordAlignLatticeLexiconInfo::lexicon_map_, WordAlignLatticeLexiconInfo::num_phones_map_, LatticeLexiconWordAligner::ComputationState::NumPhones(), LatticeLexiconWordAligner::ComputationState::PhoneFreshness(), LatticeLexiconWordAligner::ProcessTransition(), and LatticeLexiconWordAligner::ComputationState::TakeTransition().

Referenced by LatticeLexiconWordAligner::ProcessQueueElement(), and LatticeLexiconWordAligner::ProcessTransition().

381  {
382  const ComputationState &comp_state = tuple.comp_state;
383  StateId input_state = tuple.input_state;
384  StateId zero_word = 0;
385  NumPhonesMap::const_iterator iter =
386  lexicon_info_.num_phones_map_.find(zero_word);
387  if (iter == lexicon_info_.num_phones_map_.end()) {
388  return; // No epsilons to match; this can only happen if the lexicon
389  // we were provided had no lines with 0 as the first entry, i.e. no
390  // optional silences or the like.
391  }
392  // Now decide what range of phone-lengths we must process. This is all
393  // about only getting a single opportunity to process any given sequence of
394  // phones.
395  int32 min_num_phones, max_num_phones;
396 
397  if (comp_state.PhoneFreshness() == kAllFresh) {
398  // All sub-sequences of the phone sequence are fresh because we just
399  // shifted some phones off, so we do this for all lengths. We can limit
400  // ourselves to the range of possible lengths for the epsilon symbol,
401  // in the lexicon.
402  min_num_phones = iter->second.first;
403  max_num_phones = std::min(iter->second.second, comp_state.NumPhones());
404  } else if (comp_state.PhoneFreshness() == kFresh) {
405  // only last phone is "fresh", so only consider the sequence of all
406  // phones including the last one.
407  int32 num_phones = comp_state.NumPhones();
408  if (num_phones >= iter->second.first &&
409  num_phones <= iter->second.second) {
410  min_num_phones = num_phones;
411  max_num_phones = num_phones;
412  } else {
413  return;
414  }
415  } else { // kNotFresh
416  return;
417  }
418 
419  if (min_num_phones == 0)
420  KALDI_ERR << "Lexicon error: epsilon transition that produces no output:";
421 
422  for (int32 num_phones = min_num_phones;
423  num_phones <= max_num_phones;
424  num_phones++) {
425  Tuple next_tuple;
426  next_tuple.input_state = input_state; // We're not taking a transition in the
427  // input FST so this stays the same.
428  CompactLatticeArc arc;
429  if (comp_state.TakeTransition(lexicon_info_.lexicon_map_,
430  zero_word,
431  num_phones,
432  &next_tuple.comp_state,
433  &arc)) {
434  ProcessTransition(output_state, next_tuple, &arc);
435  }
436  }
437 }
void ProcessTransition(StateId prev_output_state, const Tuple &next_tuple, CompactLatticeArc *arc)
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
const WordAlignLatticeLexiconInfo & lexicon_info_

◆ ProcessFinal()

bool ProcessFinal ( )

Process all final-probs (normal case, no forcing-out).

returns true if we had at least one final-prob.

Definition at line 511 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::Tuple::comp_state, LatticeLexiconWordAligner::final_queue_, LatticeLexiconWordAligner::ComputationState::FinalWeight(), rnnlm::i, LatticeLexiconWordAligner::Tuple::input_state, KALDI_ASSERT, LatticeLexiconWordAligner::lat_in_, LatticeLexiconWordAligner::lat_out_, CompactLatticeWeightTpl< WeightType, IntType >::One(), and LatticeWeightTpl< BaseFloat >::Zero().

Referenced by LatticeLexiconWordAligner::ProcessFinalWrapper(), and LatticeLexiconWordAligner::ProcessTransition().

511  {
512  bool saw_final = false;
513  // Find final-states...
514  for (size_t i = 0; i < final_queue_.size(); i++) {
515  const Tuple &tuple = final_queue_[i].first;
516  StateId output_state = final_queue_[i].second;
517  KALDI_ASSERT(lat_in_.Final(tuple.input_state) == CompactLatticeWeight::One());
518  LatticeWeight final_weight = tuple.comp_state.FinalWeight();
519  if (final_weight != LatticeWeight::Zero()) {
520  // note: final_weight is only nonzero if there are no
521  // pending transition-ids, so there is no string component.
522  std::vector<int32> empty_vec;
523  lat_out_->SetFinal(output_state,
524  CompactLatticeWeight(final_weight, empty_vec));
525  saw_final = true;
526  }
527  }
528  return saw_final;
529 }
std::vector< std::pair< Tuple, StateId > > final_queue_
fst::CompactLatticeWeightTpl< LatticeWeight, int32 > CompactLatticeWeight
Definition: kaldi-lattice.h:35
fst::LatticeWeightTpl< BaseFloat > LatticeWeight
Definition: kaldi-lattice.h:32
static const CompactLatticeWeightTpl< WeightType, IntType > One()
static const LatticeWeightTpl Zero()
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ ProcessFinalForceOut()

void ProcessFinalForceOut ( )

Creates arcs from all the tuples that were final in the original lattice but have no arcs out of them in the output lattice that consume words or phones– does so by "forcing out" any words and phones there are pending in the computation states.

This function is only called if no states were "naturally" final; this will only happen for lattices that were forced out during decoding.

Definition at line 541 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::Tuple::comp_state, LatticeLexiconWordAligner::final_queue_, LatticeLexiconWordAligner::GetStateForTuple(), LatticeLexiconWordAligner::HasNonEpsArcsOut(), rnnlm::i, LatticeLexiconWordAligner::Tuple::input_state, KALDI_ASSERT, LatticeLexiconWordAligner::lat_out_, LatticeLexiconWordAligner::partial_word_label_, LatticeLexiconWordAligner::queue_, kaldi::swap(), and LatticeLexiconWordAligner::ComputationState::TakeForcedTransition().

Referenced by LatticeLexiconWordAligner::ProcessFinalWrapper(), and LatticeLexiconWordAligner::ProcessTransition().

541  {
542  KALDI_ASSERT(queue_.empty());
543  std::vector<std::pair<Tuple, StateId> > new_final_queue_;
544  new_final_queue_.reserve(final_queue_.size());
545  for (size_t i = 0; i < final_queue_.size();i++) { // note: all the states will
546  // be final in the orig. lattice
547  const Tuple &tuple = final_queue_[i].first;
548  StateId output_state = final_queue_[i].second;
549 
550  if (!HasNonEpsArcsOut(output_state)) { // This if-statement
551  // avoids forcing things out too early, when they had words
552  // that could naturally have been put out. [without it,
553  // we'd have multiple alternate paths at the end.]
554 
555  CompactLatticeArc arc;
556  Tuple next_tuple;
557  next_tuple.input_state = tuple.input_state;
558  tuple.comp_state.TakeForcedTransition(partial_word_label_,
559  &next_tuple.comp_state,
560  &arc);
561  // Note: the following call may add to queue_, but we'll clear it,
562  // we don't want to process these states.
563  StateId new_state = GetStateForTuple(next_tuple);
564  arc.nextstate = new_state;
565  lat_out_->AddArc(output_state, arc);
566  new_final_queue_.push_back(std::make_pair(next_tuple, new_state));
567  }
568  }
569  queue_.clear();
570  std::swap(final_queue_, new_final_queue_);
571 }
StateId GetStateForTuple(const Tuple &tuple)
std::vector< std::pair< Tuple, StateId > > final_queue_
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
std::vector< std::pair< Tuple, StateId > > queue_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
bool HasNonEpsArcsOut(StateId output_state)
This function returns true if the state "output_state" in the output lattice has arcs out that have e...

◆ ProcessFinalWrapper()

void ProcessFinalWrapper ( )
inline

Definition at line 250 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::error_, LatticeLexiconWordAligner::final_queue_, KALDI_WARN, LatticeLexiconWordAligner::ProcessFinal(), and LatticeLexiconWordAligner::ProcessFinalForceOut().

Referenced by LatticeLexiconWordAligner::AlignLattice().

250  {
251  if (final_queue_.empty()) {
252  KALDI_WARN << "No final-probs to process.";
253  error_ = true;
254  return;
255  }
256  if (ProcessFinal()) return;
257  error_ = true;
258  KALDI_WARN << "Word-aligning lattice: lattice was forced out, will have partial words at end.";
259 
261 
262  if (ProcessFinal()) return;
263  KALDI_WARN << "Word-aligning lattice: had no final-states even after forcing out "
264  << "(result will be empty). This probably indicates wrong input.";
265  return;
266  }
std::vector< std::pair< Tuple, StateId > > final_queue_
void ProcessFinalForceOut()
Creates arcs from all the tuples that were final in the original lattice but have no arcs out of them...
#define KALDI_WARN
Definition: kaldi-error.h:150
bool ProcessFinal()
Process all final-probs (normal case, no forcing-out).

◆ ProcessQueueElement()

void ProcessQueueElement ( )
inline

Definition at line 268 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::final_queue_, KALDI_ASSERT, LatticeLexiconWordAligner::lat_in_, LatticeLexiconWordAligner::PossiblyAdvanceArc(), LatticeLexiconWordAligner::ProcessEpsilonTransitions(), LatticeLexiconWordAligner::ProcessWordTransitions(), LatticeLexiconWordAligner::queue_, and CompactLatticeWeightTpl< WeightType, IntType >::Zero().

Referenced by LatticeLexiconWordAligner::AlignLattice().

268  {
269  KALDI_ASSERT(!queue_.empty());
270  Tuple tuple = queue_.back().first;
271  StateId output_state = queue_.back().second;
272  queue_.pop_back();
273 
274  ProcessEpsilonTransitions(tuple, output_state);
275  ProcessWordTransitions(tuple, output_state);
276  PossiblyAdvanceArc(tuple, output_state);
277 
278  // Note: we'll do a bit more filtering in ProcessFinal(), meaning
279  // that we won't necessarily give a final-prob to all of the things
280  // that go onto final_queue_.
281  if (lat_in_.Final(tuple.input_state) != CompactLatticeWeight::Zero())
282  final_queue_.push_back(std::make_pair(tuple, output_state));
283  }
std::vector< std::pair< Tuple, StateId > > final_queue_
void PossiblyAdvanceArc(const Tuple &tuple, StateId output_state)
void ProcessWordTransitions(const Tuple &tuple, StateId output_state)
std::vector< std::pair< Tuple, StateId > > queue_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
static const CompactLatticeWeightTpl< WeightType, IntType > Zero()
void ProcessEpsilonTransitions(const Tuple &tuple, StateId output_state)

◆ ProcessTransition()

◆ ProcessWordTransitions()

void ProcessWordTransitions ( const Tuple tuple,
StateId  output_state 
)

Definition at line 439 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::Tuple::comp_state, LatticeLexiconWordAligner::Tuple::input_state, KALDI_ERR, LatticeLexiconWordAligner::kAllFresh, LatticeLexiconWordAligner::kFresh, LatticeLexiconWordAligner::lexicon_info_, WordAlignLatticeLexiconInfo::lexicon_map_, WordAlignLatticeLexiconInfo::num_phones_map_, LatticeLexiconWordAligner::ComputationState::NumPhones(), LatticeLexiconWordAligner::ComputationState::NumWords(), LatticeLexiconWordAligner::ComputationState::PendingWord(), LatticeLexiconWordAligner::ComputationState::PhoneFreshness(), LatticeLexiconWordAligner::ProcessTransition(), LatticeLexiconWordAligner::ComputationState::TakeTransition(), and LatticeLexiconWordAligner::ComputationState::WordFreshness().

Referenced by LatticeLexiconWordAligner::ProcessQueueElement(), and LatticeLexiconWordAligner::ProcessTransition().

440  {
441  const ComputationState &comp_state = tuple.comp_state;
442  StateId input_state = tuple.input_state;
443  if (comp_state.NumWords() > 0) {
444  int32 min_num_phones, max_num_phones;
445  int32 word_id = comp_state.PendingWord();
446 
447  if (comp_state.WordFreshness() == kFresh ||
448  comp_state.PhoneFreshness() == kAllFresh) {
449  // Just saw word, or shifted phones,
450  // so 1st opportunity to process phone-sequences of all possible sizes,
451  // with this word.
452  NumPhonesMap::const_iterator iter =
453  lexicon_info_.num_phones_map_.find(word_id);
454  if (iter == lexicon_info_.num_phones_map_.end()) {
455  KALDI_ERR << "Word " << word_id << " is not present in the lexicon.";
456  }
457  min_num_phones = iter->second.first;
458  max_num_phones = std::min(iter->second.second,
459  comp_state.NumPhones());
460  } else if (comp_state.PhoneFreshness() == kFresh) {
461  // just the latest phone is new -> just try to process the
462  // phone-sequence of all the phones we have.
463  min_num_phones = comp_state.NumPhones();
464  max_num_phones = min_num_phones;
465  } else {
466  return; // Nothing to do, since neither the word nor the phones are fresh.
467  }
468 
469  for (int32 num_phones = min_num_phones;
470  num_phones <= max_num_phones;
471  num_phones++) {
472  Tuple next_tuple;
473  next_tuple.input_state = input_state; // We're not taking a transition in the
474  // input FST so this stays the same.
475  CompactLatticeArc arc;
476  if (comp_state.TakeTransition(lexicon_info_.lexicon_map_,
477  word_id,
478  num_phones,
479  &next_tuple.comp_state,
480  &arc)) {
481  ProcessTransition(output_state, next_tuple, &arc);
482  }
483  }
484  }
485 }
void ProcessTransition(StateId prev_output_state, const Tuple &next_tuple, CompactLatticeArc *arc)
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
Definition: kaldi-lattice.h:42
const WordAlignLatticeLexiconInfo & lexicon_info_

◆ RemoveEpsilonsFromLattice()

void RemoveEpsilonsFromLattice ( )
inline

Definition at line 308 of file word-align-lattice-lexicon.cc.

References LatticeLexiconWordAligner::lat_out_, and fst::RemoveSomeInputSymbols().

Referenced by LatticeLexiconWordAligner::AlignLattice().

308  {
309  Connect(lat_out_);
310  RmEpsilon(lat_out_, true); // true = connect.
311  std::vector<int32> syms_to_remove;
312  syms_to_remove.push_back(kTemporaryEpsilon);
313  RemoveSomeInputSymbols(syms_to_remove, lat_out_);
314  Project(lat_out_, fst::PROJECT_INPUT);
315  }
const int kTemporaryEpsilon
void RemoveSomeInputSymbols(const std::vector< I > &to_remove, MutableFst< Arc > *fst)
RemoveSomeInputSymbols removes any symbol that appears in "to_remove", from the input side of the FST...

Member Data Documentation

◆ error_

◆ final_queue_

◆ lat_in_

◆ lat_out_

◆ lexicon_info_

◆ map_

◆ max_states_

int32 max_states_

◆ partial_word_label_

int32 partial_word_label_

◆ queue_

◆ tmodel_

const TransitionModel& tmodel_

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