Current
SparseCL contradiction retrieval
Benchmark first
Corpora: BEIR (SciFact, ArguAna, HotpotQA) · LoTTE · KILT
Protocol: Build from corpus documents only; issue the published test queries; preserve ranked IDs and component scores. Report nDCG@10, Recall@100, MRR, p50/p95 query latency, index bytes, and results with ACL pre-filtering. Ablate candidate generation, reranking, fusion, graph expansion, and packing independently.
Contradiction retrieval asks which corpus passage explicitly disagrees with a query passage. Ordinary similarity alone tends to retrieve paraphrases. SparseCL combines topical cosine similarity with the sparsity of the difference between separately trained embeddings.
How it works
Encode twice. A standard encoder
Eproduces similarity vectors; a SparseCL-trained encoderE_sproduces vectors where contradictions differ in a small semantic subspace.Authorize first. Remove every passage outside
allowed_passage_idsbefore computing scores.Generate candidates. Rank allowed passages by
cos(E(q), E(p))and retain a large configurable candidate set—1,000 in the paper’s example.Measure sparse difference. Compute normalized Hoyer sparsity over
E_s(q) − E_s(p). One-coordinate differences approach 1; dense differences approach 0.Rerank. Sort by
cosine + alpha × Hoyer, with stable passage-ID ties, and retain every component in the result trace.
Query + corpusauthorized passages only
cosine
Top-K candidatessame-topic prefilter
Hoyer
Sparse rerankcos + α · sparsity
→
ContradictionHit[]components + stable rank
from mari_components.retrieval import (
SparseContradictionCandidate, rank_sparse_contradictions,
)
hits = rank_sparse_contradictions(
similarity_encoder(query), sparsecl_encoder(query),
(SparseContradictionCandidate(
passage_id=p.id,
similarity_embedding=similarity_encoder(p.text),
sparse_embedding=sparsecl_encoder(p.text),
) for p in corpus),
alpha=0.4, candidate_limit=1000, limit=10,
allowed_passage_ids=authorized_ids,
)
for hit in hits:
audit(hit.cosine_similarity, hit.difference_sparsity, hit.score)
Training-objective conformance
sparse_contrastive_losses evaluates the paper’s Hoyer contrastive loss: contradictions are positives, similar non-contradictory passages are hard negatives, and the rest of the batch supplies soft negatives. It is a NumPy conformance oracle, not an autodiff trainer; the application trains E_s in PyTorch, JAX, or another framework.
Paper
SparseCL: Sparse Contrastive Learning for Contradiction Retrieval
Mari implements Equations 1–3, cosine prefiltering, sparse reranking, authorization ordering, validation, and score traces. Its Hoyer edge fixtures match the MIT-licensed Overcomplete implementation. The official SparseCL repository has no declared license, so no source from it is incorporated. Mari does not ship the trained encoder.