wenmin-wu/ds-skills/batch-all-contrastive-loss
Claude Code and agent skill by wenmin-wu/ds-skills
Trust tier 2
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
All-vs-all contrastive loss comparing every pair in a batch (N^2 pairs) with margin and compactification regularizer
Install
npx vskill@latest install wenmin-wu/ds-skills/batch-all-contrastive-lossSKILL.md
Batch-All Contrastive Loss
Overview
Instead of sampling specific positive/negative pairs, compute distances for all N^2 pairs in a batch. Positive pairs (same class) minimize distance; negative pairs push apart beyond margin m. A compactification term prevents embedding space from expanding unboundedly. Averaging only over non-zero loss terms focuses learning on informative pairs.
Quick Start
Workflow
- Forward batch through embedding model
- Compute all N^2 pairwise squared distances
- Split into positive pairs (same label) and negative pairs (different label)
- Positive loss = squared distance; negative loss = relu(margin - distance)^2
- Average only non-zero terms + compactification regularizer
Key Decisions
- Margin: 10.0 is a common starting point; tune based on embedding dimensionality
- Non-zero averaging: ignores already-satisfied constraints, focusing gradients on hard cases
- Compactification:
wd * mean(dist^2)prevents embeddings from drifting to infinity - N^2 scaling: effective for batch sizes up to ~256; beyond that, sample pairs
References
- [Similarity DenseNet121 [0.805LB]](https://www.kaggle.com/code/iafoss/similarity-densenet121-0-805lb-kernel-time-limit)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cv/batch-all-contrastive-loss/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wenmin-wu/ds-skills/batch-all-contrastive-loss)