kaldi lattice


概況

兩種lattice結構

Lattice結構

FST的形式,weight包括兩部分(graph cost和acoustic cost),輸入是transition-ids,輸出是words。
其中weight的graph cost包含LM+transition+pronunciation三部分。

CompactLattice結構

和lattice相似,區別在於它是接收機,輸入和輸出一樣(都是words),weight包含兩部分(權重和transition-ids),相比於Lattice,CompactLattice把輸入的transition-ids轉移到weight上面。

lattice保證每一個word-sequence只對應lattice中的一條路徑。

Lattice實現

假設a表示graph cost,b表示acoustic cost,那麼
LatticeWeight表示爲(a,b)
LexicographicWeight表示爲(a+b,a-b)

lattice相關的算法在Lattice上面更爲高效,因爲CompactLattice的weight包含有transition-ids,當take best path的時候就涉及到transition-ids的拼接操作。

lattice寫入文件時保持acoustic cost是unscaled。可以從archive中讀取Lattice,即使裏面包含有CompactLattice。

可以使用ConvertLattice()函數將Lattice轉化爲CompactLattice。lattice轉化:

  Lattice lat;
  // initialize lat.
  CompactLattice compact_lat;
  ConvertLattice(lat, &compact_lat);

使用OpenFst算法

  Lattice lat;
  // initialize lat.
  Lattice best_path;
  fst::ShortestPath(lat, &best_path);

CompactLattice實現

weight不僅包含cost,還有transition-id,對於multiplication操作,transition-id進行append,對於adding操作,cost佔優的transition-id作爲結果。

lattice generation

對應的類 LatticeSimpleDecoder,流程包括:
- 產生state級別的lattice
- 使用lattice-delta對lattice剪枝
- 使用特殊的確定化算法對每一個word sequence只保留最優路徑

lattice operation

lattice-prune --acoustic-scale=0.1 --beam=5 ark:in.lats ark:out.lats
lattice-best-path --acoustic-scale=0.1 ark:in.lats ark:out.tra ark:out.ali
lattice-nbest --n=10 --acoustic-scale=0.1 ark:in.lats ark:out.nbest
#LM rescore
lattice-lmrescore --lm-scale=-1.0 ark:in.lats G_old.fst ark:nolm.lats
lattice-lmrescore --lm-scale=1.0 ark:nolm.lats G_new.fst ark:out.lats
#probability scaling
lattice-scale --acoustic-scale=0.1 --lm-scale=0.8 ark:in.lats ark:out.lats
#用在MMI的區分度訓練MMI,保證正確的transcription出現在分母
lattice-union ark:num_lats.ark ark:den_lats.ark ark:augmented_den_lats.ark
lattice-interp --alpha=0.4 ark:1.lats ark:2.lats ark:3.lats
lattice-to-phones final.mdl ark:1.lats ark:phones.lats
lattice-project ark:1.lats ark:- | lattice-compose ark:- ark:2.lats ark:3.lats
lattice-equivalent ark:1.lats ark:2.lats || echo "Not equivalent!"
lattice-rmali ark:in.lats ark:word.lats
#Boosted MMI training
lattice-boost-ali --silence-phones=1:2:3 --b=0.1 final.mdl ark:1.lats \
   ark:1.ali ark:boosted.lats
#前後向計算後驗概率
lattice-to-post --acoustic-scale=0.1 ark:1.lats ark:- | \
    gmm-acc-stats 10.mdl "$feats" ark:- 1.acc
lattice-determinize ark:1.lats ark:det.lats
#計算WER
 cat $data/text | \
  sed 's:<NOISE>::g' |  sed 's:<SPOKEN_NOISE>::g'  | \
  scripts/sym2int.pl --ignore-first-field $lang/words.txt | \
  lattice-oracle --word-symbol-table=$lang/words.txt  \
    "ark:gunzip -c $dir/lats.pruned.gz|" ark:- ark,t:$dir/oracle.tra \
    2>$dir/oracle.log
#增加轉移概率
lattice-add-trans-probs --transition-scale=1.0 --self-loop-scale=0.1 \
      final.mdl ark:1.lats ark:2.lats
lattice-to-fst --lm-scale=0.0 --acoustic-scale=0.0 ark:1.lats ark:1.words
lattice-copy ark:1.lats ark,t:- | head -50
lattice-to-nbest --acoustic-scale=0.1 --n=10 ark:1.lats ark:1.nbest
nbest-to-linear ark:1.nbest ark:1.ali ark:1.words ark:1.lmscore ark:1.acscore

對於lattice來講,邊上的word/transition-id/weight並不是完全的對應關係,同時得到的時間信息也是不準確的.
對於CompactLattice來說,單個邊上的信息意義不明確,只有組合成一條完整的path纔有意義。

發佈了132 篇原創文章 · 獲贊 94 · 訪問量 62萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章