In the Andrew-NG coursera course on Convnets he talked about triplet loss function for one shot face recognition.

The formula given in the video is, $$\to \small \small \small ||f(A)-f(P)||^2 \;+\;\alpha \leq\;||f(A)-f(N)||^2$$ $$\to \small \small \small D(A, P) + \alpha \leq D(A, N)$$ $$L(A,P,N) = max(||f(A)-f(P)||^2 - ||f(A)-f(N)||^2 + \alpha, 0)$$ Here, $$f(A) - \small \text{ Person }A$$ $$f(P) - \small \text{Different Picture of Person }A$$ $$F(N) - \small \text{Another Person}$$

I couldn't understand why did we use $\alpha$ in the formula. I understood that the ideal loss function is to decrease $\small \small D(A, P)$ and increase $\small \small D(A, N)$ but if we add $\alpha$ to $\small \small D(A,P)$ it will increase it which is not we require right?


1 Answer 1


$\alpha$ is known as the margin.

Not only that we want to minimize $D(A,P)$ and maximize $D(A,N)$, that is we want $D(A,P)-D(A,N)$ to be small. Not only that we want it to be non-positive, we want it to be sufficiently negative.

That is not only that we want $$D(A,P)-D(A,N) \le 0$$

We want $$D(A,P)-D(A,N) \le -\alpha.$$

  • 1
    $\begingroup$ "Not only that we want it to be non-positive, we want it to be sufficiently negative." Can you elaborate a bit please. I didn't get it. $\endgroup$
    – Jeeth
    Jul 12, 2019 at 6:11
  • 2
    $\begingroup$ Analogy for maximization of score in exam: Your teacher might say do $50$ push up if you get a scoare that is below $50$ marks in your exam. But being a motivated learning, you can set the bar to be higher and say you will still do $50$ push up if you get a score that is below $75$, hence you will work harder to avoid the punishment. It is like a "standard" that you set. For our setting, we want to be sufficiently negative. $\endgroup$ Jul 12, 2019 at 6:32
  • $\begingroup$ Thanks got it. What is the preferred value for $\alpha$? $\endgroup$
    – Jeeth
    Jul 12, 2019 at 6:37
  • 1
    $\begingroup$ I believe you have to tune it to find a value that suits your application. $\endgroup$ Jul 12, 2019 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.