I think this [1] N-pair implementation is easier to use.

embeddings_anchor => code_embedding,

embeddings_positive => docstring_embedding,

labels => [1,2,3,......N],

Where N is the batch_size.

I usually use N-pair loss in a different context where there is a set of pre-defined classes, each class has a fixed label. This is probably invalid for your problem setting.

Thus, I think setting labels = [1,2,3,......N] would work. It will signals that each code_embedding is different. I doubt the exact values matter. They just need to be different values.

[1] https://github.com/CongWeilin/cluster-loss-tensorflow/blob/ec20b1022a208a78d35291dda31e6f0522843ae6/metric_learning/metric_loss_ops.py#L245

I write reviews on computer vision papers. Writing tips are welcomed.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store