quaterion
quaterion copied to clipboard
[WIP] Implement XBM
This is still WIP, so consider it as a draft for now.
Closes #163.
I'm adding commits after small refactoring and polishing comments. Will request a review afterwards.
Deploy Preview for capable-unicorn-d5e336 ready!
Name | Link |
---|---|
Latest commit | 66fceb87cc2fb383395136d14954c6b49578be90 |
Latest deploy log | https://app.netlify.com/sites/capable-unicorn-d5e336/deploys/62fe8ccd4c5ccd0008c5158f |
Deploy Preview | https://deploy-preview-171--capable-unicorn-d5e336.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
It's zero-size tensor (scalar), so regular equal and not-equal operators should work --we use torch.allclose
and the similar to compare vectors and embeddings to avoid ambiguous meaning of comparing them.
trying to compare xbm_loss and regular loss:
torch.random.manual_seed(42)
embeddings = torch.rand(64, 100)
groups = torch.randint(0, 10, (64,))
loss = TripletLoss(margin=1.0, mining="hard")
print(loss(embeddings, groups))
print(loss._compute_xbm_loss(embeddings, groups, embeddings, groups))
If I understand the approach right, loss and _compute_xbm_loss
should give same result in this case, but in fact I got
tensor(1.5443)
tensor(50.5432)
Order of magnitude different. I am not sure how the implementation was validated and if this is an expected result, but in this case xbm weight constant is especially tricky to select.