ArticleslgStudy

computer science

Similarity learning

Similarity learning is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Similarity learning rather than just read about it. In short: Similarity learning is an area of supervised machine learning in artificial intelligence. It is closely related to regression and classification, but the goal is to learn a similarity function that measures how similar or related two objects are.

Key takeaways

  • Similarity learning belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Similarity learning to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Similarity learning from memory before moving on to harder problems.

Reference excerpt

Similarity learning is an area of supervised machine learning in artificial intelligence. It is closely related to regression and classification, but the goal is to learn a similarity function that measures how similar or related two objects are. It has applications in ranking, in recommendation systems, visual identity tracking, face verification, and speaker verification.

Learning setup There are four common setups for similarity and metric distance learning.

Regression similarity learning In this setup, pairs of objects are given (xi1,xi2) together with a measure of their similarity yi∈R. The goal is to learn a function that approximates f(xi1,xi2)∼yi for every new labeled triplet example (xi1,xi2,yi). This is typically achieved by minimizing a regularized loss minW∑iloss(w;xi1,xi2,yi)+reg(w). Classification similarity learning Given are pairs of similar objects (xi,xi+) and non similar objects (xi,xi−). An equivalent formulation is that every pair (xi1,xi2) is given together with a binary label yi∈{0,1} that determines if the two objects are similar or not. The goal is again to learn a classifier that can decide if a new pair of objects is similar or not. Ranking similarity learning Given are triplets of objects (xi,xi+,xi−) whose relative similarity obey a predefined order: xi is known to be more similar to xi+ than to xi−. The goal is to learn a function f such that for any new triplet of objects (x,x+,x−), it obeys f(x,x+)>f(x,x−) (contrastive learning). This setup assumes a weaker form of supervision than in regression, because instead of providing an exact measure of similarity, one only has to provide the relative order of similarity. For this reason, ranking-based similarity learning is easier to apply in real large-scale applications. Locality-sensitive hashing (LSH) Hashes input items so that similar items map to the same "buckets" in memory with high probability (the number of buckets being much smaller than the universe of possible input items). It is often applied in nearest neighbor search on large-scale high-dimensional data, e.g., image databases, document collections, time-series databases, and genome databases. A common approach for learning similarity is to model the similarity function as a bilinear form. For example, in the case of ranking similarity learning, one aims to learn a matrix W that parametrizes the similarity function fW(x,z)=xTWz. When data is abundant, a common approach is to learn a siamese network – a deep network model with parameter sharing.

Metric learning Similarity learning is closely related to distance metric learning. Metric learning is the task of learning a distance function over objects. A metric or distance function has to obey four axioms: non-negativity, identity of indiscernibles, symmetry and subadditivity (or the triangle inequality). In practice, metric learning algorithms ignore the condition of identity of indiscernibles and learn a pseudo-metric. When the objects xi are vectors in Rd, then any matrix W in the symmetric positive semi-definite cone S+d defines a distance pseudo-metric of the space of x through the form DW(x1,x2)2=(x1−x2)⊤W(x1−x2). When W is a symmetric positive definite matrix, DW is a metric. Moreover, as any symmetric positive semi-definite matrix W∈S+d can be decomposed as W=L⊤L where L∈Re×d and e≥rank(W), the distance function DW can be rewritten equivalently DW(x1,x2)2=(x1−x2)⊤L⊤L(x1−x2)=‖L(x1−x2)‖22. The distance DW(x1,x2)2=‖x1′−x2′‖22 corresponds to the Euclidean distance between the transformed feature vectors x1′=Lx1 and x2′=Lx2. Many formulations for metric learning have been proposed. Some well-known approaches for metric learning include learning from relative comparisons, which is based on the triplet loss, large margin nearest neighbor, and information theoretic metric learning (ITML). In statistics, the covariance matrix of the data is sometimes used to define a distance metric called Mahalanobis distance.

Applications Similarity learning is used in information retrieval for learning to rank, in face verification or face identification, and in recommendation systems. Also, many machine learning approaches rely on some metric. This includes unsupervised learning such as clustering, which groups together close or similar objects. It also includes supervised approaches like K-nearest neighbor algorithm which rely on labels of nearby objects to decide on the label of a new object. Metric learning has been proposed as a preprocessing step for many of these approaches.

Scalability Metric and similarity learning scale quadratically with the dimension of the input space, as can easily see when the learned metric has a bilinear form fW(x,z)=xTWz. Scaling to higher dimensions can be achieved by enforcing a sparseness structure over the matrix model, as done with HDSL, and with COMET.

Software metric-learn is a free software Python library which offers efficient implementations of several supervised and weakly-supervised similarity and metric learning algorithms. The API of metric-learn is compatible with scikit-learn. OpenMetricLearning is a Python framework to train and validate the models producing high-quality embeddings.

Further information For further information on this topic, see the surveys on metric and similarity learning by Bellet et al. and Kulis.

See also Kernel method Latent semantic analysis Learning to rank

References

Worked examples

Example 1 — a first encounter with Similarity learning

Start with the simplest possible case. Write down what Similarity learning claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Similarity learning before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Similarity learning ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Similarity learning

In research
Similarity learning appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Similarity learning in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Similarity learning is common in secondary-school and first-year university syllabi. It links to neighbouring topics Machine learning, Semantic relations, so understanding it makes those chapters shorter.
In everyday life
Look for Similarity learning outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Similarity learning” →

How to study Similarity learning in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Similarity learning means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Similarity learning out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Similarity learning in simple terms?

Similarity learning is an area of supervised machine learning in artificial intelligence. It is closely related to regression and classification, but the goal is to learn a similarity function that measures how similar or related two objects are.

Why does Similarity learning matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Similarity learning?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Similarity learning.

Tags

  • Machine learning
  • Semantic relations

Keep exploring