qdrant / quaterion

Blazing fast framework for fine-tuning similarity learning models
https://quaterion.qdrant.tech/
Apache License 2.0
640 stars 45 forks source link

Implementation of Centroid Triplet Loss Function #209

Closed Spinachboul closed 11 months ago

Spinachboul commented 11 months ago

Hello Developers,

I have added the code for Centroid Triplet Loss function as an added implementation in the "Loss" folder. I follows the basic code template, just contains a few changes in the forward function where the The Centroid Triplet Loss aims to learn embeddings (vectors) in such a way that distances between centroids belonging to the same group or cluster are minimized while distances between centroids of different groups are maximized.

netlify[bot] commented 11 months ago

Deploy Preview for capable-unicorn-d5e336 failed.

Name Link
Latest commit a8a91a469e04fe1c0a85f14044a789bc0a8cd349
Latest deploy log https://app.netlify.com/sites/capable-unicorn-d5e336/deploys/656c5ce9a20da6000884618b
netlify[bot] commented 11 months ago

Deploy Preview for capable-unicorn-d5e336 failed.

Name Link
Latest commit 900463359d7fa3cc9579c40bbdfc80520ffdcbca
Latest deploy log https://app.netlify.com/sites/capable-unicorn-d5e336/deploys/656c5cf3af47640008d48597
HanClinto commented 11 months ago

Looks like the build is failing due to formatting issues:

5:51:06 AM: /opt/buildhome/python3.8/lib/python3.8/site-packages/quaterion/loss/cos_face_loss.py:docstring of quaterion.loss.cos_face_loss.CosFaceLoss.forward:3: ERROR: Unexpected indentation.
5:51:06 AM: /opt/buildhome/python3.8/lib/python3.8/site-packages/quaterion/loss/cos_face_loss.py:docstring of quaterion.loss.cos_face_loss.CosFaceLoss.forward:4: WARNING: Block quote ends without a blank line; unexpected unindent.
5:51:06 AM: /opt/build/repo/docs/source/tutorials/triplet_loss_trick.rst:2: WARNING: Title underline too short.
5:51:06 AM: Triplet Loss: Vector Collapse Prevention
5:51:06 AM: ============================
Spinachboul commented 11 months ago

@HanClinto So should I again raise a PR for the function?

HanClinto commented 11 months ago

@HanClinto So should I again raise a PR for the function?

I can't speak for the maintainers of Quaternion, but Centroid Triplet Loss looks like a very useful function to have -- I would personally be interested in trying it out!

Spinachboul commented 11 months ago

For now I have deleted the branch. I also thought of implementing n-pair which is apparently better than contrastive and triplet loss.