Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about emb loss #49

Open
256785 opened this issue Jul 24, 2024 · 3 comments
Open

question about emb loss #49

256785 opened this issue Jul 24, 2024 · 3 comments

Comments

@256785
Copy link

256785 commented Jul 24, 2024

def call(self, q_reps, p_reps):
if self.negatives_cross_device:
# This gathers both negatives and positives.
# It could likely be optimized by only gathering negatives.
q_reps = self._dist_gather_tensor(q_reps)
p_reps = self._dist_gather_tensor(p_reps)
scores = self.compute_similarity(q_reps, p_reps) / self.temperature
scores = scores.view(q_reps.size(0), -1)

    target = torch.arange(scores.size(0), device=scores.device, dtype=torch.long)
    target *= (p_reps.size(0) // q_reps.size(0))
    return self.cross_entropy(scores, target)

in the code,does it use ContrastiveLoss following the paper?

@Muennighoff
Copy link
Collaborator

yes thats contrastive loss

@256785
Copy link
Author

256785 commented Jul 25, 2024

target = torch.arange(scores.size(0), device=scores.device, dtype=torch.long)
target *= (p_reps.size(0) // q_reps.size(0))

why use target as this way,a little confuse

@256785
Copy link
Author

256785 commented Jul 25, 2024

I have some sense each query refers to some samples,use divided to count the num of samples,and use arrange with multiply to find the positive item index. Maybe is that?

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

No branches or pull requests

2 participants