Common utilities
base/kaldi-common.h
幾乎所有Kaldi程序都會include該頭文件。
該頭文件include了一些其他位於base/目錄的頭文件,主要提供:
- 錯誤-日志 宏
- 類型定義(typedefs)
- 數學實用程序函數(如隨機數生成器)
- 其他#defines
util/common-utils.h
命令行參數解析
I/O函數(處理帶管道的文件名)
ark列表處理
列表類型
字符串轉換
gmm/model-common.h
GMM/SGMM的枚舉,如:模型哪些部分需要更新
gmm/diag-gmm.h
單個GMM的定義,對GMM的操作,包括:
調整混合組元數以及特征維數
復制
高斯采樣
擾動
分裂
合並
對組元的增、刪、改、讀寫
似然計算
根據數據選擇似然最高的組元
private:
/// GMM Constant(對數高斯混合模型概率密度函數中的常量)
/// 即 log(weight) - 0.5 * (log det(var) + mean*mean*inv(var))
Vector<BaseFloat> gconsts_;
bool valid_gconsts_; ///< Recompute gconsts_ if false
gmm/am-diag-gmm.h
該類僅儲存了一個GMM列表,以及定義了一些存取函數和便捷函數。
std::vector<DiagGmm*> densities_;
矩陣庫
matrix/matrix-lib.h
該頭文件是對BLAS和LAPACK的封裝
sp-matrix.h
壓縮的對稱矩陣(symmetric packed matrices)
tp-matrix.h
壓縮的上下三角矩陣(triangular packed matrices)
srfft.h
分裂基快速傅里葉變換(Split Rafix FFT)
matrix/kaldi-matrix.h
矩陣定義、矩陣運算,tutorial
在文件matrix/matrix-lib-test.cc中添加一個測試函數。如前所述,如果出現問題,測試程序將被設計為以非零狀態中止或退出。
我們將為Vector::AddVec函數添加一個測試例程。該函數將一個常量乘以一個向量,並加到另一個向量中。仔細閱讀下面的代碼,盡可能多地理解它(請注意:我們故意在代碼中插入了兩個錯誤)。如果你對模板不熟悉,理解它可能會很困難。我們盡量避免使用模板,因此Kaldi的大部分內容在不知道模板編程的情況下仍然可以理解。
template<class Real> void UnitTestAddVec() { // note: Real will be float or double when instantiated. int32 dim = 1 + Rand() % 10; Vector<Real> v(dim); w(dim); // two vectors the same size. v.SetRandn(); w.SetRandn(); Vector<Real> w2(w); // w2 is a copy of w. Real f = RandGauss(); w.AddVec(f, v); // w <-- w + f v for (int32 i = 0; i < dim; i++) { Real a = w(i), b = f * w2(i) + v(i); AssertEqual(a, b); // will crash if not equal to within // a tolerance. } } |
特征提取代碼
feat/feature-mfcc.h
數據成員有:
// lifter系數
Vector<BaseFloat> lifter_coeffs_;
// 離散余弦變換(Discrete Cosine Transformation)矩陣
Matrix<BaseFloat> dct_matrix_; // matrix we left-multiply by to perform DCT.
// 最小對數能量
BaseFloat log_energy_floor_;
// 梅爾濾波器組,聲道長度歸一化系數
std::map<BaseFloat, MelBanks*> mel_banks_; // BaseFloat is VTLN coefficient.
// 分裂基傅里葉變換
SplitRadixRealFft<BaseFloat> *srfft_;
// note: mel_energies_ is specific to the frame we're processing, it's
// just a temporary workspace.
// 當前幀的梅爾能量
Vector<BaseFloat> mel_energies_;
以及特征計算函數
聲學決策樹以及HMM拓撲代碼
tree/build-tree.h
決策樹構建主要是由BuildTree函數實現:
EventMap *BuildTree(...)
其返回值EventMap是一個能夠表示從EventType((key, value)二元組向量)到EventAnswerType(整數)的映射。
key表示音素上下文位置(如,-1、0、1或2);
其中-1表示當前位置位於該HMM中(粗略的位置)
value表示音素的標識符;
BuildTree()函數的輸入數據為
const BuildTreeStatsType &stats,
其類型BuildTreeStatsType:
typedef vector<pair<EventType, Clusterable*> > BuildTreeStatsType;
其中的EventType:
typedef vector<pair<EventKeyType, EventValueType> > EventType;
EventType是三音素標識符,如{{-1, 1},{0, 15},{1, 21},{2, 38}}表示左上文音素為15、右下文音素為38的三音素21,並且其pdf-class(中間狀態的標識符)為1。
Clusterable* 是指向一個接口類,支持如 統計數據相加、目標函數(如似然)計算 的運算。
在常見的腳本中,該指針通常指向一個統計數據類。
該類包含足夠的用於估計對角高斯pdf的統計數據。
如:
class GaussClusterable: public Clusterable{
private:
Matrix<double> stats_;//兩行的矩陣,一行為向量之和,一行為向量的平方和
}
在進行accumlate tree時,為三音素中的每個HMM狀態(即pdf-class)統計單高斯的統計數據。
-ci-phones選項(該選項是優化項,不加也可)用於指定無需進行數據統計的上下文無關音素(如靜音音素)。
該程序的輸出可以被看作是上述的BuildTreeStatsType。