all-MiniLM-L6-v2 fine-tuned to decide whether two e-commerce product titles
describe the same product: the entity-resolution problem behind price
comparison and catalog deduplication.
Abt: nikon black 13.5 megapixel coolpix digital camera coolpixp6000bk
Buy: nikon coolpix p6000 13 megapixels digital camera w / 4x wide angle
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("rabiaozers/minilm-abtbuy")
a = "nikon black 13.5 megapixel coolpix digital camera coolpixp6000bk"
b = "nikon coolpix p6000 13 megapixels digital camera w / 4x wide angle"
ea, eb = model.encode([a, b])
score = util.cos_sim(ea, eb).item()
print(score, score > 0.41) # 0.41 = threshold chosen on the Abt-Buy validation set
The threshold is not a property of the model. 0.41 maximised F1 on this
dataset's validation split; choose your own on your own data.
CosineSimilarityLoss. Written as a plain PyTorch training loop.Thresholds are chosen on the validation set; the test set is used once.
| Method | Threshold | Precision | Recall | F1 |
|---|---|---|---|---|
| TF-IDF, character 3-grams (baseline) | 0.60 | 0.658 | 0.636 | 0.647 |
| Pretrained all-MiniLM-L6-v2 | 0.85 | 0.500 | 0.442 | 0.469 |
| This model | 0.41 | 0.632 | 0.791 | 0.703 |
| Hybrid: 0.6 · TF-IDF + 0.4 · this model | 0.53 | 0.752 | 0.738 | 0.745 |
Catalog search with FAISS, recall@k over the 206 true matches in the test set:
| Vectors | recall@1 | recall@5 | recall@10 |
|---|---|---|---|
| This model | 0.641 | 0.772 | 0.825 |
| Hybrid (TF-IDF + this model) | 0.883 | 0.990 | 0.995 |
For reference, Ditto, a strong published model, reports F1 = 0.89 on this dataset.
Only about 11% of pairs match, so a model that always answers "different" reaches 89% accuracy and finds nothing. Precision, recall and F1 are reported instead.
About 90% of test products also appear in training pairs. On the 128 test pairs with at least one product never seen in training, this model still beat TF-IDF (F1 0.868 vs 0.739). That group is small and has a much higher match rate, so compare models within it rather than across groups.
nnsd797s vs
nnsd767s) are still often matched.delonghi dc50b
for a Sony home theater davis50b), because its training negatives were all
similar products. Combining it with TF-IDF, as in the hybrid above, fixes
most of this.sentence-transformers/all-MiniLM-L6-v2