AI Course
Hidden Markov Models
In the previous lesson, we learned about Markov Models, where the states of the system are directly visible. However, in many real-world problems, the actual states are not visible — they are hidden.
Hidden Markov Models (HMMs) are used when we cannot directly observe the state of a system, but we can observe signals or outcomes generated by those states.
Why Do We Need Hidden Markov Models?
In reality, AI systems often work with incomplete or indirect information.
- We hear sounds but do not see how speech is formed
- We see words but not the intent behind them
- We observe symptoms but not the disease itself
Hidden Markov Models allow AI to reason about these hidden states using probabilities.
Real-World Connection
Consider speech recognition.
- Hidden states: Actual spoken words or phonemes
- Observed data: Sound signals captured by the microphone
The AI does not directly see the words — it only hears sounds. HMMs help estimate the most likely words that produced those sounds.
Core Components of a Hidden Markov Model
An HMM consists of three main components:
- Hidden States: Actual conditions (not directly observable)
- Observations: What we can measure or see
- Probabilities: Transitions and emissions
There are two types of probabilities in an HMM:
- Transition Probability: Moving from one hidden state to another
- Emission Probability: Likelihood of an observation from a state
Simple HMM Example
Let’s use a simple weather example.
- Hidden states: Sunny, Rainy
- Observations: Walk, Shop, Clean
We do not directly observe the weather. We only observe what activity a person is doing.
Hidden Markov Model in Python (Conceptual)
Below is a simplified Python representation of an HMM structure.
states = ["Sunny", "Rainy"]
observations = ["Walk", "Shop", "Clean"]
transition_prob = {
"Sunny": {"Sunny": 0.7, "Rainy": 0.3},
"Rainy": {"Sunny": 0.4, "Rainy": 0.6}
}
emission_prob = {
"Sunny": {"Walk": 0.6, "Shop": 0.3, "Clean": 0.1},
"Rainy": {"Walk": 0.1, "Shop": 0.4, "Clean": 0.5}
}
print("HMM defined successfully")
Code Explanation
This code defines:
- Possible hidden states
- Possible observable actions
- Transition probabilities between states
- Emission probabilities for observations
An actual HMM algorithm uses this information to estimate hidden states.
Output Explanation
The output confirms that the model structure is defined. Real HMMs then perform inference on observed sequences.
What Problems Can HMMs Solve?
Hidden Markov Models are commonly used for:
- Speech recognition
- Part-of-speech tagging
- Gesture recognition
- Biological sequence analysis
- User behavior modeling
They are especially useful when states cannot be directly observed.
Limitations of Hidden Markov Models
HMMs are powerful but not perfect.
- They assume the Markov property
- They struggle with very long dependencies
- Modern deep learning models sometimes replace them
However, HMMs are still foundational and widely taught in AI.
Practice Questions (Logic + Code Thinking)
Practice 1: In an HMM, what is not directly observable?
Practice 2: Which probability links a hidden state to an observation?
Practice 3: Name one real-world application of HMMs.
Quick Quiz (Reasoning + Understanding)
Quiz 1: In HMMs, what do we directly observe?
Quiz 2: Which probability defines how observations are generated?
Quiz 3: HMMs are mainly used to handle?
Coming up next: AI Ethics — responsible, fair, and safe use of Artificial Intelligence.