Encoder-decoders:
from autoencoders to foundation models

Session 26 · Wed Dec 2 · Book section 4.6 (enrichment: 569 required, 469 optional)

⌛

Today’s question

A seismic station records small local earthquakes on top of the ocean microseism, wind and traffic.

Can one network clean the record and time the P and S waves, and what do records without labels add when labels are few?

Reading: 4.6 Encoder-decoders · training and evaluating any network: lecture 24a

Four canonical networks: no new row today

An encoder-decoder is an arrangement of these layers, not a new layer.

This lecture in the literature

PhaseNet, 2019: a U-Net picker

EQTransformer, 2020: 3 decoders

SeisLM, 2024: no labels

Prithvi-EO-2.0, 2024: masking

PhaseNet: redrawn after Zhu & Beroza (2019), GJI 216:261. Reproduced under CC BY 4.0: Mousavi et al. (2020), Nat. Commun. 11:3952, Fig. 1, cropped and shortened; Liu et al. (2024), arXiv:2410.15765, Fig. 1; Szwarcman et al. (2024), arXiv:2412.02732v3, Fig. 3.

The data: one station, two kinds of noise

1,100 synthetic records of 32 s; half have an SNR below 6.5.

From autoencoders to foundation models

Four threads: the shape, seismology, pretraining without labels, experts.

Year of the journal or proceedings (masked autoencoder: CVPR 2022; Switch Transformer: JMLR 2022); arXiv year for preprints (Prithvi, 2023).

2006: deep autoencoders become trainable

Redrawn after Hinton & Salakhutdinov (2006), Science 313:504, Fig. 1, with its layer sizes. RBM: restricted Boltzmann machine.

Our autoencoder: error 0.414 through 50 numbers, 0.261 through 400.

Inside the notebook’s encoder-decoder

Notebook 4.6, cell 11: shapes for b = 8 channels, 7,249 weights. Record: test record 707 (SNR 6.0), clean signal, for example.

The length halves four times, 800 to 50; the bottleneck holds 8 × 50 = 400 numbers.

2015: the U-Net

Redrawn after Ronneberger et al. (2015), arXiv:1505.04597, Fig. 1, with the last box of each level. Above a box: channels; below: map size in pixels; white: the copied encoder map.

Each encoder map is copied to the decoder level of the same size, past the bottleneck.

Our U-Net: what a skip carries

Notebook 4.6: cells 11 and 25 (shapes), cell 27 (errors, 3 seeds). Record: test record 707, clean signal.

Skips carry the onset (0.04 s); denoising error 0.411 without them, 0.309 with them.

Leaderboard: denoising, three seeds (4.6)

Notebook 4.6, cells 7 and 27. Bar: mean; dot: one seed (0, 1, 2). The two references are built from each record’s clean signal.

The U-Net beats both references (0.309); without skips the network ties Wiener.

2019: DeepDenoiser, on real records

Redrawn after Zhu, Mousavi & Beroza (2019), IEEE TGRS 57:9476, Fig. 2 (data flow). Icon: test record 707 of notebook 4.6.

Two masks on the spectrogram, signal and noise, each inverted back to a waveform.

2019: PhaseNet, a U-Net that picks

Redrawn after Zhu & Beroza (2019), GJI 216:261, Fig. 5, with the sizes of arXiv:1803.03211 (Fig. 5 and Method). Numbers above a box: channels.

Three probability traces out, P, S and noise; the pick is the time of the peak.

2020: EQTransformer, one encoder, three decoders

Mousavi et al. (2020), Nat. Commun. 11:3952, Fig. 1, CC BY 4.0; cropped to the end of the encoder and the three decoders, with 5 of the 7 upsampling blocks of each decoder cut out (dots).

The end of one shared encoder, then three decoders: detection, P, S.

Multi-task: one encoder, two decoders

Notebook 4.6, cells 33 to 36 (loss, weights, picks per seed). Record and targets: test record 707 (SNR 6.0), for example.

One loss, the sum of both; 13,328 weights against 18,184 for two U-Nets.

Leaderboard: P picking, three seeds (4.6)

Notebook 4.6, cells 8 and 36. Bar: mean; dot: one seed (0, 1, 2).

Multi-task, by seed: 68.5, 70.8 and 5.8%. Seed 2 put 90.5% of its P picks on the S arrival; seed 0 or 1 alone would have hidden it.

2022: the masked autoencoder

He et al., arXiv:2111.06377 (2021; CVPR 2022), Fig. 1, CC BY 4.0.

Hide 75% of the patches, rebuild them, keep the encoder: no labels needed.

Pretrain without labels, then fine-tune on 20

Notebook 4.6, cells 40 to 45: 3 sets of 20 labeled records × 3 seeds per row.

20 labels, 9 runs each: 46.5% from scratch, 52.3% masked, 53.5% denoising.

Foundation models for Earth observation

Szwarcman et al. (2024), arXiv:2412.02732v3, Fig. 3, CC BY 4.0.

Pretrained by masking 4.2 million image time series; fine-tuned with one head per task.

2022: Switch Transformer, a router among experts

Fedus et al. (2022), JMLR 23(120), Fig. 2, CC BY 4.0; cropped to the switching layer, for two tokens.

A router picks 1 of 4 experts per token, scales its output by p; only it runs.

Mixture of experts, U-Net, multi-task decoders

Notebook 4.6, cell 48, seed 0: experts 0.204 against one decoder 0.216 (8,302 and 8,327 weights). Seeds 1 and 2 (notebook Exercise): 0.236, 0.215 against 0.228, 0.199.

Skips are not experts: every record takes every path. A mixture of experts learns, record by record, which decoder to trust.

Best practices: encoder-decoders

Step Practice Rubric
Split by record; no record in two sets A4
Baseline band-pass, Wiener reference, STA/LTA A6, C2.4
Design skips where timing matters C2.1, C2.3
Loss squared error for waveforms; cross-entropy per sample for picks D2
Seeds 3 seeds and 3 label sets; read every run D7, E3
Deploy real records: no clean signal, picks with errors E5

Now build it yourself: open 4.6

  1. pixi run jupyter lab → mlgeo_4.6_AutoEncoder.ipynb, Run all; Your turn (1): the compression ratio
  2. Your turn (2): join a skip connection
  3. Your turn (3): the multi-task loss; Your turn (4): freeze the encoder
  4. Optional, section 7: a mixture of experts; read the router’s choice

PyTorch names: nn.Conv1d, nn.ConvTranspose1d, torch.cat([h, skip], dim=1), requires_grad = False · the notebook runs in about 3 minutes on a laptop CPU · training loop: lecture 24a

Where encoder-decoders fit

A record in, a record of the same length out. The U-Net beat both filter references (0.309); pretraining raised 20-label picks from 47 to 52-54%.