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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- recommendation
|
| 5 |
+
- retrieval
|
| 6 |
+
- two-tower
|
| 7 |
+
- prag
|
| 8 |
+
- pytorch
|
| 9 |
+
- modernbert
|
| 10 |
+
- amazon-reviews
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# PRAG Encoder Model
|
| 14 |
+
|
| 15 |
+
This is a PRAG (Prompting for RAG-styled recommendation) encoder model trained on Amazon review data. It uses a two-tower architecture with a shared ModernBERT backbone to embed both user queries and product items into a common vector space for efficient retrieval.
|
| 16 |
+
|
| 17 |
+
## Model Details
|
| 18 |
+
|
| 19 |
+
### Model Description
|
| 20 |
+
<!-- Provide a longer summary of what this model is. -->
|
| 21 |
+
The PRAG model is designed for product recommendation and retrieval tasks. It maps text inputs (queries or item descriptions) to high-dimensional embeddings. The model is optimized using contrastive learning, where the goal is to maximize the cosine similarity between a query and its corresponding relevant item while minimizing similarity with irrelevant items.
|
| 22 |
+
|
| 23 |
+
- **Developed by:** @[dodo](https://huggingface.co/do2do2), @[quocdat32461997](https://huggingface.co/tendatngo)
|
| 24 |
+
- **Model type:** LLM Encoder
|
| 25 |
+
- **Language(s) (NLP):** English
|
| 26 |
+
- **Finetuned from model:** LLM Encoder
|
| 27 |
+
|
| 28 |
+
### Model Sources [optional]
|
| 29 |
+
<!-- Provide the basic links for the model. -->
|
| 30 |
+
- **Repository:** https://github.com/do2do2-ai
|
| 31 |
+
- **Paper [optional]:** [More Information Needed]
|
| 32 |
+
- **Demo [optional]:** [More Information Needed]
|
| 33 |
+
## Uses
|
| 34 |
+
|
| 35 |
+
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 36 |
+
|
| 37 |
+
### Direct Use
|
| 38 |
+
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 39 |
+
|
| 40 |
+
### Downstream Use [optional]
|
| 41 |
+
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 42 |
+
This model can be used directly for:
|
| 43 |
+
- Semantic search in e-commerce catalogs.
|
| 44 |
+
- Building recommendation systems by matching user intent (queries) to product descriptions.
|
| 45 |
+
- Zero-shot product retrieval tasks.
|
| 46 |
+
|
| 47 |
+
### Out-of-Scope Use
|
| 48 |
+
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 49 |
+
- Non-English text (not explicitly trained/validated).
|
| 50 |
+
- General-purpose text embedding outside the e-commerce/recommendation domain.
|
| 51 |
+
- Tasks requiring generative capabilities (this is an encoder-only model).
|
| 52 |
+
|
| 53 |
+
## Bias, Risks, and Limitations
|
| 54 |
+
|
| 55 |
+
- **Domain Specificity:** Optimized for product data with similar features and characteristics, but performance may vary on different domains or datasets.
|
| 56 |
+
- **Language:** Limited to English.
|
| 57 |
+
- **Biases:** May inherit biases present in the Amazon Reviews 2023 dataset.
|
| 58 |
+
|
| 59 |
+
### Recommendations
|
| 60 |
+
|
| 61 |
+
Users should evaluate the model on their specific product domain before deployment. Consider fine-tuning if the target domain's vocabulary differs significantly from Amazon's.
|
| 62 |
+
|
| 63 |
+
## How to Get Started with the Model
|
| 64 |
+
|
| 65 |
+
You can use the model via the recommendation API. Below is an example of how to make an authenticated request to get product recommendations.
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
import os
|
| 69 |
+
import requests
|
| 70 |
+
import json
|
| 71 |
+
|
| 72 |
+
# Configuration
|
| 73 |
+
api_key = "YOUR_API_KEY"
|
| 74 |
+
recommend_url = "https://trydodo.xyz"
|
| 75 |
+
|
| 76 |
+
headers = {
|
| 77 |
+
"Content-Type": "application/json",
|
| 78 |
+
"Authorization": f"Bearer {api_key}",
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
# Define context, template, and product catalog
|
| 82 |
+
payload = {
|
| 83 |
+
"context": {
|
| 84 |
+
"previous_purchases": ["electronics", "books"],
|
| 85 |
+
"budget": 100.0,
|
| 86 |
+
},
|
| 87 |
+
"template": "Recommend next product to customer. Previous purchases: {previous_purchases}, Budget less than: {budget}",
|
| 88 |
+
"catalog": {
|
| 89 |
+
"product_1": "Wireless headphones - Premium noise-cancelling",
|
| 90 |
+
"product_2": "Laptop stand - Adjustable aluminum ergonomic",
|
| 91 |
+
"product_3": "Python book - Complete guide for beginners",
|
| 92 |
+
"product_4": "Smartphone case - Shockproof cover with kickstand",
|
| 93 |
+
"product_5": "USB-C hub - 7-in-1 adapter with 4K HDMI",
|
| 94 |
+
},
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
try:
|
| 98 |
+
response = requests.post(
|
| 99 |
+
url=f"{recommend_url}/api/recommend/recommend",
|
| 100 |
+
params={
|
| 101 |
+
"model_key": "prag_v1",
|
| 102 |
+
"num_results": 5,
|
| 103 |
+
},
|
| 104 |
+
headers=headers,
|
| 105 |
+
json=payload,
|
| 106 |
+
)
|
| 107 |
+
response.raise_for_status()
|
| 108 |
+
|
| 109 |
+
recommendations = response.json()
|
| 110 |
+
print(f"Recommendations: {json.dumps(recommendations, indent=2)}")
|
| 111 |
+
|
| 112 |
+
except Exception as e:
|
| 113 |
+
print(f"Request failed: {e}")
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
## Training Details
|
| 117 |
+
|
| 118 |
+
The model was trained following standard large language model (LLM) training practices for encoder-based retrieval systems.
|
| 119 |
+
|
| 120 |
+
### Training Data
|
| 121 |
+
|
| 122 |
+
The model is trained on diverse product-related datasets, including product reviews, metadata, and user interaction logs. The data is preprocessed to emphasize semantic relationships between queries and items.
|
| 123 |
+
|
| 124 |
+
### Training Procedure
|
| 125 |
+
|
| 126 |
+
#### Preprocessing
|
| 127 |
+
|
| 128 |
+
- Standard tokenization using a ModernBERT-based tokenizer.
|
| 129 |
+
- Input sequences are formatted to represent user intent (queries) and product characteristics (items).
|
| 130 |
+
- Dynamic padding and truncation are applied to optimize training efficiency.
|
| 131 |
+
|
| 132 |
+
#### Training Hyperparameters
|
| 133 |
+
|
| 134 |
+
The training follows casual LLM training practices:
|
| 135 |
+
- **Batch Size:** Scaled to maximize GPU utilization.
|
| 136 |
+
- **Loss Function:** Contrastive learning objective.
|
| 137 |
+
- **Temperature:** Tuned to balance retrieval precision and recall.
|
| 138 |
+
|
| 139 |
+
## Evaluation
|
| 140 |
+
|
| 141 |
+
### Testing Data, Factors & Metrics
|
| 142 |
+
|
| 143 |
+
#### Metrics
|
| 144 |
+
|
| 145 |
+
The model is evaluated using standard retrieval metrics:
|
| 146 |
+
- Precision@K (K=2, 5, 10, 20)
|
| 147 |
+
- Recall@K (K=2, 5, 10, 20)
|
| 148 |
+
- Hit Ratio@K (K=2, 5, 10, 20)
|
| 149 |
+
- NDCG@K (K=2, 5, 10, 20)
|
| 150 |
+
|
| 151 |
+
## Technical Specifications
|
| 152 |
+
|
| 153 |
+
### Model Architecture and Objective
|
| 154 |
+
|
| 155 |
+
- **Backbone:** Standard transformer-based encoder for text representation.
|
| 156 |
+
- **Objective:** Contrastive learning objective
|
| 157 |
+
|
| 158 |
+
### Software
|
| 159 |
+
|
| 160 |
+
- **Framework:** PyTorch
|
| 161 |
+
- **Library:** Transformers
|
| 162 |
+
|
| 163 |
+
## Model Card Authors
|
| 164 |
+
|
| 165 |
+
quocdat32461997
|