Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

4.6 Encoder-decoders: from autoencoders to foundation models

A seismometer records local earthquakes on top of noise: the ocean microseism at low frequencies, wind, traffic and machinery at higher frequencies. Two daily tasks of observational seismology are to clean the record (denoising) and to time the arrivals of the P and S waves (picking). Both take a time series in and give back a time series of the same length. An encoder-decoder is the network built for that. The encoder shrinks the record, step by step, into a short summary, the bottleneck; the decoder expands the summary back to the full length. Change what the decoder is asked to produce, and the same network compresses, denoises, picks, or does several of these at once.

This notebook follows the steps that led from autoencoders to foundation models, on one system: local earthquakes recorded at one seismic station.

stepideasection
autoencoderrebuild the input through a bottleneck3
U-Netskip connections carry the detail of each scale past the bottleneck4
multi-taskone encoder shared by one decoder per task5
pretrain, then fine-tunetrain the encoder on records without labels, then a task with few labels6
mixture of experts (optional)a router weights two decoders for each record7

Learning outcomes. After this notebook you can:

  1. follow the shape of a record through an encoder and a decoder, and compute the compression of a bottleneck;

  2. train an encoder-decoder to denoise a seismogram, and explain what skip connections change;

  3. train a phase picker on probability-trace labels, alone and as one of two tasks sharing an encoder, and rank it against STA/LTA;

  4. pretrain an encoder without labels, fine-tune it or freeze it, and measure what it gives when labels are few;

  5. say how a mixture of experts differs from the skip connections and the task decoders of a U-Net.

From the literature. Networks that rebuild their input through a narrow layer date from the 1980s (Rumelhart et al., 1986; Kramer, 1991); Hinton & Salakhutdinov (2006) made deep ones trainable. The U-Net (Ronneberger et al., 2015) joins encoder and decoder at every scale. In seismology, PhaseNet (Zhu & Beroza, 2019) picks P and S with a U-Net, DeepDenoiser (Zhu, Mousavi & Beroza, 2019) separates earthquake from noise, and EQTransformer (Mousavi et al., 2020) shares one encoder among three decoders. Masked autoencoders (He et al., 2022) pretrain an encoder without labels, the recipe that foundation models for Earth data such as Prithvi (Jakubik et al., 2023) and Aurora (Bodnar et al., 2025) apply at scale. A mixture of experts (Jacobs et al., 1991; Shazeer et al., 2017; Fedus et al., 2022) lets a router choose among sub-networks for each input.

🖥️ Lecture slides: encoder-decoders (enrichment, session 26)

1. The data: local earthquakes at one station

mlgeo_synth.synthetic_seismogram draws one vertical record of a local earthquake: a P wavelet at 5 Hz arriving at 5 s + distance / (6 km/s), an S wavelet twice as large at 3 Hz arriving at 5 s + distance / (3.5 km/s), and noise whose power falls with frequency ff as 1/fc1/f^{c}. The exponent cc is the noise color: c=0c = 0 is white noise, c=2c = 2 puts most of the noise power at low frequencies, as the ocean microseism does. The signal-to-noise ratio (SNR) is the peak of the signal divided by the standard deviation of the noise. Each record draws its own:

parameterrange
magnitude1 to 3, uniform
distance5 to 60 km, uniform
SNR1.5 to 30, uniform in log
noise color cc0 to 2, uniform

We sample at 25 Hz for 32 s, 800 samples. The clean signal is known exactly: we build each record a second time with the same seed and snr=1e12, which divides the noise by 1012. The P and S arrival times come with each record (t_p, t_s).

Split by record. Each record is its own earthquake with its own noise, and no part of a record appears in two sets: 500 records train, 200 validate, 400 test. In lecture 25 (case 1), overlapping windows cut from the same records fell on both sides of a split, and a detector that scored 0.97 on its test windows scored 0.76 on new records.

train      500 records
validation 200 records
test       400 records
Loading...
<Figure size 900x460 with 2 Axes>

Top: a record with an SNR above 15, where both waves stand out. Bottom: an SNR below 3, where the P wave is hidden in the noise. Half of the records have an SNR below 6.5 (the 50% row of the table), and the P wave has half the amplitude of the S wave, so on most records the P arrival is hard to see.

2. Baselines first

The methods a seismologist would use before any network, scored the way the networks will be.

  • Denoising: a band-pass filter. A zero-phase Butterworth filter of order 4. We try 20 bands and keep the one with the lowest error on the training records.

  • Denoising score: error against the clean signal. The rms of (output − clean signal) divided by the rms of the clean signal, averaged over the 400 test records; 0 is perfect. We also give the SNR gain, in dB: 20 log10 (rms of the noise in the record / rms of the error left in the output).

  • Two references, not baselines, built for each record from its own clean signal, which no method can know: the Wiener filter, built from the record’s own signal and noise power spectra, and the best gain per frequency, a number between 0 and 1 for each frequency, chosen to bring that record closest to its clean signal. Both weight each frequency the same way at every time.

  • Picking: STA/LTA (Allen, 1978), the ratio of the short-term to the long-term average of the squared trace. The P pick is the first sample where the ratio exceeds a threshold. STA, LTA, threshold, and whether to run it on the recorded or the band-passed trace are chosen on the training records.

  • Picking score: the percentage of test records whose P pick is within 0.5 s of the true arrival, and the median of |pick − true arrival|. A record without a trigger counts as a miss. The arrival times are exact, so the floor is 0 s, within one sample (0.04 s).

band chosen on the training records: 2 to 4 Hz
recorded trace, unfiltered                                 error 1.982   SNR gain   0.0 dB
band-pass 2-4 Hz                                           error 0.725   SNR gain   6.8 dB
reference: Wiener filter that knows the clean spectrum     error 0.428   SNR gain  11.8 dB
reference: best gain per frequency, knows the clean signal error 0.391   SNR gain  12.6 dB
best on the training records, recorded trace: 44.2% of P picks within 0.5 s
best on the training records, band-passed 2-4 Hz trace: 34.2% of P picks within 0.5 s
kept: recorded trace, STA 0.2 s, LTA 5.0 s, threshold 4
test: median P pick error 1.53 s, 37.5% of P picks within 0.5 s

The 2 to 4 Hz band brings the error from 1.98 (the record as recorded: the noise is larger than the signal on most records) down to 0.725, an SNR gain of 6.8 dB. The Wiener filter reaches 0.428 (11.8 dB) and the best gain per frequency 0.391 (12.6 dB): a filter tuned to each record’s own clean signal still leaves about 40% of the signal’s rms as error, because the signal (3 and 5 Hz) and the noise share the same frequencies. STA/LTA puts 37.5% of the P picks within 0.5 s of the arrival, with a median error of 1.53 s. On the training records it does worse on the 2 to 4 Hz band-passed trace (34.2% against 44.2%), because the band cuts into the 5 Hz P wavelet, so the recorded trace is kept.

3. The encoder-decoder shape

The encoder is a stack of four 1-D convolution blocks (4.3). Each block slides 5-sample filters along the record and keeps every second output (a stride of 2), so the length halves while the number of channels grows: 800 → 400 → 200 → 100 → 50 samples, 1 → 8 → 16 → 16 → 32 channels. A 1 × 1 convolution then reduces the 32 channels to b: the bottleneck holds b × 50 numbers. The decoder mirrors the encoder with transposed convolutions. A transposed convolution spreads each input sample over a 4-sample kernel and places the outputs of neighboring input samples 2 samples apart, so 50 samples become 100. Four blocks bring the record back to 800 samples; a last convolution gives the output channels.

The shape after each block, for one record:

input             (1, 1, 800)
encoder block 1   (1, 8, 400)
encoder block 2   (1, 16, 200)
encoder block 3   (1, 16, 100)
encoder block 4   (1, 32, 50)
bottleneck        (1, 8, 50)
decoder block 1   (1, 16, 100)
decoder block 2   (1, 16, 200)
decoder block 3   (1, 8, 400)
decoder block 4   (1, 8, 800)
output            (1, 1, 800)
7249 weights

One training loop

Every network of this notebook trains with the loop of the training block (section 2.4 of 4.7). one_epoch shuffles the records and makes one update per batch with the same four lines; train_model keeps the weights of the epoch with the lowest validation loss (the checkpoint). The starting weights are random numbers drawn after torch.manual_seed(seed), never zeros. The optimizer is Adam, with a learning rate α=3×10−3\alpha = 3 \times 10^{-3}, batches of 32 records and 20 epochs. From section to section, only the data and the loss (criterion) change.

The autoencoder

An autoencoder is an encoder-decoder trained to give back its input: here the clean signal in, the clean signal out, and the mean squared error between the two as the loss. Nothing reaches the output except through the bottleneck, so the size of the bottleneck limits what the decoder can rebuild. We train two, with b = 1 channel (50 numbers) and b = 8 channels (400 numbers).

bottleneck 1 x 50 =  50 numbers: test error 0.422, 6570 weights, 3.7 s, best epoch 19
bottleneck 8 x 50 = 400 numbers: test error 0.264, 7249 weights, 3.2 s, best epoch 19
<Figure size 900x260 with 1 Axes>

Through 400 numbers the autoencoder rebuilds the test records with an error of 0.261; through 50 numbers, 0.414. Both validation losses were still falling at the last epoch (best epoch 19, counted from 0): longer training would lower both errors, and we stop at 20 epochs to keep the notebook to about 3 minutes. In the figure, both rebuild the S wave; through 50 numbers, the first swings of the P wave come out smaller than they are.

Your turn (1): the compression ratio

How many times fewer numbers does the bottleneck hold than the input? Compute the ratio (numbers in the input / numbers in the bottleneck) for the two autoencoders. Read the shapes printed above: the input is 1 channel × 800 samples, the bottleneck b channels × 50 samples. One line.

Answer below (click to open it).

Notebook Cell
{1: 16.0, 8: 2.0}

4. Denoising, and skip connections: the U-Net

Keep the target, change the input: the noisy record in, the clean signal out. The network now has to learn which part of a record is earthquake and which is noise. We train the encoder-decoder of section 3 (b = 8) twice: as it is, and with skip connections. After each decoder block, the encoder output of the same length is joined to the decoder’s channels, so the detail of the record at each scale reaches the decoder without going through the bottleneck. An encoder-decoder with skip connections at every scale is a U-Net (Ronneberger et al., 2015); drawn with the encoder going down on the left and the decoder going up on the right, it has the shape of a U.

Your turn (2): join a skip connection

Decoder.forward calls join(h, skip) after each decoder block. h has shape (records, channels of the decoder, length) and skip, the encoder output of the same length, has shape (records, channels of the encoder, length). Write the one line that puts them side by side along the channel dimension. Hint: torch.cat([...], dim=1).

Answer below (click to open it).

Notebook Cell
bottleneck        (1, 8, 50)
decoder block 1   (1, 16, 100) + encoder (1, 16, 100) -> (1, 32, 100)
decoder block 2   (1, 16, 200) + encoder (1, 16, 200) -> (1, 32, 200)
decoder block 3   (1, 8, 400) + encoder (1, 8, 400) -> (1, 16, 400)
decoder block 4   (1, 8, 800) + encoder (1, 1, 800) -> (1, 9, 800)
output            (1, 1, 800)
9046 weights, against 7249 without the skips
encoder-decoder, no skips, seed 0: test error 0.423, SNR gain 10.6 dB, 3.3 s, best epoch 19
encoder-decoder, no skips, seed 1: test error 0.410, SNR gain 10.9 dB, 3.3 s, best epoch 19
encoder-decoder, no skips, seed 2: test error 0.401, SNR gain 11.1 dB, 3.3 s, best epoch 19
U-Net (encoder-decoder with skips), seed 0: test error 0.327, SNR gain 14.4 dB, 5.0 s, best epoch 19
U-Net (encoder-decoder with skips), seed 1: test error 0.301, SNR gain 15.2 dB, 4.7 s, best epoch 19
U-Net (encoder-decoder with skips), seed 2: test error 0.298, SNR gain 15.3 dB, 4.2 s, best epoch 19
Loading...
<Figure size 900x600 with 4 Axes>

Ranked by error against the clean signal (mean ± sample standard deviation over 3 seeds):

  • U-Net: 0.309 ± 0.017, an SNR gain of 14.9 dB, 9,046 weights.

  • References built from each record’s clean signal: best gain per frequency 0.391 (12.6 dB); Wiener filter 0.428 (11.8 dB).

  • Encoder-decoder without skips: 0.411 ± 0.011, 10.9 dB, 7,249 weights.

  • Band-pass 2 to 4 Hz: 0.725 (6.8 dB).

The skip connections add 1,797 weights and lower the error by a quarter, from 0.411 to 0.309. Only the U-Net beats both references. A filter weights each frequency the same way at every time, while the U-Net removes the noise before the P arrival and keeps the 3 to 5 Hz energy after it (figure). Without skips the network ties the Wiener filter: lower error (0.411 against 0.428), lower dB gain (10.9 against 11.8). The two scores average differently. The error is a mean of ratios, dominated by the hard, low-SNR records, where the network does better (0.53 against 0.65 on the third of the test records with the lowest SNR). The dB gain is a mean of logarithms, which counts halving the error on an easy record as much as on a hard one, and on the third with the highest SNR the Wiener filter does better (0.21 against 0.33). Both networks were still improving at epoch 20 (best epoch 19).

5. Multi-task: one encoder, two decoders

A phase picker is an encoder-decoder whose output is not a waveform but three probability traces: P, S and “no arrival”, which sum to 1 at each sample. The labels are Gaussian bumps of standard deviation 0.2 s centered on the true arrival times, as PhaseNet labels its records (Zhu & Beroza, 2019); the “no arrival” trace is what is left. The loss is the cross-entropy between the predicted and the label traces, the loss of classification (3.6), computed at every sample. The P pick is the time of the largest P probability.

A multi-task network shares one encoder between two decoders: one gives the clean waveform (the task of section 4), the other the three probability traces. EQTransformer (Mousavi et al., 2020) shares one encoder among three decoders in the same way. The loss is a weighted sum of the two task losses, L=Lwave+λ Lpick\mathcal{L} = \mathcal{L}_{wave} + \lambda\,\mathcal{L}_{pick}, and the gradients of both reach the same encoder weights. Both decoders run on every record. We use λ=1\lambda = 1. While building the notebook we also looked at the test scores of λ\lambda = 0.5 to 10, which a study should not do (choose it on the validation loss); none changed the result below.

targets of the multi-task network: (500, 4, 800) (records, 1 + 3 channels, samples)

Your turn (3): the multi-task loss

The multi-task network returns 4 channels: the clean waveform (channel 0) and the 3 probability traces (channels 1 to 3). Write the line that combines the two task losses into one: a weighted sum, with weight lam on the picking loss. Gradient descent then updates the shared encoder with the gradient of this sum.

Answer below (click to open it).

Notebook Cell
picker alone (U-Net, 1 decoder), seed 0: 70.0% of P picks within 0.5 s (median error 0.11 s), 23.0% within 0.5 s of the S arrival; 97.2% of S picks within 0.5 s; 4.3 s
picker alone (U-Net, 1 decoder), seed 1: 68.2% of P picks within 0.5 s (median error 0.07 s), 22.0% within 0.5 s of the S arrival; 98.0% of S picks within 0.5 s; 4.4 s
picker alone (U-Net, 1 decoder), seed 2: 69.2% of P picks within 0.5 s (median error 0.10 s), 24.0% within 0.5 s of the S arrival; 96.2% of S picks within 0.5 s; 4.4 s
multi-task (U-Net, shared encoder, 2 decoders), seed 0: 68.2% of P picks within 0.5 s (median error 0.20 s), 22.8% within 0.5 s of the S arrival; 97.8% of S picks within 0.5 s; 7.3 s
multi-task (U-Net, shared encoder, 2 decoders), seed 1: 70.2% of P picks within 0.5 s (median error 0.10 s), 22.8% within 0.5 s of the S arrival; 97.8% of S picks within 0.5 s; 7.2 s
multi-task (U-Net, shared encoder, 2 decoders), seed 2: 7.0% of P picks within 0.5 s (median error 3.56 s), 89.2% within 0.5 s of the S arrival; 95.2% of S picks within 0.5 s; 7.2 s
waveform error of the multi-task network: 0.329
Loading...
<Figure size 900x420 with 2 Axes>

Figure: seed 0, test record 707 (SNR 6.0). The P probability reaches only about 0.35 at the P arrival. Even the runs that trained put 21 to 25% of their P picks within 0.5 s of the S arrival: on low-SNR records the P wave, half as large as the S wave, is not seen.

Ranked by the percentage of P picks within 0.5 s (mean ± sample standard deviation over 3 seeds):

  • The picker alone: 69.3 ± 1.4%, median error 0.09 s, against 37.5% and 1.53 s for STA/LTA.

  • The multi-task network: 68.5% and 70.8% on seeds 0 and 1, as good as the picker alone, but 5.8% on seed 2, so 48.3 ± 36.9%. Seed 2 put 90.5% of its P picks within 0.5 s of the S arrival while 95.8% of its S picks were right: it found the arrivals and swapped them. Seed 0 or seed 1 alone would have hidden this. Its waveform decoder scores 0.331 (mean of 3 seeds), close to the U-Net denoiser (0.309), and the network does both tasks with 13,328 weights, against 9,046 + 9,138 = 18,184 for two U-Nets.

6. Pretrain, then fine-tune: the foundation-model idea in miniature

Arrival-time labels are expensive: each needs an analyst, and a new station has none. Records without labels are cheap: a station writes them every day. A foundation model is trained once on a large amount of data without labels, then adapted to many tasks with few labels each. Training without labels needs a pretext task whose answer is in the data itself. Masked autoencoders (He et al., 2022) hide parts of the input and train the network to fill them in.

The same steps, in miniature:

  1. Pretrain. A U-Net learns to fill in 1,500 new records without arrival times: four 1-s stretches of each record are set to 0, and the loss is the squared error on the hidden samples only.

  2. Fine-tune with 20 labeled records (and 20 more for validation), batches of 5, 60 epochs. The picker starts from scratch, or from the pretrained encoder, which is either fine-tuned (all weights updated) or frozen (only the decoder is updated). Which 20 records an analyst happens to label changes the result, so each row repeats with three sets of 20 (training records 0-19, 20-39 and 40-59, each with its own 20 validation records) and three seeds: 9 runs per row. We chose 20 labels, 60 epochs and batches of 5 in trial runs that we scored on the test records; read the small differences below with that in mind.

  3. A second pretext. The U-Net denoiser of section 4 (seed 0) was also trained without arrival times, but with clean signals as targets, which real data never give. DeepDenoiser builds such training pairs by adding recorded noise to earthquake records of high SNR (Zhu, Mousavi & Beroza, 2019). Its encoder is a second starting point.

masked pretraining on 1300 records: validation loss 0.617 (the hidden samples have variance 1.011), 5.0 s
<Figure size 900x240 with 1 Axes>

Your turn (4): freeze the encoder

make_picker builds a picker and, if a pretrained model is given, copies its encoder weights. Write the lines that freeze the encoder when freeze=True: its weights get no gradient, so the updates change only the decoder. Hint: a for loop over model.encoder.parameters(), setting .requires_grad = False. Two lines.

Answer below (click to open it).

Notebook Cell
4546 of 9138 weights are trained
from scratch                          46.7 ± 10.3% of P picks within 0.5 s;  mean of each draw: 42.4, 51.3, 46.2;  lowest run 32.2
masked pretraining, fine-tuned        53.6 ±  5.0% of P picks within 0.5 s;  mean of each draw: 50.9, 54.8, 54.9;  lowest run 46.5
masked pretraining, encoder frozen    49.3 ±  4.9% of P picks within 0.5 s;  mean of each draw: 50.9, 46.8, 50.2;  lowest run 40.2
denoising pretraining, fine-tuned     59.1 ±  3.3% of P picks within 0.5 s;  mean of each draw: 60.6, 59.7, 57.0;  lowest run 51.7
Loading...

With 20 labeled records (mean ± sample standard deviation over 9 runs: 3 sets of 20 labeled records × 3 seeds):

  • From scratch: 46.5 ± 10.2% of P picks within 0.5 s, above STA/LTA (37.5%); runs from 32.2 to 58.2%.

  • Masked pretraining: 52.3 ± 7.3% fine-tuned, 50.3 ± 6.0% with the encoder frozen (4,546 of 9,138 weights trained). Pretraining on records without a single arrival time raised the mean by 4 to 6 points.

  • Denoising pretraining, fine-tuned: 53.5 ± 16.5%. Eight of its nine runs fall between 53.0 and 62.5%, against 69.3% with 500 labels; the ninth (records 40-59, seed 1) fell to 10.2%.

The mean of each row also depends on which 20 records were labeled: from scratch, 42.4, 51.2 and 45.9% for the three sets; denoising pretraining, 58.8, 57.5 and 44.2%. With the first set alone (records 0-19) and three seeds, denoising pretraining looks 16 points better than training from scratch (58.8 against 42.4%); over the three sets the gap is 7 points, smaller than the spread of the runs. Pretraining helps on average here, but 20 labels are too few to rank the two pretexts. A frozen encoder keeps features learned for another task; fine-tuning lets the 20 labeled records adjust them. The masked network explains 39% of the variance of what it cannot see (validation loss 0.617, against a variance of 1.011 for the hidden samples): in the figure, the filled stretches follow the slow swings of the noise, which is most of a record.

Foundation models apply the same three choices at scale: what to pretrain on, which pretext, and how much of the encoder to update with the labels of each new task.

7. Optional: a mixture of experts

Optional; it runs in about 15 s and nothing after it depends on it.

A U-Net uses every weight on every record. A mixture of experts (Jacobs et al., 1991) holds several sub-networks, the experts, and a small router that reads the input and gives expert kk a weight wkw_k, with ∑kwk=1\sum_k w_k = 1. Ours is a soft mixture: both experts run on every record and the output is ∑kwky^k\sum_k w_k \hat y_k; the Switch Transformer (Fedus et al., 2022) runs only the expert with the largest weight, to save computation.

The test: a station with two noise regimes, 400 records with low-frequency noise (color 2, like the ocean microseism) and 400 with high-frequency noise (color −1.5, like traffic). One encoder, two narrow decoders (the experts) and a router (one linear layer on the time average of each encoder output, then a softmax), never told the regime; against one decoder with about the same number of weights. The model returns the two experts’ outputs and the router’s two log-weights as 4 channels, so that train_model runs unchanged.

The loss of a record, where eke_k is the mean squared error of expert kk and wˉk\bar w_k the average weight of expert kk over the batch, for K=2K = 2 experts:

L=−log⁡∑kwkexp⁡(−ek2σ2)  +  balance×K∑kwˉk 2\mathcal{L} = -\log \sum_{k} w_k \exp\left(-\frac{e_k}{2\sigma^2}\right) \; + \; \text{balance} \times K \sum_k \bar w_k^{\,2}

The first term (Jacobs et al., 1991) is small when the router puts its weight on the expert that fits the record best, so the experts compete instead of averaging. σ2=0.01\sigma^2 = 0.01 is the variance the error of an expert is assumed to have. The second term is smallest when the experts receive equal shares of the records; the Switch Transformer adds a load-balancing term for the same reason. We use balance = 1; we also looked at the test errors of 0.3 and 3 (which a study should not do), and the two-expert error moved by less than 0.01.

one decoder:       8327 weights, test error 0.216, 3.9 s
two experts:       8302 weights, test error 0.204, 5.5 s
router choice agrees with the noise regime for 100.0% of the 200 test records
Loading...

For seed 0, the router sends every one of the 200 test records to the expert of its noise regime (expert 0 takes the 117 low-frequency records, expert 1 the 83 high-frequency records), although it was never told the regime. The two experts reach an error of 0.204, against 0.216 for one decoder with about the same number of weights (8,302 and 8,327).

Exercise. Rerun the cell above with seeds 1 and 2 (torch.manual_seed(1) before both models), then without the balance term: train_model(moe, d7, lambda out, y: experts_loss(out, y, balance=0.0)). Our runs: 100% agreement again, but the experts scored 0.236 and 0.215 against 0.228 and 0.199 for one decoder, so over three seeds they do not lower the error; without the balance term, seeds 1 and 2 sent every record to one expert (58.5% agreement, the share of the larger regime). What the mixture gives here is a choice that can be read: the kind of noise the network found in each record.

Are the skip connections of a U-Net experts? No. Every record takes every skip and every decoder block: the path does not depend on the input. The two decoders of the multi-task network of section 5 are not experts either: both run on every record and their losses are summed. A task decoder acts as a router set by hand only when a task label picks which decoder runs, as when a foundation model gets one fine-tuned head per task. The multi-gate mixture of experts (Ma et al., 2018) joins the two ideas: several task decoders, each with its own learned router over shared experts.

8. Summary

networkrecord in → outtest score (mean ± std, 3 seeds)weightsbaseline
autoencoder, bottleneck 50 / 400 numbersclean → cleanerror 0.414 / 0.261 (1 seed)6,570 / 7,249
encoder-decoder, no skipsnoisy → cleanerror 0.411 ± 0.011 (10.9 dB)7,249band-pass 0.725; references: Wiener 0.428, best gain 0.391
U-Netnoisy → cleanerror 0.309 ± 0.017 (14.9 dB)9,046band-pass 6.8 dB
U-Net picker, 500 labelsnoisy → P, S, no-arrival69.3 ± 1.4% P picks within 0.5 s9,138STA/LTA 37.5%
multi-task U-Net, 500 labelsnoisy → clean + probabilities48.3 ± 36.9% (seeds: 68.5, 70.8, 5.8)13,328STA/LTA 37.5%
U-Net picker, 20 labels: scratch / masked pretraining / denoising pretraining (fine-tuned)noisy → probabilities46.5 ± 10.2 / 52.3 ± 7.3 / 53.5 ± 16.5% (9 runs: 3 label sets × 3 seeds)9,138STA/LTA 37.5%
two experts and a router (optional)noisy → clean, 2 noise regimeserror 0.204, router right on 100% (seed 0)8,302one decoder 0.216
  • An encoder-decoder maps a record to a record of the same length through a bottleneck. The target sets what the output means: the same record (autoencoder), the clean signal (denoiser), arrival probabilities (picker).

  • Skip connections carry the detail of each scale past the bottleneck: the U-Net cut the denoising error by a quarter for 1,797 more weights, and only the U-Net beat the filters built from each record’s clean signal.

  • One encoder can serve one decoder per task (EQTransformer). Report every seed: one start out of three called the S wave P, which seed 0 or seed 1 alone would have hidden.

  • Pretraining on records without labels made 20 labels go further on average: 47% of P picks within 0.5 s from scratch, 52% after masked pretraining, 54% after denoising pretraining (9 runs each). Which 20 records were labeled moved the means as much as the choice of pretext did.

  • Foundation models for Earth data, such as Prithvi and Aurora, apply this recipe at scale, with attention layers (4.4; Vaswani et al., 2017) in their encoders.

  • A mixture of experts learns a router that weights its decoders record by record. Skip connections and the decoders of a multi-task network make no such choice: every record takes every path.

The training loop, the checkpoint, the seeds and the leaderboards of this notebook are those of the training block, 4.7.

Now on real data. The homework (Homework_DL) trains a convolutional detector on real seismograms. On real records the clean signal is never known: DeepDenoiser builds its training pairs from high-SNR earthquake records and recorded noise, and PhaseNet trains on picks made by analysts, so a picker is scored against picks that have errors of their own.

Reflect on this notebook

As for every assignment in this course (1.8), a few sentences each:

  1. What did you learn from this exercise? Name the scientific or technical idea, with one example from your own work in this notebook.

  2. What did you learn from interacting with agents or chatbots? Say what you asked, what the tool got right, what it got wrong, and how you checked it.

  3. What would you suggest to improve this notebook so it meets its learning goals? Be specific.

References

  • Allen, R. V. (1978). Automatic earthquake recognition and timing from single traces. Bulletin of the Seismological Society of America, 68(5), 1521–1532. Allen (1978)

  • Bodnar, C., Bruinsma, W. P., Lucic, A., Stanley, M., Allen, A., Brandstetter, J., et al. (2025). A foundation model for the Earth system. Nature, 641(8065), 1180–1187. Bodnar et al. (2025)

  • Fedus, W., Zoph, B., & Shazeer, N. (2022). Switch Transformers: scaling to trillion parameter models with simple and efficient sparsity. Journal of Machine Learning Research, 23(120), 1–39. https://jmlr.org/papers/v23/21-0998.html (arXiv:2101.03961)

  • He, K., Chen, X., Xie, S., Li, Y., Dollár, P., & Girshick, R. (2022). Masked autoencoders are scalable vision learners. IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 15979–15988. He et al. (2022)

  • Hinton, G. E., & Salakhutdinov, R. R. (2006). Reducing the dimensionality of data with neural networks. Science, 313(5786), 504–507. Hinton & Salakhutdinov (2006)

  • Jacobs, R. A., Jordan, M. I., Nowlan, S. J., & Hinton, G. E. (1991). Adaptive mixtures of local experts. Neural Computation, 3(1), 79–87. Jacobs et al. (1991)

  • Jakubik, J., Roy, S., Phillips, C. E., Fraccaro, P., Godwin, D., et al. (2023). Foundation models for generalist geospatial artificial intelligence. arXiv:2310.18660. https://arxiv.org/abs/2310.18660

  • Kramer, M. A. (1991). Nonlinear principal component analysis using autoassociative neural networks. AIChE Journal, 37(2), 233–243. Kramer (1991)

  • Ma, J., Zhao, Z., Yi, X., Chen, J., Hong, L., & Chi, E. H. (2018). Modeling task relationships in multi-task learning with multi-gate mixture-of-experts. Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 1930–1939. Ma et al. (2018)

  • Mousavi, S. M., Ellsworth, W. L., Zhu, W., Chuang, L. Y., & Beroza, G. C. (2020). Earthquake transformer: an attentive deep-learning model for simultaneous earthquake detection and phase picking. Nature Communications, 11, 3952. Mousavi et al. (2020)

  • Ronneberger, O., Fischer, P., & Brox, T. (2015). U-Net: convolutional networks for biomedical image segmentation. Medical Image Computing and Computer-Assisted Intervention (MICCAI), Lecture Notes in Computer Science 9351, 234–241. Ronneberger et al. (2015), arXiv:1505.04597

  • Rumelhart, D. E., Hinton, G. E., & Williams, R. J. (1986). Learning internal representations by error propagation. In D. E. Rumelhart & J. L. McClelland (Eds.), Parallel Distributed Processing, Vol. 1, 318–362. MIT Press.

  • Shazeer, N., Mirhoseini, A., Maziarz, K., Davis, A., Le, Q., Hinton, G., & Dean, J. (2017). Outrageously large neural networks: the sparsely-gated mixture-of-experts layer. International Conference on Learning Representations. https://arxiv.org/abs/1701.06538

  • Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, Ł., & Polosukhin, I. (2017). Attention is all you need. Advances in Neural Information Processing Systems, 30. https://arxiv.org/abs/1706.03762

  • Zhu, W., & Beroza, G. C. (2019). PhaseNet: a deep-neural-network-based seismic arrival-time picking method. Geophysical Journal International, 216(1), 261–273. https://doi.org/10.1093/gji/ggy423

  • Zhu, W., Mousavi, S. M., & Beroza, G. C. (2019). Seismic signal denoising and decomposition using deep neural networks. IEEE Transactions on Geoscience and Remote Sensing, 57(11), 9476–9488. Zhu et al. (2019)

References
  1. Allen, R. V. (1978). Automatic earthquake recognition and timing from single traces. Bulletin of the Seismological Society of America, 68(5), 1521–1532. 10.1785/bssa0680051521
  2. Bodnar, C., Bruinsma, W. P., Lucic, A., Stanley, M., Allen, A., Brandstetter, J., Garvan, P., Riechert, M., Weyn, J. A., Dong, H., Gupta, J. K., Thambiratnam, K., Archibald, A. T., Wu, C.-C., Heider, E., Welling, M., Turner, R. E., & Perdikaris, P. (2025). A foundation model for the Earth system. Nature, 641(8065), 1180–1187. 10.1038/s41586-025-09005-y
  3. He, K., Chen, X., Xie, S., Li, Y., Dollar, P., & Girshick, R. (2022). Masked Autoencoders Are Scalable Vision Learners. 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 15979–15988. 10.1109/cvpr52688.2022.01553
  4. Hinton, G. E., & Salakhutdinov, R. R. (2006). Reducing the Dimensionality of Data with Neural Networks. Science, 313(5786), 504–507. 10.1126/science.1127647
  5. Jacobs, R. A., Jordan, M. I., Nowlan, S. J., & Hinton, G. E. (1991). Adaptive Mixtures of Local Experts. Neural Computation, 3(1), 79–87. 10.1162/neco.1991.3.1.79
  6. Kramer, M. A. (1991). Nonlinear principal component analysis using autoassociative neural networks. AIChE Journal, 37(2), 233–243. 10.1002/aic.690370209
  7. Ma, J., Zhao, Z., Yi, X., Chen, J., Hong, L., & Chi, E. H. (2018). Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts. Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 1930–1939. 10.1145/3219819.3220007
  8. Mousavi, S. M., Ellsworth, W. L., Zhu, W., Chuang, L. Y., & Beroza, G. C. (2020). Earthquake transformer—an attentive deep-learning model for simultaneous earthquake detection and phase picking. Nature Communications, 11(1). 10.1038/s41467-020-17591-w
  9. Ronneberger, O., Fischer, P., & Brox, T. (2015). U-Net: Convolutional Networks for Biomedical Image Segmentation. In Lecture Notes in Computer Science (pp. 234–241). Springer International Publishing. 10.1007/978-3-319-24574-4_28
  10. Zhu, W., Mousavi, S. M., & Beroza, G. C. (2019). Seismic Signal Denoising and Decomposition Using Deep Neural Networks. IEEE Transactions on Geoscience and Remote Sensing, 57(11), 9476–9488. 10.1109/tgrs.2019.2926772