How do models turn ordered observations into useful memory?
Machine Learning in Engineering Science Fall 2026 · Week 07 · Hour 1 Chi-Hua Jonny Yu · NCKU / LAiMM


W07 · H1 · 14:00–15:00 · 19 October 2026
How do models turn ordered observations into useful memory?
Machine Learning in Engineering Science Fall 2026 · Week 07 · Hour 1 Chi-Hua Jonny Yu · NCKU / LAiMM


W07 · H1 · Machine Learning in Engineering Science
Define a valid sequence task, then explain and test how LSTM stores information.
Goal: trace one cell update and judge a forecast.


W07 · H1 · Machine Learning in Engineering Science
A sequence contains both values and an ordering rule.
[1, 2, 4, 8] ≠ [8, 1, 4, 2]
What remains identical after shuffling?
The multiset and mean; adjacency, trend, and time-dependent structure can change.


W07 · H1 · Machine Learning in Engineering Science
The prediction must use only information available at its origin.
history: x[t−L:t] target: x[t]


W07 · H1 · Machine Learning in Engineering Science
Sequence models receive a batch of histories, with features at every time step.
X ∈ ℝᴮˣᵀˣᶠ


W07 · H1 · Machine Learning in Engineering Science
Many-to-one predicts one value; many-to-many predicts a value at multiple positions.


W07 · H1 · Machine Learning in Engineering Science
Train on earlier targets, select on later validation, then evaluate on test.
train < validation < test


W07 · H1 · Machine Learning in Engineering Science
Global means and variances can reveal future distribution information.
z = (x − μtrain) / σtrain


W07 · H1 · Machine Learning in Engineering Science
Predict the next observation using the last known observation.
ŷ[t] = x[t−1]


W07 · H1 · Machine Learning in Engineering Science
An RNN applies the same state-update parameters at every time step.
hₜ = tanh(Wₓxₜ + Wₕhₜ₋₁ + b)


W07 · H1 · Machine Learning in Engineering Science
Backpropagation through time multiplies Jacobians along earlier states.
∂hₜ/∂hₜ₋ₖ = Jₜ Jₜ₋₁ … Jₜ₋ₖ₊₁


W07 · H1 · Machine Learning in Engineering Science
The cell state carries memory; the hidden state exposes a filtered view.
cell: cₜ hidden output: hₜ


W07 · H1 · Machine Learning in Engineering Science
Sigmoid outputs values between zero and one for each hidden dimension.
σ(z) = 1 / (1 + exp(−z))


W07 · H1 · Machine Learning in Engineering Science
Multiply the previous cell state by a learned forget coefficient.
fₜ = σ(Wf [hₜ₋₁; xₜ] + bf)


W07 · H1 · Machine Learning in Engineering Science
A candidate proposes content; the input gate scales how much is written.
iₜ = σ(Wi [hₜ₋₁; xₜ] + bi) gₜ = tanh(Wg [hₜ₋₁; xₜ] + bg)


W07 · H1 · Machine Learning in Engineering Science
Retain selected old memory and add selected new content.
cₜ = fₜ ⊙ cₜ₋₁ + iₜ ⊙ gₜ


W07 · H1 · Machine Learning in Engineering Science
The hidden state is a bounded, gated view of the updated cell.
oₜ = σ(Wo [hₜ₋₁; xₜ] + bo) hₜ = oₜ ⊙ tanh(cₜ)


W07 · H1 · Machine Learning in Engineering Science
Chosen gates make every intermediate step visible.
0.9 × 0.8 + 0.2 × (−0.5) = 0.62
What is the hidden output?
h = 0.7 × tanh(0.62) ≈ 0.386.


W07 · H1 · Machine Learning in Engineering Science
A high forget coefficient does not prevent new content from changing memory.
cnew = f × cold + i × g


W07 · H1 · Machine Learning in Engineering Science
Run setup and inspect the synthetic sensor before fitting anything.


W07 · H1 · Machine Learning in Engineering Science
A correct shape is insufficient if the window contains its target.
X[i] = signal[t−24:t] y[i] = signal[t]


W07 · H1 · Machine Learning in Engineering Science
Ridge uses fixed window positions; LSTM updates a shared recurrent state.


W07 · H1 · Machine Learning in Engineering Science
batch_first changes input/output layout, not hidden-state layout.
input: (B,T,1) states: (B,T,H) hₙ: (layers,B,H)


W07 · H1 · Machine Learning in Engineering Science
Gradient updates use training; checkpoint selection uses validation.


W07 · H1 · Machine Learning in Engineering Science
Inspect actual training and validation trajectories in your notebook.



W07 · H1 · Machine Learning in Engineering Science
MAE averages error magnitude; RMSE emphasizes large residuals.
MAE = mean |ŷ−y| RMSE = √mean(ŷ−y)²



W07 · H1 · Machine Learning in Engineering Science
PyTorch concatenates its learned gate parameters in i, f, g, o order.
linear projections → split → activations → cell update



W07 · H1 · Machine Learning in Engineering Science
Change window length while preserving the forecast question and split boundaries.


W07 · H1 · Machine Learning in Engineering Science
Retention depends on learned gates, sequence structure, and optimization.
direct memory factor ≈ ∏ fⱼ


W07 · H1 · Machine Learning in Engineering Science
Order defines the task. LSTM gates control what memory is kept, written, and exposed.
cₜ = fₜ ⊙ cₜ₋₁ + iₜ ⊙ gₜ hₜ = oₜ ⊙ tanh(cₜ)
← → navigate · N notes · R answer · O overview · F fullscreen