Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- pt
|
| 4 |
+
- multilingual
|
| 5 |
+
license: mit
|
| 6 |
+
tags:
|
| 7 |
+
- recommenders
|
| 8 |
+
- text-retrieval
|
| 9 |
+
- product-recommendation
|
| 10 |
+
- sentence-transformers
|
| 11 |
+
datasets:
|
| 12 |
+
- synthetic-ecommerce
|
| 13 |
+
metrics:
|
| 14 |
+
- auc
|
| 15 |
+
- ndcg
|
| 16 |
+
- mrr
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# foundational-model
|
| 20 |
+
|
| 21 |
+
A semantic product recommendation model that matches user profiles (free text) to products. Uses a frozen multilingual MiniLM encoder with trainable projection heads and chunk attention for user encoding.
|
| 22 |
+
|
| 23 |
+
## Model description
|
| 24 |
+
|
| 25 |
+
- **Architecture**: Dual-encoder (user encoder + item encoder)
|
| 26 |
+
- **Base model**: [paraphrase-multilingual-MiniLM-L12-v2](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2) (frozen)
|
| 27 |
+
- **Trainable params**: ~148k (projection head + chunk attention)
|
| 28 |
+
- **Input**: User profile text + product name + description
|
| 29 |
+
- **Output**: Cosine similarity scores for ranking
|
| 30 |
+
|
| 31 |
+
## Intended use
|
| 32 |
+
|
| 33 |
+
Product recommendation from user free-text profiles (e.g. "Marcos, gosto de videogames e de música, sou de Rio de janeiro"). Trained on synthetic e-commerce interactions in Portuguese.
|
| 34 |
+
|
| 35 |
+
## How to use
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from transformers import AutoTokenizer
|
| 39 |
+
import torch
|
| 40 |
+
from huggingface_hub import hf_hub_download
|
| 41 |
+
|
| 42 |
+
# Download checkpoint
|
| 43 |
+
checkpoint = hf_hub_download(repo_id="oristides/foundational-model", filename="pytorch_model.bin")
|
| 44 |
+
|
| 45 |
+
# Load model (requires model_arch1.RecSysModel - see repo for architecture)
|
| 46 |
+
from model.model_arch1 import RecSysModel
|
| 47 |
+
tokenizer = AutoTokenizer.from_pretrained("sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2")
|
| 48 |
+
model = RecSysModel()
|
| 49 |
+
model.load_state_dict(torch.load(checkpoint, map_location="cpu"))
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
# Encode user and items, then: scores = user_emb @ item_embs.T
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
Or use the `recommender` CLI in this repo: `uv run projects/reneguirecsys/model/recommender.py "your profile" -k 10`
|
| 56 |
+
|
| 57 |
+
## Training
|
| 58 |
+
|
| 59 |
+
- **Loss**: In-batch multi-negative cross-entropy
|
| 60 |
+
- **Split**: Leave-one-out per user
|
| 61 |
+
- **Eval metrics**: AUC, NDCG@10, MRR
|
| 62 |
+
- **Max sequence length**: 256 (user chunks), 128 (items)
|
| 63 |
+
|
| 64 |
+
## Citation
|
| 65 |
+
|
| 66 |
+
```bibtex
|
| 67 |
+
@misc{oristides-foundational-model-2025,
|
| 68 |
+
author = {oristides},
|
| 69 |
+
title = {Foundational Model for Product Recommendation},
|
| 70 |
+
year = {2025},
|
| 71 |
+
publisher = {Hugging Face},
|
| 72 |
+
url = {https://huggingface.co/oristides/foundational-model}
|
| 73 |
+
}
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## License
|
| 77 |
+
|
| 78 |
+
MIT
|