Speech & Audio AI Lab

Interactive labs for speech recognition, speech synthesis, and audio in general: in-browser DSP experiments, algorithms, datasets, and a learning path, without storing any recording.

43experiments

Hidden Markov Model

Hidden Markov Model (HMM)

AdvancedMachine Learning

Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.

Definition

A probabilistic model for sequences generated from hidden states that transition according to a Markov chain, where each state emits observations with a probability distribution. It was the foundation of speech recognition systems before deep networks.

Mathematical Idea

Parameters: the initial distribution $\pi$, the transition matrix $A$, and the emission probabilities $B$. The forward algorithm computes the sequence probability by the recursion $\alpha_t(j)=[\sum_i\alpha_{t-1}(i)a_{ij}]b_j(o_t)$ with complexity $O(TN^2)$. The Viterbi algorithm replaces the sum with a max to find the most likely state path. The model is trained with the Baum–Welch algorithm (a special case of EM).

How It Works

  1. Define the states (for example silence/speech or phonemes).
  2. Define $\pi$, $A$, and $B$.
  3. Compute the probability with the forward algorithm.
  4. Find the most likely path with Viterbi.
  5. Estimate the parameters with Baum–Welch.

Stages Diagram

  1. Observations
  2. π, A, B
  3. Forward
  4. Viterbi
  5. State Path

Equations

$$\alpha_t(j)=\Big[\sum_{i}\alpha_{t-1}(i)\,a_{ij}\Big]\,b_j(o_t)$$

The forward algorithm; $a_{ij}$ is the transition probability and $b_j$ the emission.

$$\delta_t(j)=\max_i\big[\delta_{t-1}(i)\,a_{ij}\big]\,b_j(o_t)$$

The Viterbi algorithm.

$$P(O)=\sum_j \alpha_T(j)$$

The probability of the full sequence.

Advantages

  • A clear mathematical framework for sequences.
  • Represents temporal structure and transitions.
  • Efficient inference with dynamic programming.

Limitations

  • The Markov assumption limits long memory.
  • Requires separate emission models (GMM or a network).
  • Less accurate than modern deep models.

Use Cases

  • Classical speech recognition (GMM-HMM).
  • Voice activity detection and segmentation.
  • Modeling temporal sound events.

Applied Example

With $\pi=[0.6,0.4]$, $A=[[0.7,0.3],[0.4,0.6]]$, $B=[[0.9,0.1],[0.2,0.8]]$, and two observations $[0,1]$: $P(O)=0.209$ and the Viterbi path is $[0,1]$ with probability $0.1296$.

Code Example

PythonImplemented and Tested
import numpy as np
pi = np.array([0.6, 0.4])
A = np.array([[0.7, 0.3], [0.4, 0.6]])
B = np.array([[0.9, 0.1], [0.2, 0.8]])
obs = [0, 1]
alpha = pi*B[:, obs[0]]                                # forward algorithm
delta, back = alpha.copy(), []
for o in obs[1:]:
    alpha = (alpha @ A)*B[:, o]
    cand = delta[:, None]*A                            # Viterbi
    back.append(cand.argmax(axis=0))
    delta = cand.max(axis=0)*B[:, o]
print("P(obs):", round(alpha.sum(), 4))
path = [int(delta.argmax())]
for bp in reversed(back):
    path.insert(0, int(bp[path[0]]))
print("Viterbi path:", path, "prob:", round(delta.max(), 4))

References

  1. Rabiner. A tutorial on hidden Markov models and selected applications in speech recognition. Proceedings of the IEEE 77(2):257-286 (1989). DOI
  2. Reynolds, Quatieri, Dunn. Speaker Verification Using Adapted Gaussian Mixture Models. Digital Signal Processing (2000). DOI

Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy