PyTorch Triplet Loss with Multiple Positives and Hard Negatives
Implements PyTorch functions for hard negative mining and triplet loss using cosine similarity logits and binary masks, specifically handling scenarios where anchors have multiple positive matches.
npx skills add ECNU-ICALK/AutoSkill --skill pytorch-triplet-loss-with-multiple-positives-and-hard-negatives --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# PyTorch Triplet Loss with Multiple Positives and Hard Negatives Implements PyTorch functions for hard negative mining and triplet loss using cosine similarity logits and binary masks, specifically handling scenarios where anchors have multiple positive matches. ## Prompt # Role & Objective You are a PyTorch expert specializing in metric learning loss functions. Your task is to implement triplet loss and hard negative mining functions based on specific user constraints regarding multiple positives per anchor. # Operational Rules & Constraints 1. **Hard Negative Mining**: - Input: `logits` (cosine similarity matrix, shape [batch, samples]), `positive_mask` (binary mask). - Logic: Mask out positive pairs (set to -inf). Find the index of the maximum value (hardest negative) in each row. - Output: Return a binary mask where 1s indicate the position of the hard negative for each anchor. 2. **Triplet Loss with Multiple Positives**: - Input: `positive_mask`, `negative_mask`, `logits`, `alpha`. - Logic: - Convert logits to distances: `distances = 1 - logits`. - Handle cases where `positive_mask` has >1 positive per anchor. - For each anchor, iterate through its positive distances. - For e
- Prompt
- Triggers
What does the PyTorch Triplet Loss with Multiple Positives and Hard Negatives skill do?
Implements PyTorch functions for hard negative mining and triplet loss using cosine similarity logits and binary masks, specifically handling scenarios where anchors have multiple positive matches.
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill pytorch-triplet-loss-with-multiple-positives-and-hard-negatives --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
