question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusion about MultipleNegativesRankingLoss

See original GitHub issue

First of all, thank you for your work.

I have been using sentence-transformers in recent days, but I am a bit confused about the MultipleNegativesRankingLoss.

If i use like below:

from sentence_transformers import SentenceTransformer, SentencesDataset, LoggingHandler, losses from sentence_transformers.readers import InputExample

model = SentenceTransformer('distilbert-base-nli-mean-tokens') train_examples = [InputExample(texts=['Anchor 1', 'Positive 1']), InputExample(texts=['Anchor 2', 'Positive 2'])]

train_dataset = SentencesDataset(train_examples, model) train_dataloader = DataLoader(train_dataset, shuffle=True, batch_size=train_batch_size) train_loss = losses.MultipleNegativesRankingLoss(model=model)

model.fit(train_objectives=[(train_dataloader, train_loss)], epochs=1, warmup_steps=100)

Does it mean that train_examples are all positive examples? Will negative examples be constructed automatically by sentence_transformers?

Or, train_examples should also contain negative examples. Should I build them manually?

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
datistiquocommented, Feb 1, 2021

@nreimers Hey, I think it would be very helpful if you could provide at least a rough minimal example of using a dataset for MUltipleNegativeLoss structuring the batch right with having positive and negatives right, I think. this loss is not applicable very well besides for very very large amount of data like in msmarco example. But in most situations you have to take care that all other positives are not negatives.

It is still a bit confusing. And I think an example would be great.

0reactions
i-wanna-tocommented, Dec 23, 2020

Okay, I understand. Thanks for your help! @nreimers @datistiquo

Read more comments on GitHub >

github_iconTop Results From Across the Web

Confusion about MultipleNegativesRankingLoss #608 - GitHub
I have data (1000 example in total eg) where each positive anchor has up to 5 positive examples. So like in the format...
Read more >
How to use SentenceTransformers for contrastive learning?
Use the SentenceTransformer to encode images and text into a single vector space. I would combine both using SentenceTransformer to create a new...
Read more >
Understanding Ranking Loss, Contrastive Loss, Margin Loss ...
Understanding Ranking Loss, Contrastive Loss, Margin Loss, Triplet Loss, Hinge Loss and all those confusing names. Apr 3, 2019.
Read more >
Losses — Sentence-Transformers documentation
MultipleNegativesRankingLoss is a great loss function if you only have positive pairs, for example, only pairs of similar texts like pairs of paraphrases, ......
Read more >
How to implement MultipleNegativesRankingLoss in TF?
Confused about simple PyTorch backward() code. How does A.grad know about the x derivative? r/learnmachinelearning - Confused about ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found