Hi, in my understanding, x1 and x2 corresponds to distance between positive(same-class) pair and negative pair. Before you apply MarginRankingLoss(), you have to compute those distances from batch.
For example, we have X1c,X2c,X3,X4 (X1c,X2c belong to class c and others are not).

In the binary classification phase, we apply usual classification to X1~X4.
In the ranking phase, at first, distance Dp = d(f(X1c) - f(X2c)), Dn = (f(X1c) - f(X4)) are computed, where f() returns model output, d() returns distance between two feature vectors.
Then loss computation would be as follows:
loss = max(0, Dp - Dn + m)


In your case, if you fix x1 as Dp and x2 as Dn, y should be always 1