Shared layers: one set of weights, many call sites
Shared layers apply the same weights to different inputs. You get this for free from the callable-layer idea (lesson 02): construct a layer once, hold the instance, and call it on more than one tensor — every call reuses the same weights, and gradients from all call sites accumulate into that single weight set. The first Code block builds a Siamese network this way: one shared_embedding encodes both inputs, so the model learns a single embedding space in which 'similar' is a measurable distance. That weight tying is the whole point — if each input had its own encoder, there'd be no shared space to compare in.
Nested models: a model IS a layer
Any Keras Model can be called like a layer inside another model (second Code block). This is more than a convenience: it's the mechanism behind transfer learning. A pretrained backbone is just a Model you call on your input before attaching a fresh head — and because the nested model carries its own weights, loading pretrained weights and (optionally) freezing them with backbone.trainable = False works exactly as you'd expect. The same nesting is how encoder/decoder pairs compose into an autoencoder. Treat 'reuse a whole subgraph' and 'reuse a single layer' as the same move at different scales.