Unique nbest list with OpenFst

Wrapper function to generate a unique n-best list with OpenFst’s ShortestPath algorithm

template<class Arc>
void UniqueNbest(const Fst<Arc>& fst, int n, MutableFst<Arc>* ofst) {
  VectorFst<Arc> ifst(fst);
  Project(&ifst, PROJECT_OUTPUT);
  RmEpsilon(&ifst);
  vector<typename Arc::Weight> d;
  typedef AutoQueue<typename Arc::StateId> Q;
  AnyArcFilter<Arc> filter;
  Q q(ifst, &d, filter);
  ShortestPathOptions<Arc, Q, AnyArcFilter<Arc> > opts(&q, filter);
  opts.nshortest = n;
  opts.unique = true;
  ShortestPath(ifst, ofst, &d, opts);
}

5 thoughts on “Unique nbest list with OpenFst”

Leave a Reply

Note: only a member of this blog may post a comment.