Sequence-to-Sequence (Seq2Seq) Models
Some time-series problems are not about predicting just the next value. They are about converting one entire sequence into another sequence.
This is where sequence-to-sequence models become essential.
What Problem Do Seq2Seq Models Solve?
Seq2Seq models handle problems where:
- Input length ≠ output length
- Prediction happens as a sequence, not a single value
- Context matters across the whole timeline
In time series, this often appears in:
- Multi-step forecasting
- Signal transformation
- Pattern translation
Real-World Example: Energy Demand Forecasting
Imagine this real scenario:
- Input: last 14 days of hourly energy usage
- Output: next 7 days of hourly demand
Here, one sequence (past) must be converted into another (future).
Predicting step-by-step independently often fails. Seq2Seq models learn the relationship between entire sequences.
How Seq2Seq Works (Conceptually)
A Seq2Seq model has two major parts:
- Encoder – reads the input sequence and compresses it into context
- Decoder – uses that context to generate the output sequence
The encoder does not predict. It only understands.
The decoder does not look at raw history. It relies on encoded knowledge.
Visual Flow of Seq2Seq
The chart below illustrates:
- Input sequence (past energy usage)
- Output sequence (future demand)
How to Read This Visualization
- The left portion represents historical data
- The right portion represents predicted future sequence
- The transition point is learned, not forced
Seq2Seq models learn how patterns evolve across time.
Why Regular Models Fail Here
Traditional models assume:
- One input → one output
- Fixed step prediction
Seq2Seq models allow:
- Many-to-many mapping
- Dynamic horizons
- Long-range dependency learning
Conceptual Seq2Seq Logic
# Encoder reads full input sequence
context = encode(input_sequence)
# Decoder generates output sequence step by step
output_sequence = []
state = context
for t in range(output_length):
next_value, state = decode_step(state)
output_sequence.append(next_value)
Key idea:
- The encoder compresses information
- The decoder expands it into a new sequence
Strengths of Seq2Seq Models
- Flexible input and output lengths
- Handles complex temporal relationships
- Strong for long-horizon forecasts
Where Seq2Seq Is Commonly Used
- Weather forecasting
- Energy demand prediction
- Traffic flow forecasting
- Financial trend projection
Practice Questions
Q1. Why is Seq2Seq better than step-wise prediction for long horizons?
Q2. What happens if the encoder loses important context?
Next lesson: Encoder–Decoder architectures in more detail.