Multi-Sequence Speech Recognition using Hidden Markov Models
This project implements Hidden Markov Models (HMMs) for a speech recognition task, extending classic HMM applications to classify sequences of spoken digits ("zero", "one", "two") from noisy acoustic data. The implementation processes multiple observation sequences, performs parameter estimation using the Baum-Welch algorithm, conducts model comparison under varying noise levels, and analyzes robustness.
The HMM is defined with:
-
States: Three hidden states,
$S = \lbrace Z, O, T \rbrace$ , for "zero," "one," "two." -
Observations: Four acoustic symbols,
$V = \lbrace A, B, C, D \rbrace$ . - Transition probabilities (A):
- Emission probabilities (B):
- Initial state probabilities (
$\pi$ ):
For three observation sequences:
$O_1 = \lbrace A, B, C, D \rbrace$ $O_2 = \lbrace B, C, A, D \rbrace$ $O_3 = \lbrace C, D, A, B \rbrace$
Compute
For each sequence, find the most likely state sequence using the Viterbi algorithm with backtracking.
Implement Baum-Welch to estimate parameters
Train two HMMs:
- One with 10% noise (randomly flip observation symbols)
- Another with 20% noise
Compare performance by computing average log-likelihood on a test set of 50 simulated sequences (length 4, no noise). Plot the log-likelihood distributions.
- Simulate 200 sequences (length 4) using the true HMM.
- Split into training (150) and test (50) sets.
- Train HMMs with 0%, 10%, and 20% noise levels (5 iterations each).
- Plot the Mean Absolute Error (MAE) of the transition matrix over iterations for each noise level.
| Algorithm | Purpose |
|---|---|
| Forward | Compute |
| Viterbi | Decode the most likely hidden state sequence |
| Baum-Welch | EM algorithm for parameter estimation from multiple observation sequences |
Sequences are simulated using the true HMM parameters. Noise is introduced by randomly flipping observation symbols with a given probability.
Noise levels tested:
- 0% Noise — Clean data (baseline)
- 10% Noise — Moderate corruption
- 20% Noise — High corruption
| Metric | Description |
|---|---|
| Log-Likelihood | Measures how well the trained model explains test data |
| Mean Absolute Error (MAE) | Average absolute difference between estimated and true transition matrices |
multi-sequence-speech-recognition/
│
├── code.ipynb # Complete HMM implementation
│ ├── forward() # Forward algorithm with scaling
│ ├── viterbi() # Viterbi decoding with backtracking
│ ├── baum_welch() # Parameter estimation (EM)
│ ├── simulate_sequence() # Generate synthetic data
│ └── add_noise() # Inject observation noise
│
├── outputs/
│ ├── log_likelihood_dist.png # Histogram (Task 4)
│ ├── mae_convergence.png # MAE over iterations (Task 5)
│ └── console_output.txt # Forward, Viterbi, Baum-Welch results
│
└── README.md # This documentation
| Sequence |
|
Most Likely Hidden Path (Viterbi) |
|---|---|---|
|
|
['Z', 'Z', 'T', 'T'] |
|
|
|
['Z', 'Z', 'Z', 'T'] |
|
|
|
['T', 'T', 'Z', 'Z'] |
After 2 iterations of Baum-Welch using all three sequences jointly:
Updated Transition Matrix A:
Updated Emission Matrix B:
Updated Initial Distribution
-
10% Noise Model: Average Log-Likelihood
$\approx 5.5676$ -
20% Noise Model: Average Log-Likelihood
$\approx 5.5674$
Both models achieve similar test performance, suggesting Baum-Welch is reasonably robust to moderate observation noise.
| Iteration | 0% Noise | 10% Noise | 20% Noise |
|---|---|---|---|
| 0 | 0.104586 | 0.103374 | 0.102812 |
| 1 | 0.101004 | 0.099931 | 0.099464 |
| 2 | 0.097769 | 0.096844 | 0.097921 |
| 3 | 0.095137 | 0.094077 | 0.097058 |
| 4 | 0.094093 | 0.091587 | 0.096347 |
As mentioned in the assignment: Hidden Markov Models (HMMs) were pioneered by Leonard E. Baum in the 1960s, with notable applications in IBM's Tangora system (1980s) and Bell Labs' SPHINX system (1980s-1990s) for speech recognition.