Edinburgh Speech Tools  2.1-release
viterbi_main.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Authors: Alan W Black and Simon King */
34 /* Date : January 1997 */
35 /*-----------------------------------------------------------------------*/
36 /* A simple use of the Viterbi decoder */
37 /* */
38 /*=======================================================================*/
39 
40 #include <cstdlib>
41 #include <cstdio>
42 #include <cmath>
43 #include "EST.h"
44 
45 using namespace std;
46 
48  const EST_String &filename,
49  const int vec_len);
50 
51 static void print_results(EST_Relation &wstream);
52 static bool do_search(EST_Relation &wstream);
53 static EST_VTPath *vit_npath(EST_VTPath *p,EST_VTCandidate *c,EST_Features &f);
54 static EST_VTCandidate *vit_candlist(EST_Item *s,EST_Features &f);
55 static void top_n_candidates(EST_VTCandidate* &all_c);
56 static void load_vocab(const EST_String &vfile);
57 
58 static void add_word(EST_Relation &w, const EST_String &word, int pos);
59 
60 static void load_wstream(const EST_String &filename,
61  const EST_String &vfile,
62  EST_Relation &w,
63  EST_Track &obs);
64 
65 static void load_given(const EST_String &filename,
66  const int ngram_order);
67 
68 static double find_gram_prob(EST_VTPath *p,int *state);
69 
70 // special stuff for non-sliding window ngrams
71 static double find_extra_gram_prob(EST_VTPath *p,int *state, int time);
72 static void get_history(EST_StrVector &history, EST_VTPath *p);
73 static void fill_window(EST_StrVector &window,EST_StrVector &history,
74  EST_VTPath *p,const int time);
75 static int is_a_special(const EST_String &s, int &val);
76 static int max_history=0;
77 
78 static EST_Ngrammar ngram;
79 static EST_String pstring = SENTENCE_START_MARKER;
80 static EST_String ppstring = SENTENCE_END_MARKER;
81 static float lm_scale = 1.0;
82 static float ob_scale = 1.0;
83 static float ob_scale2 = 1.0;
84 
85 // pruning beam widths
86 static float beam=-1;
87 static float ob_beam=-1;
88 static int n_beam = -1;
89 
90 static bool trace_on = FALSE;
91 
92 // always logs
93 static double ob_log_prob_floor = SAFE_LOG_ZERO;
94 static double ob_log_prob_floor2 = SAFE_LOG_ZERO;
95 static double lm_log_prob_floor = SAFE_LOG_ZERO;
96 
98 static EST_String out_file = "";
99 static EST_StrList vocab;
100 static EST_Track observations;
101 static EST_Track observations2;
102 static EST_TList<EST_StrVector> given; // to do : convert to array for speed
104 
105 // default is that obs are already logs
107 int num_obs = 1;
108 
109 
110 int main(int argc, char **argv)
111 {
112  EST_StrList files;
113  EST_Option al;
114  EST_Relation wstream;
115  double floor; // a temporary
116 
117  parse_command_line(argc, argv,
118  EST_String("[observations file] -o [output file]\n")+
119  "Summary: find the most likely path through a sequence of\n"+
120  " observations, constrained by a language model.\n"+
121  "-ngram <string> Grammar file, required\n"+
122  "-given <string> ngram left contexts, per frame\n"+
123  "-vocab <string> File with names of vocabulary, this\n"+
124  " must be same number as width of observations, required\n"+
125  "-ob_type <string> Observation type : likelihood .... and change doc\"probs\" or \"logs\" (default is \"logs\")\n"+
126  "\nFloor values and scaling (scaling is applied after floor value)\n"+
127  "-lm_floor <float> LM floor probability\n"+
128  "-lm_scale <float> LM scale factor factor (applied to log prob)\n"+
129  "-ob_floor <float> Observations floor probability\n"+
130  "-ob_scale <float> Observation scale factor (applied to prob or log prob, depending on -ob_type)\n\n"+
131  "-prev_tag <string>\n"+
132  " tag before sentence start\n"+
133  "-prev_prev_tag <string>\n"+
134  " all words before 'prev_tag'\n"+
135  "-last_tag <string>\n"+
136  " after sentence end\n"+
137  "-default_tags use default tags of "+SENTENCE_START_MARKER+","
139  " respectively\n\n"+
140 
141  "-observes2 <string> second observations (overlays first, ob_type must be same)\n"+
142  "-ob_floor2 <float> \n"+
143  "-ob_scale2 <float> \n\n"+
144  "-ob_prune <float> observation pruning beam width (log) probability\n"+
145  "-n_prune <int> top-n pruning of observations\n"+
146  "-prune <float> pruning beam width (log) probability\n"+
147  "-trace show details of search as it proceeds\n",
148  files, al);
149 
150  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
151 
152  if (files.length() != 1)
153  {
154  cerr << argv[0];
155  cerr << ": you must give exactly one observations file on the command line";
156  cerr << endl;
157  cerr << "(use -observes2 for optional second observations)" << endl;
158  exit(-1);
159  }
160 
161  if (al.present("-ngram"))
162  {
163  ngram.load(al.val("-ngram"));
164  }
165  else
166  {
167  cerr << argv[0] << ": no ngram specified" << endl;
168  exit(-1);
169  }
170 
171  if(!al.present("-vocab"))
172  {
173  cerr << "You must provide a vocabulary file !" << endl;
174  exit(-1);
175  }
176 
177  load_wstream(files.first(),al.val("-vocab"),wstream,observations);
178  if (al.present("-observes2"))
179  {
180  load_wstream(al.val("-observes2"),al.val("-vocab"),wstream,observations2);
181  num_obs = 2;
182  }
183 
184  if (al.present("-given"))
185  {
186  load_given(al.val("-given"),ngram.order());
188  }
189 
190  if (al.present("-lm_scale"))
191  lm_scale = al.fval("-lm_scale");
192  else
193  lm_scale = 1.0;
194 
195  if (al.present("-ob_scale"))
196  ob_scale = al.fval("-ob_scale");
197  else
198  ob_scale = 1.0;
199 
200  if (al.present("-ob_scale2"))
201  ob_scale2 = al.fval("-ob_scale2");
202  else
203  ob_scale2 = 1.0;
204 
205  if (al.present("-prev_tag"))
206  pstring = al.val("-prev_tag");
207  if (al.present("-prev_prev_tag"))
208  ppstring = al.val("-prev_prev_tag");
209 
210  // pruning
211  if (al.present("-prune"))
212  beam = al.fval("-prune");
213  else
214  beam = -1; // no pruning
215 
216  if (al.present("-ob_prune"))
217  ob_beam = al.fval("-ob_prune");
218  else
219  ob_beam = -1; // no pruning
220 
221  if (al.present("-n_prune"))
222  {
223  n_beam = al.ival("-n_prune");
224  if(n_beam <= 0)
225  {
226  cerr << "WARNING : " << n_beam;
227  cerr << " is not a reasonable value for -n_prune !" << endl;
228  }
229  }
230  else
231  n_beam = -1; // no pruning
232 
233 
234 
235  if (al.present("-trace"))
236  trace_on = TRUE;
237 
238  // language model floor
239  if (al.present("-lm_floor"))
240  {
241  floor = al.fval("-lm_floor");
242  if(floor < 0)
243  {
244  cerr << "Error : LM floor probability is negative !" << endl;
245  exit(-1);
246  }
247  else if(floor > 1)
248  {
249  cerr << "Error : LM floor probability > 1 " << endl;
250  exit(-1);
251  }
252  lm_log_prob_floor = safe_log(floor);
253  }
254 
255  // observations floor
256  if (al.present("-ob_floor"))
257  {
258  floor = al.fval("-ob_floor");
259  if(floor < 0)
260  {
261  cerr << "Error : Observation floor probability is negative !" << endl;
262  exit(-1);
263  }
264  else if(floor > 1)
265  {
266  cerr << "Error : Observation floor probability > 1 " << endl;
267  exit(-1);
268  }
269  ob_log_prob_floor = safe_log(floor);
270  }
271 
272  if (al.present("-ob_floor2"))
273  {
274  floor = al.fval("-ob_floor2");
275  if(floor < 0)
276  {
277  cerr << "Error : Observation2 floor probability is negative !" << endl;
278  exit(-1);
279  }
280  else if(floor > 1)
281  {
282  cerr << "Error : Observation2 floor probability > 1 " << endl;
283  exit(-1);
284  }
285  ob_log_prob_floor2 = safe_log(floor);
286  }
287 
288 
289  if (al.present("-ob_type"))
290  {
291  if(al.val("-ob_type") == "logs")
292  take_logs = false;
293  else if(al.val("-ob_type") == "probs")
294  take_logs = true;
295  else
296  {
297  cerr << "\"" << al.val("-ob_type")
298  << "\" is not a valid ob_type : try \"logs\" or \"probs\"" << endl;
299  exit(-1);
300  }
301  }
302 
303  if(do_search(wstream))
304  print_results(wstream);
305  else
306  cerr << "No path could be found." << endl;
307 
308  return 0;
309 }
310 
311 static void print_results(EST_Relation &wstream)
312 {
313  EST_Item *s;
314  float pscore;
315  EST_String predict;
316  FILE *fd;
317 
318  if (out_file == "-")
319  fd = stdout;
320  else if ((fd = fopen(out_file,"wb")) == NULL)
321  {
322  cerr << "can't open \"" << out_file << "\" for output" << endl;
323  exit(-1);
324  }
325 
326  for (s=wstream.head(); s != 0 ; s=s->next())
327  {
328  predict = s->f("best").string();
329  pscore = s->f("best_score");
330  fprintf(fd,"%s %f\n",(const char *)predict,pscore);
331  }
332 
333  if (fd != stdout)
334  fclose(fd);
335 
336 }
337 
338 static bool do_search(EST_Relation &wstream)
339 {
340  // Apply Ngram to matrix of probs
341  int states;
342 
343  states = ngram.num_states();
344  EST_Viterbi_Decoder vc(vit_candlist,vit_npath,states);
345 
346  vc.initialise(&wstream);
347 
348  if((beam > 0) || (ob_beam > 0))
349  vc.set_pruning_parameters(beam,ob_beam);
350 
351  if(trace_on)
352  {
353  vc.turn_on_trace();
354  cerr << "Starting Viterbi search..." << endl;
355  }
356 
357  vc.search();
358 
359  return vc.result("best"); // adds fields to w with best values
360 
361 }
362 
363 static void load_wstream(const EST_String &filename,
364  const EST_String &vfile,
365  EST_Relation &w,
366  EST_Track &obs)
367 {
368  // Load in vocab and probs into Stream (this isn't general)
369  EST_String word, pos;
370  int i=-1;
371 
372  if(vocab.empty())
373  load_vocab(vfile);
374 
375  if (obs.load(filename,0.10) != 0)
376  {
377  cerr << "can't find observations file \"" << filename << "\"" << endl;
378  exit(-1);
379  }
380 
381  if (vocab.length() != obs.num_channels())
382  {
383  cerr << "Number in vocab (" << vocab.length() <<
384  ") not equal to observation's width (" <<
385  obs.num_channels() << ")" << endl;
386  exit(-1);
387  }
388 
389  if(w.empty())
390  for (i=0; i < obs.num_frames(); i++)
391  add_word(w,itoString(i),i);
392 }
393 
394 
395 static void load_given(const EST_String &filename,
396  const int ngram_order)
397 {
398 
399  EST_String word, pos;
400  EST_Litem *p;
401  int i,j;
402 
403  if (load_TList_of_StrVector(given,filename,ngram_order-1) != 0)
404  {
405  cerr << "can't load given file \"" << filename << "\"" << endl;
406  exit(-1);
407  }
408 
409  // set max history
410  for (p = given.head(); p; p = p->next())
411  {
412  for(i=0;i<given(p).length();i++)
413  if( is_a_special( given(p)(i), j) && (-j > max_history))
414  max_history = -j;
415 
416  }
417 
418 }
419 
420 static void load_vocab(const EST_String &vfile)
421 {
422  // Load vocabulary (strings)
423  EST_TokenStream ts;
424 
425  if (ts.open(vfile) == -1)
426  {
427  cerr << "can't find vocab file \"" << vfile << "\"" << endl;
428  exit(-1);
429  }
430 
431  while (!ts.eof())
432  if (ts.peek() != "")
433  vocab.append(ts.get().string());
434 
435  ts.close();
436 }
437 
438 static void add_word(EST_Relation &w, const EST_String &word, int pos)
439 {
440  EST_Item *item = w.append();
441 
442  item->set_name(word);
443  item->set("pos",pos);
444 }
445 
446 static EST_VTCandidate *vit_candlist(EST_Item *s,EST_Features &f)
447 {
448  // Return a list of new candidates from this point
449  double prob=1.0,prob2=1.0;
450  ssize_t i;
451  EST_Litem *p;
452  ssize_t observe;
453  EST_VTCandidate *all_c = 0;
454  EST_VTCandidate *c;
455  (void)f;
456 
457  observe = s->f("pos"); // index for observations TRACK
458  for (i=0,p=vocab.head(); i < observations.num_channels(); i++,p=p->next())
459  {
460  c = new EST_VTCandidate;
461  c->name = vocab(p); // to be more efficient this could be the index
462  prob = observations.a(observe,i);
463  if(num_obs == 2)
464  prob2 = observations2.a(observe,i);
465 
466  if(take_logs)
467  {
468  prob = safe_log10(prob);
469  if (prob < ob_log_prob_floor)
470  prob = ob_log_prob_floor;
471 
472  if(num_obs == 2)
473  {
474  prob2 = safe_log10(prob2);
475  if (prob2 < ob_log_prob_floor2)
476  prob2 = ob_log_prob_floor2;
477  }
478  }
479  else // already in logs
480  {
481  if (prob < ob_log_prob_floor)
482  prob = ob_log_prob_floor;
483  if ((num_obs == 2) && (prob2 < ob_log_prob_floor2))
484  prob2 = ob_log_prob_floor2;
485  }
486 
487  prob *= ob_scale;
488  prob2 *= ob_scale2;
489 
490  if(num_obs == 2)
491  c->score = prob + prob2;
492  else
493  c->score = prob;
494 
495  c->next = all_c;
496  c->s = s;
497  all_c = c;
498  }
499 
500  if(n_beam > 0)
501  {
502  // N.B. this might be very time-consuming
503  top_n_candidates(all_c);
504  }
505 
506  return all_c;
507 }
508 
509 static EST_VTPath *vit_npath(EST_VTPath *p,EST_VTCandidate *c,
510  EST_Features &f)
511 {
512  // Build a (potential) new path link from this previous path and
513  // This candidate
514  EST_VTPath *np = new EST_VTPath;
515  double lprob,prob;
516  EST_String prev,ttt;
517  (void)f;
518 
519  np->c = c;
520  np->from = p;
521 
522  // are we using extra info ?
523  if(using_given)
524  // time of candidate is
525  // c->s->f("pos");
526  prob = find_extra_gram_prob(np,&np->state,c->s->f("pos"));
527  else
528  prob = find_gram_prob(np,&np->state);
529 
530  lprob = safe_log10(prob);
531  if (lprob < lm_log_prob_floor)
532  lprob = lm_log_prob_floor;
533 
534  lprob *= lm_scale;
535 
536  np->f.set("lscore",(c->score+lprob)); // simonk : changed prob to lprob
537  if (p==0)
538  np->score = (c->score+lprob);
539  else
540  np->score = (c->score+lprob) + p->score;
541 
542  return np;
543 }
544 
545 static double find_gram_prob(EST_VTPath *p,int *state)
546 {
547  // Look up transition probability from *state for name.
548  // Return probability and update state
549  double prob=0.0,nprob;
550  int i,f=FALSE;
551  EST_VTPath *pp;
552 
553  EST_StrVector window(ngram.order());
554  for (pp=p->from,i=ngram.order()-2; i >= 0; i--)
555  {
556  if (pp != 0)
557  {
558  window[i] = pp->c->name.string();
559  pp = pp->from;
560  }
561  else if (f)
562  window[i] = ppstring;
563  else
564  {
565  window[i] = pstring;
566  f = TRUE;
567  }
568  }
569  window[ngram.order()-1] = p->c->name.string();
570  const EST_DiscreteProbDistribution &pd = ngram.prob_dist(window);
571  if (pd.samples() == 0)
572  prob = 0;
573  else
574  prob = (double)pd.probability(p->c->name.string());
575 
576  for (i=0; i < ngram.order()-1; i++)
577  window[i] = window(i+1);
578  ngram.predict(window,&nprob,state);
579 
580  return prob;
581 }
582 
583 
584 static double find_extra_gram_prob(EST_VTPath *p,int *state,int time)
585 {
586 
587  int i;
588  double prob=0.0,nprob;
589  EST_StrVector window(ngram.order());
590  EST_StrVector history(max_history);
591 
592  get_history(history,p);
593 
594  fill_window(window,history,p,time);
595 
596  /*
597  cerr << "Looking up ngram ";
598  for(i=0;i<window.num_points();i++)
599  cerr << window(i) << " ";
600  cerr << endl;
601  */
602 
603  const EST_DiscreteProbDistribution &pd = ngram.prob_dist(window);
604  if (pd.samples() == 0)
605  prob = 0;
606  else
607  prob = (double)pd.probability(p->c->name.string());
608 
609  // shift history, adding latest item at 'end' (0)
610  if(max_history>0)
611  {
612  for(i=history.length()-1;i>0;i--)
613  history[i] = history(i-1);
614  history[0] = p->c->name.string();
615  }
616 
617  fill_window(window,history,p,time+1);
618  ngram.predict(window,&nprob,state);
619 
620  //cerr << endl << endl;
621 
622  return prob;
623 
624 }
625 
626 static void get_history(EST_StrVector &history, EST_VTPath *p)
627 {
628 
629  EST_VTPath *pp;
630  int i,f=FALSE;
631  for (pp=p->from,i=0; i < history.length(); i++)
632  {
633 
634  if (pp != 0)
635  {
636  history[i] = pp->c->name.string();
637  pp = pp->from;
638  }
639  else if (f)
640  history[i] = ppstring;
641  else
642  {
643  history[i] = pstring;
644  f = TRUE;
645  }
646  }
647 
648 }
649 
650 static void fill_window(EST_StrVector &window,EST_StrVector &history,
651  EST_VTPath *p,const int time)
652 {
653  // Look up transition probability from *state for name.
654  // Return probability and update state
655  int i,j;
656  EST_String s;
657 
658  // can we even do it?
659  if( time >= given.length() )
660  return;
661 
662  // format should be run-time defined, but try this for now
663  // first n-1 things in window come from 'given'
664  // last one is predictee
665 
666  // also want vocab and grammar mismatch allowed !!!!!!
667 
668  // predictee
669  window[ngram.order()-1] = p->c->name.string();
670 
671  // given info for this time
672  EST_StrVector *this_g = &(given.nth(time)); // inefficient to count down a list
673 
674 
675  for(i=0;i<ngram.order()-1;i++)
676  {
677 
678  if( is_a_special( (*this_g)(i), j))
679  window[i] = history(-1-j); // j=-1 -> (0) j=-2 -> (1) etc.
680  else
681  window[i] = (*this_g)(i);
682  }
683 }
684 
685 
686 
687 static int is_a_special(const EST_String &s, int &val)
688 {
689 
690  // special is "<int>"
691 
692  EST_String tmp;
693  if(s.contains("<") && s.contains(">"))
694  {
695  tmp = s.after("<");
696  tmp = tmp.before(">");
697  val = atoi(tmp);
698  //cerr << "special " << tmp << "=" << val << endl;
699  return TRUE;
700  }
701  return FALSE;
702 }
703 
704 static void top_n_candidates(EST_VTCandidate* &all_c)
705 {
706  // keep the n most likely candidates
707  // avoiding a full sort of the (potentially long) list
708 
709  EST_VTCandidate *top_c=NULL,*p,*q,*this_best, *prev_to_best;
710  int i;
711  if(n_beam < 1)
712  return; // do nothing
713 
714  // here we assume big is always good
715  //if(!big_is_good)
716  //score_multiplier = -1;
717 
718  for(i=0;i<n_beam;i++)
719  {
720 
721  // head of the list is best guess
722  this_best=all_c;
723  prev_to_best=NULL;
724 
725  // find best candidate in all_c
726  q=NULL;;
727  for(p=all_c;p!= NULL;q=p,p=p->next)
728  {
729  //cerr << "item : " << p->score << endl;
730  if(p->score > this_best->score)
731  {
732  this_best = p;
733  prev_to_best=q;
734  }
735  }
736 
737  if(this_best == NULL)
738  break; // give up now - must have run out of candidates
739 
740  // move best candidate over to new list
741  if(prev_to_best == NULL)
742  // best was head of list
743  all_c = this_best->next;
744  else
745  // best was not head of all_c
746  prev_to_best->next = this_best->next;
747 
748  this_best->next = top_c;
749  top_c = this_best;
750  }
751 
752  delete all_c;
753  all_c = top_c;
754 
755 /*
756  cerr << "Here are the top " << n_beam << " candidates" << endl;
757  for(p=all_c;p != NULL;p=p->next)
758  cerr << p->score << endl;
759 */
760 }
761 
762 
EST_Item * head() const
Definition: EST_Relation.h:121
EST_TokenStream & get(EST_Token &t)
get next token in stream
Definition: EST_Token.cc:499
int contains(const char *s, ssize_t pos=-1) const
Does it contain this substring?
Definition: EST_String.h:365
EST_read_status load(const EST_String &filename)
EST_read_status load_TList_of_StrVector(EST_TList< EST_StrVector > &w, const EST_String &filename, const int vec_len)
Definition: EST_svec_aux.cc:54
double safe_log(const double x)
Definition: EST_math.h:158
double samples(void) const
Total number of example found.
#define SENTENCE_END_MARKER
Definition: EST_Ngrammar.h:60
void set(const EST_String &name, ssize_t ival)
Definition: EST_Item.h:185
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
int num_channels() const
return number of channels in track
Definition: EST_Track.h:657
void close(void)
Close stream.
Definition: EST_Token.cc:419
const EST_String & predict(const EST_StrVector &words, double *prob, int *state) const
EST_String itoString(int n)
Make a EST_String object from an integer.
Definition: util_io.cc:141
bool result(const EST_String &n)
Definition: EST_viterbi.cc:515
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:104
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
T & nth(int n)
return the Nth value
Definition: EST_TList.h:145
void print_results(EST_Relation &ref, EST_Relation &test, EST_FMatrix &m, int tot, int del, int ins, int v)
int ssize_t
double probability(const EST_String &s) const
int num_states(void) const
Definition: EST_Ngrammar.h:413
double safe_log10(const double x)
Definition: EST_math.h:178
double score
Definition: EST_viterbi.h:83
int main(int argc, char **argv)
EST_UItem * next()
Definition: EST_UList.h:55
int open(const EST_String &filename)
open a EST_TokenStream for a file.
Definition: EST_Token.cc:213
const EST_Val f(const EST_String &name) const
Definition: EST_Item.h:260
const EST_DiscreteProbDistribution & prob_dist(const EST_StrVector &words) const
int eof()
end of file
Definition: EST_Token.h:362
EST_read_status load(const EST_String name, float ishift=0.0, float startt=0.0)
Definition: EST_Track.cc:1312
int take_logs
void set_name(const EST_String &name) const
Definition: EST_Item.h:254
float & a(ssize_t i, int c=0)
Definition: EST_Track.cc:1025
void search(void)
Do the the actual search.
Definition: EST_viterbi.cc:207
void set_pruning_parameters(float beam, float ob_beam)
set beam widths for pruning
Definition: EST_viterbi.cc:186
INLINE ssize_t length() const
number of items in vector.
Definition: EST_TVector.h:249
int num_obs
void initialise(EST_Relation *r)
Build the initial table from a EST_Relation.
Definition: EST_viterbi.cc:112
int empty() const
Definition: EST_Relation.h:143
int btest_debug
Definition: viterbi_main.cc:97
#define FALSE
Definition: EST_bool.h:119
EST_VTPath * from
Definition: EST_viterbi.h:87
float time(const EST_Item &item)
Definition: EST_item_aux.cc:82
NULL
Definition: EST_WFST.cc:55
EST_Item * s
Definition: EST_viterbi.h:67
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:152
f
Definition: EST_item_aux.cc:48
ssize_t num_frames() const
return number of frames in track
Definition: EST_Track.h:651
EST_Token & peek(void)
peek at next token
Definition: EST_Token.h:332
const EST_String & string(void) const
Definition: EST_Val.h:161
int using_given
#define SAFE_LOG_ZERO
Definition: EST_math.h:154
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
void append(const T &item)
add item onto end of list
Definition: EST_TList.h:196
EST_Features f
Definition: EST_viterbi.h:85
EST_Item * next() const
Definition: EST_Item.h:348
int length() const
Definition: EST_UList.cc:57
int order() const
Definition: EST_Ngrammar.h:415
EST_read_status
EST_VTCandidate * next
Definition: EST_viterbi.h:68
EST_VTCandidate * c
Definition: EST_viterbi.h:86
Template vector.
Definition: EST_TVector.h:145
A class that offers a generalised Viterbi decoder.
Definition: EST_viterbi.h:134
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_UItem * head() const
Definition: EST_UList.h:97
EST_Item * append(EST_Item *si)
Definition: EST_Relation.cc:88
EST_String after(int pos, int len=1) const
Part after pos+len.
Definition: EST_String.h:308
EST_String before(int pos, int len=0) const
Part before position.
Definition: EST_String.h:276
EST_String
#define SENTENCE_START_MARKER
Definition: EST_Ngrammar.h:59
#define TRUE
Definition: EST_bool.h:118
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101
EST_StrVector vocab
Definition: dp_main.cc:85
int empty() const
Definition: EST_UList.h:89