kaldi-native-fbank C++ API
Kaldi-compatible feature extraction C++ API
Loading...
Searching...
No Matches
knf::OnlineCmvn Class Reference

Online (running) cepstral mean and optional variance normalization. More...

#include <online-cmvn.h>

Public Member Functions

 OnlineCmvn (const OnlineCmvnOptions &opts, const OnlineCmvnState &state)
 Construct with options and adaptation state.
int32_t Dim () const
 Feature dimension (dim of the global stats minus one).
int32_t NumFramesAccepted () const
 Number of frames accepted so far.
VectorF AcceptFeature (const float *feat, int32_t dim)
 Push one raw feature frame; return the normalized frame.
VectorF AcceptFeature (const VectorF &feat)
 Same as AcceptFeature(const float *, int32_t).
MatrixF AcceptFeatures (const MatrixF &feats)
 Push a batch of raw feature frames.
void Freeze ()
 Freeze the normalization at the current frame.
OnlineCmvnState GetState () const
 Return the adaptation state for the next utterance.

Static Public Member Functions

static void SmoothOnlineCmvnStats (const MatrixD &speaker_stats, const MatrixD &global_stats, const OnlineCmvnOptions &opts, MatrixD *stats)
 Smooth window stats with speaker and global stats.

Detailed Description

Online (running) cepstral mean and optional variance normalization.

A port of kaldi's OnlineCmvn (kaldi/src/feat/online-feature.h), push-style: feed raw feature frames one by one and get the normalized frames back (kaldi's version is a pull-style filter in an OnlineFeatureInterface chain).

Unlike the offline CMVN of feature-cmvn.h (which uses the whole utterance), this class looks only at the past. In the middle of a long utterance it accumulates stats from the previous cmn_window frames (default 600, i.e. 6 seconds) and normalizes the current frame with them. At the beginning of an utterance the window stats are augmented ("smoothed") with up to speaker_frames frames of speaker stats from previous utterances and up to global_frames frames of global stats, so the first frames are normalized against a reasonable distribution.

The frame being normalized is included in the stats that normalize it (exactly like kaldi). Variance normalization floors the variance at 1e-20.

Note
Features normalized this way are only approximately zero-mean, especially at utterance start. Acoustic models must be trained with the same kind of normalization ("matched" online training).
Parity with kaldi is tested frame-by-frame against apply-cmvn-online in tests/parity/parity_online_cmvn.py.

Example:

knf::OnlineCmvnState state(global_stats); // MatrixD [2, dim+1]
knf::OnlineCmvn cmvn(opts, state);
for (const knf::VectorF &f : frames) {
knf::VectorF y = cmvn.AcceptFeature(f);
}
auto next_state = cmvn.GetState(); // hand over to the next utterance
Online (running) cepstral mean and optional variance normalization.
Definition online-cmvn.h:130
Eigen::VectorXf VectorF
1-D feature/aux vector (float).
Definition feature-matrix.h:35
Options for OnlineCmvn, mirroring kaldi's OnlineCmvnOptions (kaldi/src/feat/online-feature....
Definition online-cmvn.h:28
State of CMVN adaptation between utterances (not the within-utterance computation state).
Definition online-cmvn.h:73

Constructor & Destructor Documentation

◆ OnlineCmvn()

knf::OnlineCmvn::OnlineCmvn ( const OnlineCmvnOptions & opts,
const OnlineCmvnState & state )

Construct with options and adaptation state.

Parameters
opts[in] The options (defaults match kaldi).
state[in] Adaptation state; state.global_cmvn_stats must be a 2 x (dim+1) matrix. speaker_cmvn_stats and frozen_state may be empty; if frozen_state is set, the normalization is frozen from the start (see Freeze()).

Member Function Documentation

◆ AcceptFeature() [1/2]

VectorF knf::OnlineCmvn::AcceptFeature ( const float * feat,
int32_t dim )

Push one raw feature frame; return the normalized frame.

Parameters
feat[in] Pointer to dim raw feature values.
dim[in] Feature dimension (must equal Dim()).
Returns
The normalized frame, same dimension.

The frame is normalized with stats that include the frame itself (like kaldi). The raw frame also updates the speaker stats used by GetState().

◆ AcceptFeature() [2/2]

VectorF knf::OnlineCmvn::AcceptFeature ( const VectorF & feat)

◆ AcceptFeatures()

MatrixF knf::OnlineCmvn::AcceptFeatures ( const MatrixF & feats)

Push a batch of raw feature frames.

Parameters
feats[in] Raw features, rows are frames, [T, dim].
Returns
The normalized features, [T, dim].

◆ Dim()

int32_t knf::OnlineCmvn::Dim ( ) const
inline

Feature dimension (dim of the global stats minus one).

◆ Freeze()

void knf::OnlineCmvn::Freeze ( )

Freeze the normalization at the current frame.

From now on frames are normalized with the current (smoothed) stats and the running stats stop updating. The frozen state is part of GetState() so later utterances of the speaker keep the same normalization (kaldi uses this to estimate fMLLR on top of a fixed CMVN).

◆ GetState()

OnlineCmvnState knf::OnlineCmvn::GetState ( ) const

Return the adaptation state for the next utterance.

Contains the speaker stats accumulated over all accepted frames (plus any incoming speaker stats), the global stats, and any frozen state — equivalent to kaldi's OnlineCmvn::GetState(cur_frame).

◆ NumFramesAccepted()

int32_t knf::OnlineCmvn::NumFramesAccepted ( ) const
inline

Number of frames accepted so far.

◆ SmoothOnlineCmvnStats()

void knf::OnlineCmvn::SmoothOnlineCmvnStats ( const MatrixD & speaker_stats,
const MatrixD & global_stats,
const OnlineCmvnOptions & opts,
MatrixD * stats )
static

Smooth window stats with speaker and global stats.

A port of kaldi's static OnlineCmvn::SmoothOnlineCmvnStats. Adds up to speaker_frames worth of speaker stats and up to global_frames worth of global stats to stats, scaled by their counts, so the total count approaches cmn_window (a no-op once it is reached).

Parameters
speaker_stats[in] Speaker stats [2, dim+1], may be empty.
global_stats[in] Global stats [2, dim+1] (required at runtime).
opts[in] The options in use.
stats[in,out] Window stats to smooth.

The documentation for this class was generated from the following file:
  • /home/runner/work/kaldi-native-fbank/kaldi-native-fbank/kaldi-native-fbank/csrc/online-cmvn.h