Skip to content

[feat] Add triplets/n-tuple support to AnglE#3609

Merged
tomaarsen merged 4 commits into
huggingface:mainfrom
tomaarsen:exp/angle_negatives
Jan 28, 2026
Merged

[feat] Add triplets/n-tuple support to AnglE#3609
tomaarsen merged 4 commits into
huggingface:mainfrom
tomaarsen:exp/angle_negatives

Conversation

@tomaarsen

@tomaarsen tomaarsen commented Jan 8, 2026

Copy link
Copy Markdown
Member

Hello!

Pull Request overview

  • Experiment to add triplets/n-tuple support to AnglE
  • A training script based on all-nli

Details

This is a draft to add triplets/n-tuple support to AnglELoss, at which point the inputs are converted to pairs again, with labels set to 1 for positive pairs and 0 for negative pairs. I copied a simple training script and updated it to use AnglE, resulting in this model:

Which can be fairly compared to e.g. these:


  • Tom Aarsen

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds experimental triplet and n-tuple support to AnglELoss. Previously, AnglELoss only supported pairs of texts with float similarity scores. Now it can also process triplets (anchor, positive, negative) and n-tuples (anchor, positive, negative_1, ..., negative_n) by internally converting them to pairwise comparisons.

Changes:

  • Extended AnglELoss to handle triplet and n-tuple inputs by converting them to pairs internally
  • Added a training example script demonstrating the new functionality with the AllNLI dataset
  • Updated documentation to reflect the new input formats supported

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sentence_transformers/losses/AnglELoss.py Adds compute_loss_from_embeddings method to handle triplet/n-tuple inputs by converting them to pairwise comparisons with appropriate labels
examples/sentence_transformer/training/nli/training_nli_angle.py New training script demonstrating AnglELoss with triplet data from AllNLI dataset
examples/sentence_transformer/training/nli/README.md Documents the new training_nli_angle.py example
docs/sentence_transformer/loss_overview.md Updates loss function table to include AnglELoss for triplet and n-tuple inputs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sentence_transformers/losses/AnglELoss.py
@tomaarsen tomaarsen marked this pull request as ready for review January 28, 2026 12:17
@tomaarsen tomaarsen enabled auto-merge (squash) January 28, 2026 12:17
@tomaarsen tomaarsen disabled auto-merge January 28, 2026 13:07
@tomaarsen tomaarsen changed the title Experiment to add triplets/n-tuple support to AnglE [feat] Add triplets/n-tuple support to AnglE Jan 28, 2026
@tomaarsen tomaarsen merged commit c79db61 into huggingface:main Jan 28, 2026
11 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants