Bridging Language and Items for Retrieval and Recommendation
Paper • 2403.03952 • Published
How to use benzbe/blair-fashion-base with Transformers:
# Load model directly
from transformers import RobertaForCL
model = RobertaForCL.from_pretrained("benzbe/blair-fashion-base", device_map="auto")Domain-specific contrastive embedding model for Amazon Fashion product search, trained on 1.25M (review, product metadata) pairs from the Amazon Reviews 2023 Fashion dataset.
Based on BLaIR (Hou et al., 2024) — SimCSE-style contrastive learning with infoNCE loss and in-batch negatives, plus auxiliary MLM objective.
roberta-base (125M params)import torch
from transformers import RobertaTokenizer
from models import RobertaForCL
# Load
tokenizer = RobertaTokenizer.from_pretrained("benzbe/blair-fashion-base")
model = RobertaForCL.from_pretrained(
"benzbe/blair-fashion-base",
temp=0.05, pooler_type="cls", do_mlm=False
)
model.eval()
# Encode texts
texts = ["comfortable running shoes", "leather handbag", "summer floral dress"]
inputs = tokenizer(texts, padding=True, truncation=True, max_length=128, return_tensors="pt")
with torch.no_grad():
embeddings = model.sentence_embed(inputs["input_ids"], inputs["attention_mask"])
# Shape: (3, 768), L2-normalized
# Cosine similarity
sim = embeddings @ embeddings.T
print(sim)
On a 10-query ground-truth test against 100 random Fashion products:
| Parameter | Value |
|---|---|
| Epochs | 5+ (stopped at ~89K steps) |
| Batch size | 64 × 4 accumulation = 256 effective |
| Learning rate | 5e-5 (linear warmup 10%) |
| Max seq length | 128 |
| Best val loss | 0.8708 |
| GPU | RTX 4090 (24GB) |