← Lessons

quiz vs the machine

Gold1350

Machine Learning

The Siamese Networks

Two towers that share one set of weights to compare inputs in a shared space.

5 min read · core · beat Gold to climb

The shared tower idea

A Siamese network feeds two inputs through the same encoder, which means both branches share identical weights. The two resulting vectors live in one common space and are compared with a similarity or distance function.

Why share weights

Sharing weights guarantees that the two inputs are embedded consistently: a sentence encoded on the left and the same sentence on the right produce the same vector. It also halves the number of parameters and makes the comparison symmetric.

How it is trained

  • Feed a pair through the shared encoder.
  • Compute the distance between the two output vectors.
  • Apply a loss that wants matching pairs close and non matching pairs apart.

A common choice is the contrastive loss over pairs, or a triplet loss when three inputs are used.

Where it shows up

Siamese architectures power face verification, signature matching, duplicate question detection, and the Sentence BERT family of text encoders. Because the towers share weights, you can encode a large corpus once and reuse those vectors for fast comparison.

Key idea

A Siamese network embeds two inputs through one shared weight encoder so they land in a common space, making distance a consistent and symmetric measure of similarity.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the defining feature of a Siamese network?

2. Why does weight sharing matter for comparing inputs?