README: engine v2.0 is the model to use; older models moved to archive/
Browse filesThis view is limited to 50 files because it contains too many changes. Β See raw diff
- README.md +328 -344
- archive/README.md +11 -0
- {legacy_v1_1 β archive/engine_v1_1}/backend_modes_report.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/build_report.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/cold_stage2.onnx +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/meta.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed0.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed1.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed2.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed3.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed4.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed0.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed1.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed2.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed3.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed4.pth +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/sensitivity_report.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/validation_v1_1.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/verification_report.json +0 -0
- {legacy_v1_1 β archive/engine_v1_1}/warm_deepfm.onnx +0 -0
- {phase1_models β archive/phase1_models}/README.md +0 -0
- {phase1_models β archive/phase1_models}/docs/Model_Explainer.docx +0 -0
- {phase1_models β archive/phase1_models}/example_inference.py +0 -0
- {phase1_models β archive/phase1_models}/metadata/ctr_vocab.json +0 -0
- {phase1_models β archive/phase1_models}/metadata/export_report.json +0 -0
- {phase1_models β archive/phase1_models}/metadata/feature_stats.json +0 -0
- {phase1_models β archive/phase1_models}/metadata/pca.json +0 -0
- {phase1_models β archive/phase1_models}/metadata/sasrec_vocab.json +0 -0
- {phase1_models β archive/phase1_models}/onnx/DCNV2.onnx +0 -0
- {phase1_models β archive/phase1_models}/onnx/DeepFM.onnx +0 -0
- {phase1_models β archive/phase1_models}/onnx/LR.onnx +0 -0
- {phase1_models β archive/phase1_models}/onnx/SASRec.onnx +0 -0
- {phase1_models β archive/phase1_models}/onnx/WideDeep.onnx +0 -0
- {phase1_models β archive/phase1_models}/pytorch_checkpoints/DCNV2.pth +0 -0
- {phase1_models β archive/phase1_models}/pytorch_checkpoints/DeepFM.pth +0 -0
- {phase1_models β archive/phase1_models}/pytorch_checkpoints/LR.pth +0 -0
- {phase1_models β archive/phase1_models}/pytorch_checkpoints/SASRec.pth +0 -0
- {phase1_models β archive/phase1_models}/pytorch_checkpoints/WideDeep.pth +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/engine_features.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_real_backtest.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_simulation.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_tag_quality.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage1.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_DeepFM_meta.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_LR_meta.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_WideDeep_meta.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_summary.json +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/DeepFM.onnx +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/LR.onnx +0 -0
- {v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/WideDeep.onnx +0 -0
README.md
CHANGED
|
@@ -1,344 +1,328 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
library_name: onnx
|
| 4 |
-
language:
|
| 5 |
-
- en
|
| 6 |
-
pipeline_tag: tabular-classification
|
| 7 |
-
tags:
|
| 8 |
-
- recommender-system
|
| 9 |
-
- feed-ranking
|
| 10 |
-
- ctr-prediction
|
| 11 |
-
- cold-start
|
| 12 |
-
- deepfm
|
| 13 |
-
- wide-and-deep
|
| 14 |
-
- onnx
|
| 15 |
-
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
- **
|
| 24 |
-
- **
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
---
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
```
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
],
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
-
|
| 124 |
-
|
| 125 |
-
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
`
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
| 161 |
-
|---|---|---|
|
| 162 |
-
|
|
| 163 |
-
|
|
| 164 |
-
|
|
| 165 |
-
|
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
| 241 |
-
|
|
| 242 |
-
|
|
| 243 |
-
|
|
| 244 |
-
|
|
| 245 |
-
|
|
| 246 |
-
|
|
| 247 |
-
| **
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
|
| 254 |
-
|
|
| 255 |
-
|
|
| 256 |
-
|
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
--
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
**
|
| 308 |
-
|
| 309 |
-
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
---
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
- **Topic-first can hide drifting interests.** If a user's engagement moves to topics outside their picked tags, the 7-of-10 rule pushes those posts down. Keep an exploration share (15β20%) in your serving layer, and monitor off-topic engagement.
|
| 330 |
-
- **About 24% of posts got no tag** in the trace. Untagged posts get no closeness bonus but are still ranked by the models.
|
| 331 |
-
- **It ranks; it does not retrieve or moderate.** Candidate retrieval, safety filtering and policy enforcement must happen before the engine.
|
| 332 |
-
|
| 333 |
-
---
|
| 334 |
-
|
| 335 |
-
## Citation
|
| 336 |
-
```bibtex
|
| 337 |
-
@misc{unihive_recsys_2026,
|
| 338 |
-
title = {UniHive RecSys: a hybrid cold-to-warm feed-ranking engine},
|
| 339 |
-
author = {Singh, Tirthanker},
|
| 340 |
-
year = {2026},
|
| 341 |
-
url = {https://huggingface.co/Tirthanker/UniHive_RecSys}
|
| 342 |
-
}
|
| 343 |
-
```
|
| 344 |
-
Underlying methods: Cheng et al. 2016 (Wide & Deep); Guo et al. 2017 (DeepFM); Wang et al. 2021 (DCN V2); Kang & McAuley 2018 (SASRec); Yi et al. 2019 (two-tower sampling-bias correction); Platt 1999 (calibration); Carbonell & Goldstein 1998 (MMR); Zhao et al. 2021 (RecBole).
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: onnx
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
pipeline_tag: tabular-classification
|
| 7 |
+
tags:
|
| 8 |
+
- recommender-system
|
| 9 |
+
- feed-ranking
|
| 10 |
+
- ctr-prediction
|
| 11 |
+
- cold-start
|
| 12 |
+
- deepfm
|
| 13 |
+
- wide-and-deep
|
| 14 |
+
- onnx
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# UniHive RecSys: hybrid feed-ranking engine (v2.0)
|
| 18 |
+
|
| 19 |
+
A small, fast **post recommendation engine** for a student social app. Give it a user (interests + past interactions) and a list of candidate posts; it returns the posts in feed order, with a score and an explanation for each.
|
| 20 |
+
|
| 21 |
+
> ### β
This repository is engine v2.0: our final, intended design. Use `hybrid_engine/`.
|
| 22 |
+
> - **Run it:** `hybrid_engine/` (code) + `hybrid_engine/artifacts/` (the weights it loads). Nothing else is needed.
|
| 23 |
+
> - **Train it further:** `pytorch_checkpoints/engine_v2.0/` (the same v2.0 models as PyTorch files).
|
| 24 |
+
> - **Ignore `archive/`** unless you are studying the project's history. Those are superseded experiments, built on different inputs, and they will not work with `hybrid_engine/`.
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Contents
|
| 29 |
+
1. [Which files you need](#1-which-files-you-need)
|
| 30 |
+
2. [Install and run in 2 minutes](#2-install-and-run-in-2-minutes)
|
| 31 |
+
3. [Use it in your code](#3-use-it-in-your-code)
|
| 32 |
+
4. [Content vectors (recommended)](#4-content-vectors-recommended)
|
| 33 |
+
5. [Inputs and outputs](#5-inputs-and-outputs)
|
| 34 |
+
6. [Settings](#6-settings)
|
| 35 |
+
7. [Plug it into a backend](#7-plug-it-into-a-backend)
|
| 36 |
+
8. [Continue training](#8-continue-training)
|
| 37 |
+
9. [How it works](#9-how-it-works)
|
| 38 |
+
10. [Scores](#10-scores)
|
| 39 |
+
11. [Model size](#11-model-size)
|
| 40 |
+
12. [Where the engine's parts come from](#12-where-the-engines-parts-come-from)
|
| 41 |
+
13. [Training data and limitations](#13-training-data-and-limitations)
|
| 42 |
+
14. [Archive (older versions)](#14-archive-older-versions)
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## 1. Which files you need
|
| 47 |
+
|
| 48 |
+
| You want to... | Files |
|
| 49 |
+
|---|---|
|
| 50 |
+
| **Rank posts** (most users) | `hybrid_engine/` (code + `artifacts/cold_stage2.onnx`, `artifacts/warm_deepfm.onnx`, `artifacts/meta.json`) |
|
| 51 |
+
| Turn post text into content vectors | the public encoder [`Qwen/Qwen3-Embedding-0.6B`](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B) (section 4) |
|
| 52 |
+
| Continue training the models | `pytorch_checkpoints/engine_v2.0/` (section 8) |
|
| 53 |
+
| Read the full project report | `REPORT.md` |
|
| 54 |
+
|
| 55 |
+
The engine reads exactly the files in `hybrid_engine/artifacts/`. Don't replace them with files from `archive/`: the feature lists, vocabularies and standardisation differ.
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## 2. Install and run in 2 minutes
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
pip install huggingface_hub numpy onnxruntime
|
| 63 |
+
hf download Tirthanker/UniHive_RecSys --include "hybrid_engine/*" --local-dir UniHive_RecSys
|
| 64 |
+
cd UniHive_RecSys
|
| 65 |
+
python -m hybrid_engine.example # demo: a brand-new user vs the same user after 30 engaged posts
|
| 66 |
+
python -m hybrid_engine.tests.test_engine # smoke tests; should end with "community / flair guard passed"
|
| 67 |
+
```
|
| 68 |
+
Python 3.10+. Runs on CPU; no GPU needed.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## 3. Use it in your code
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
import time
|
| 76 |
+
from hybrid_engine import HybridRecommender
|
| 77 |
+
|
| 78 |
+
engine = HybridRecommender() # load once at startup; reuse for every request
|
| 79 |
+
|
| 80 |
+
user = {
|
| 81 |
+
"interests": ["machine-learning", "computer-vision"], # tag slugs the user picked (list: meta.json -> taxonomy.child)
|
| 82 |
+
"history": [ # what the user saw before; may be empty for a new user
|
| 83 |
+
{"post_id": "p1", "ts_ms": 1791141039157, "visible_ms": 5200, "focal_ms": 4800, "hover_ms": 300,
|
| 84 |
+
"clicked": True, "engaged": True, "community": "c-ml", "author": "a-17", "embedding": None},
|
| 85 |
+
],
|
| 86 |
+
}
|
| 87 |
+
candidates = [
|
| 88 |
+
{"post_id": "p9", "post_type": "text", "score": 42, "comments": 7, "age_hours": 3.5,
|
| 89 |
+
"title": "Fine-tuning ViTs on a laptop GPU", "body": "Notes from a weekend project ...",
|
| 90 |
+
"tags": {"computer-vision": 0.9, "deep-learning": 0.7}, "embedding": None,
|
| 91 |
+
"author": "a-3", "impressions": 0, "community": "c-cv"},
|
| 92 |
+
{"post_id": "p10", "post_type": "image", "score": 300, "comments": 40, "age_hours": 50,
|
| 93 |
+
"title": "Campus fest photos", "body": "", "tags": {"photography": 0.8}, "embedding": None,
|
| 94 |
+
"author": "a-8", "impressions": 120, "community": "c-fest"},
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
feed = engine.recommend(user, candidates, now_ms=time.time() * 1000, k=10)
|
| 98 |
+
for d in feed:
|
| 99 |
+
print(d["position"], d["post_id"], round(d["score"], 3), "topic" if d["topic_match"] else "", "warm weight", d["warm_weight"])
|
| 100 |
+
```
|
| 101 |
+
- `recommend(user, candidates, now_ms, k)`: the top k in final feed order.
|
| 102 |
+
- `rank(...)`: every candidate in feed order.
|
| 103 |
+
- `score(...)`: raw scores without the topic-first reordering.
|
| 104 |
+
|
| 105 |
+
`now_ms` is the request time in milliseconds. History items at or after it are ignored automatically.
|
| 106 |
+
|
| 107 |
+
---
|
| 108 |
+
|
| 109 |
+
## 4. Content vectors (recommended)
|
| 110 |
+
|
| 111 |
+
The models read a 1024-d content vector per post. Build it **exactly** like this (the same recipe the models were trained on):
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
from sentence_transformers import SentenceTransformer # pip install sentence-transformers
|
| 115 |
+
from hybrid_engine.backend_adapter import qwen3_text
|
| 116 |
+
|
| 117 |
+
encoder = SentenceTransformer("Qwen/Qwen3-Embedding-0.6B"); encoder.max_seq_length = 512 # load once
|
| 118 |
+
text = qwen3_text(title, body, image_caption) # "title. body" (+ " Image: caption"); no community, no flair
|
| 119 |
+
post["embedding"] = encoder.encode(text, normalize_embeddings=True)
|
| 120 |
+
```
|
| 121 |
+
- Compute it once per post when the post is created, and store it.
|
| 122 |
+
- Without vectors (`"embedding": None`) the engine still ranks, but loses the content signal: about 0.02 lower NDCG@10 on average (section 10).
|
| 123 |
+
- A vector of the wrong size (e.g. a 512-d CLIP vector) is ignored on purpose: it lives in a different space.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
## 5. Inputs and outputs
|
| 128 |
+
|
| 129 |
+
**Candidate post**
|
| 130 |
+
|
| 131 |
+
| Field | Type | Meaning |
|
| 132 |
+
|---|---|---|
|
| 133 |
+
| `post_id` | str | your id |
|
| 134 |
+
| `post_type` | str | `text`, `image`, `video`, `link`, `gallery`, ... |
|
| 135 |
+
| `score`, `comments` | int | likes / upvotes and comment count |
|
| 136 |
+
| `age_hours` | float | hours since the post was created |
|
| 137 |
+
| `title`, `body`, `image_caption` | str | used for length features (and for the content vector, section 4) |
|
| 138 |
+
| `tags` | dict or list | `{slug: confidence}` from the 114-tag taxonomy, or a list of slugs (confidence 1.0) |
|
| 139 |
+
| `embedding` | 1024 floats or None | section 4 |
|
| 140 |
+
| `author`, `community` | str | used only for the user's *own* history with that author / community, never as model inputs |
|
| 141 |
+
| `impressions` | int | how often your platform has shown the post (drives the new-post push) |
|
| 142 |
+
| optional | | `domain`, `language`, `is_ad`, `is_spoiler`, `upvote_ratio`, `awards`, `is_member` |
|
| 143 |
+
|
| 144 |
+
**History item:** `post_id`, `ts_ms` (when shown), `visible_ms`, `focal_ms` (attention), `hover_ms`, `clicked`, `engaged`, `community`, `author`, `embedding`. Set `engaged` to True for dwell β₯ 3 s or a click / like / save / join / reply. If you log only one dwell value, use it for both `visible_ms` and `focal_ms`, and set `hover_ms` to 0.
|
| 145 |
+
|
| 146 |
+
**Output per candidate**
|
| 147 |
+
- `score`, `position`, `topic_match`;
|
| 148 |
+
- `v2b`, `cold_probability`, `tag_closeness`;
|
| 149 |
+
- `warm_probability`, `warm_weight`, `engaged_history`;
|
| 150 |
+
- `freshness_multiplier`, `push`, `has_content_embedding`.
|
| 151 |
+
|
| 152 |
+
Log them to explain any feed.
|
| 153 |
+
|
| 154 |
+
---
|
| 155 |
+
|
| 156 |
+
## 6. Settings
|
| 157 |
+
|
| 158 |
+
`HybridRecommender(**overrides)`; the defaults are stored in `hybrid_engine/artifacts/meta.json`.
|
| 159 |
+
|
| 160 |
+
| Setting | Default | Effect |
|
| 161 |
+
|---|---|---|
|
| 162 |
+
| `n0_engaged_posts` | 10 | engaged posts at which the warm model reaches half of its maximum share |
|
| 163 |
+
| `w_max` | 0.7 | maximum warm-model share (the rest stays with the new-user model) |
|
| 164 |
+
| `tag_bonus` | 0.1 | weight of interest-tag closeness in the new-user score |
|
| 165 |
+
| `decay_half_life_hours`, `decay_floor` | 720, 0.85 | freshness: a week-old post keeps 98%, a month-old 93%, never below 85% |
|
| 166 |
+
| `push_beta`, `push_max_age_hours` | 0.1, 24 | lift for posts under 24 h old, fading with impressions |
|
| 167 |
+
| `topic_first_slots`, `topic_block` | 7, 10 | 7 of every 10 positions go to posts matching the user's interests (0 = off) |
|
| 168 |
+
|
| 169 |
+
Example: `HybridRecommender(w_max=0.5, topic_first_slots=5)`.
|
| 170 |
+
|
| 171 |
+
---
|
| 172 |
+
|
| 173 |
+
## 7. Plug it into a backend
|
| 174 |
+
|
| 175 |
+
`hybrid_engine/backend_adapter.py` maps the data of a FastAPI + Redis + Postgres feed service onto the engine:
|
| 176 |
+
- **Posts:** `post_from_meta`, `post_from_row` (backend posts β candidates).
|
| 177 |
+
- **History:** `history_from_events` (raw VIEW / LONG_VIEW / CLICK / LIKE / SAVE / SKIP / HIDE events β history, merging visits and correcting timestamps).
|
| 178 |
+
- **Interests:** `expand_interests` (broad interests β tags).
|
| 179 |
+
- **Ranking:** `build_pool_hybrid`, a drop-in replacement for a `build_pool(r, uid, state, level)` scoring step.
|
| 180 |
+
- **Vectors in Redis:** `encode_q3`, `fetch_q3`.
|
| 181 |
+
|
| 182 |
+
Step-by-step guide: [`hybrid_engine/INTEGRATION.md`](hybrid_engine/INTEGRATION.md). Speed: about 0.7 ms per candidate on one CPU thread, so a 200-post pool takes about 140 ms.
|
| 183 |
+
|
| 184 |
+
---
|
| 185 |
+
|
| 186 |
+
## 8. Continue training
|
| 187 |
+
|
| 188 |
+
`pytorch_checkpoints/engine_v2.0/` holds the RecBole 1.2.0 originals of both models, 5 seeds each (`cold_widedeep_seed0-4.pth`, `warm_deepfm_seed0-4.pth`). The shipped ONNX files average these 5 seeds.
|
| 189 |
+
|
| 190 |
+
```bash
|
| 191 |
+
pip install torch recbole==1.2.0 # the checkpoints store a RecBole config, so RecBole must be importable to load them
|
| 192 |
+
```
|
| 193 |
+
```python
|
| 194 |
+
import torch
|
| 195 |
+
ckpt = torch.load("pytorch_checkpoints/engine_v2.0/warm_deepfm_seed0.pth", map_location="cpu", weights_only=False)
|
| 196 |
+
print(ckpt["config"]["model"], ckpt["config"]["dataset"]) # DeepFM reco_ctr_nc_noid_strict
|
| 197 |
+
state = ckpt["state_dict"] # weights
|
| 198 |
+
```
|
| 199 |
+
Rebuilding and retraining needs the RecBole datasets and scripts of the training kit: GitHub repository, branch `recommender`, folder `models/training/`. Use `engine_v2/build_engine_v2.py`, then `engine_v2/verify_hybrid_engine.py`. After retraining, re-export **both** ONNX files and `meta.json` together.
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## 9. How it works
|
| 204 |
+
|
| 205 |
+
```
|
| 206 |
+
candidate posts ββ¬ββΊ tag closeness (8 tag-match features β logistic score)
|
| 207 |
+
βββΊ COLD model, Wide&Deep: post stats + content + tag match β calibrated P(engage)
|
| 208 |
+
βββΊ WARM model, DeepFM: post inputs + 27 user-history features β P(engage)
|
| 209 |
+
|
| 210 |
+
v2b = P_cold + 0.1 Β· rank(tag closeness) (the new-user score)
|
| 211 |
+
w = 0 for a user with no engaged posts, else min(0.7, engaged / (engaged + 10))
|
| 212 |
+
blend = (1 β w) Β· rank(v2b) + w Β· rank(P_warm)
|
| 213 |
+
score = blend Β· (0.85 + 0.15 Β· 0.5^(age_h / 720)) + 0.1 Β· [age_h β€ 24] / sqrt(1 + impressions)
|
| 214 |
+
order = in each block of 10 positions: 7 best interest matches, then 3 best of any kind
|
| 215 |
+
```
|
| 216 |
+
- **New users:** w = 0, so pure v2b.
|
| 217 |
+
- **The warm model takes over gradually:** w = 0.09 after 1 engaged post, 0.33 after 5, 0.50 after 10, and 0.70 at most. The new-user model always keeps at least 30%.
|
| 218 |
+
- **Excluded from the models:** user and post IDs, feed position, scroll speed, community name and flair.
|
| 219 |
+
|
| 220 |
+
---
|
| 221 |
+
|
| 222 |
+
## 10. Scores
|
| 223 |
+
|
| 224 |
+
All numbers are for v2.0, on data the models never trained on.
|
| 225 |
+
- **AUC:** chance an engaged post is scored above a non-engaged one (0.5 = random).
|
| 226 |
+
- **NDCG@10:** quality of the top 10 (1.0 = all engaged posts first).
|
| 227 |
+
|
| 228 |
+
**Models** (test split: last 15% of each user's timeline, 270 exposures, 44 engaged)
|
| 229 |
+
|
| 230 |
+
| Model | Validation AUC | Test AUC |
|
| 231 |
+
|---|---|---|
|
| 232 |
+
| Cold model (Wide&Deep, 5-seed ensemble) | 0.777 | **0.602** |
|
| 233 |
+
| Warm model (DeepFM, 5-seed ensemble) | 0.713 | **0.565** |
|
| 234 |
+
|
| 235 |
+
**Ranking quality** (NDCG@10; each feed ranked as one live request)
|
| 236 |
+
|
| 237 |
+
| Feed | v2.0 | v2.0 with typical backend data | same, no content vectors | Random |
|
| 238 |
+
|---|---|---|---|---|
|
| 239 |
+
| Validation period, whole feeds | **0.650** | 0.579 | 0.604 | 0.350 |
|
| 240 |
+
| Validation period, 25-post pages | 0.559 | 0.595 | 0.582 | 0.350 |
|
| 241 |
+
| Test period, whole feeds | **0.340** | 0.329 | 0.268 | 0.201 |
|
| 242 |
+
| Test period, 25-post pages | 0.415 | 0.397 | 0.441 | 0.286 |
|
| 243 |
+
| Later real session 1, one feed | 0.255 | 0.159 | 0.155 | 0.119 |
|
| 244 |
+
| Later real session 1, 25-post pages | 0.468 | 0.486 | 0.362 | 0.282 |
|
| 245 |
+
| Later real session 2, one feed | 0.110 | 0.110 | 0.110 | 0.079 |
|
| 246 |
+
| Later real session 2, 25-post pages | 0.403 | 0.382 | 0.372 | 0.245 |
|
| 247 |
+
| **Mean** | **0.400** | **0.380** | **0.362** | **0.239** |
|
| 248 |
+
|
| 249 |
+
"Typical backend data" means no flair, tags without confidences, a single dwell value and no vote ratio.
|
| 250 |
+
|
| 251 |
+
**The two later real sessions** (recorded two days after all training data)
|
| 252 |
+
|
| 253 |
+
| | Session 1 (89 posts, 11 engaged) | Session 2 (142 posts, 10 engaged) |
|
| 254 |
+
|---|---|---|
|
| 255 |
+
| v2.0: NDCG@10 / engaged in top 10 / AUC | 0.255 / 3 / 0.688 | 0.110 / 1 / 0.498 |
|
| 256 |
+
| Reddit's own feed order | 0.641 / 6 / 0.917 | 0.312 / 3 / 0.773 |
|
| 257 |
+
| Random | 0.124 / 1.1 / 0.50 | 0.070 / 0.6 / 0.50 |
|
| 258 |
+
|
| 259 |
+
**Engineering checks**
|
| 260 |
+
- ONNX equals PyTorch within 2.4e-7.
|
| 261 |
+
- The engine rebuilds the training features from raw data within 0.0021, with 0 category mismatches.
|
| 262 |
+
- Engine scores match the offline predictions within 2.5e-4.
|
| 263 |
+
- 9 automated tests pass.
|
| 264 |
+
|
| 265 |
+
**Compared with the previous version:** v1.1 used the community name and scored higher on its Reddit training data (test AUC 0.692 / 0.671, mean NDCG@10 0.446). Community names don't carry over to a new platform. Under realistic conditions the gap is small: 0.380 for v2.0 vs 0.410 for v1.1, and 0.362 vs 0.369 without content vectors. Details are in `REPORT.md`, section 13.
|
| 266 |
+
|
| 267 |
+
---
|
| 268 |
+
|
| 269 |
+
## 11. Model size
|
| 270 |
+
|
| 271 |
+
| Model | Parameters | Shipped file |
|
| 272 |
+
|---|---|---|
|
| 273 |
+
| Cold model (Wide&Deep: 4-wide embeddings β MLP 64 β 32) | 13,048 per seed | `cold_stage2.onnx`, 5 seeds, 319 KB |
|
| 274 |
+
| Warm model (DeepFM: 16-wide embeddings β MLP 64 β 32) | 66,457 per seed | `warm_deepfm.onnx`, 5 seeds, 1.4 MB |
|
| 275 |
+
|
| 276 |
+
The models are small on purpose: they learn from about 1,800 interactions, and a larger network would only memorise them. The `.pth` files are bigger than the parameter count because they also store the training configuration and optimizer state. The only large model in the pipeline is the public **Qwen3-Embedding-0.6B** text encoder (about 1.2 GB). It is used as is and downloaded from its own repository, so it is not copied here.
|
| 277 |
+
|
| 278 |
+
---
|
| 279 |
+
|
| 280 |
+
## 12. Where the engine's parts come from
|
| 281 |
+
|
| 282 |
+
This is an independent implementation built from methods used in well-known production recommenders. It is not affiliated with any of these companies.
|
| 283 |
+
|
| 284 |
+
| Part | Method | Known use |
|
| 285 |
+
|---|---|---|
|
| 286 |
+
| Cold model | **Wide & Deep** (Cheng et al., 2016) | Google Play app recommendations (Google) |
|
| 287 |
+
| Warm model | **DeepFM** (Guo et al., 2017) | Huawei App Market CTR prediction (Huawei Noah's Ark Lab) |
|
| 288 |
+
| Cold β warm blend | new-user model handing over to a behavioural model as history grows | the standard cold-start pattern of e-commerce and streaming feeds |
|
| 289 |
+
| Calibration | **Platt scaling** | CTR models in online advertising |
|
| 290 |
+
| Freshness decay | exponential time decay | the family of Hacker News and Reddit "hot" ranking |
|
| 291 |
+
| New-post push | a boost for new items that fades with exposure | initial-audience boosts for new content in short-video feeds such as TikTok |
|
| 292 |
+
| Topic-first slots + exploration share | slot quotas, with 15β20% exploration kept in the serving layer | quota-based feed blending in large feeds (YouTube, Instagram) |
|
| 293 |
+
| Content vectors | **Qwen3-Embedding-0.6B** | Alibaba Qwen's open embedding model |
|
| 294 |
+
| Interest tags | LLM tagging into a closed taxonomy | cold-starting item catalogs with LLM labels |
|
| 295 |
+
| Evaluated during research, not in v2.0 | two-tower retrieval (YouTube), X's Thunder + Phoenix pipeline, MMR diversification, DCN V2 (Google), SASRec | see `REPORT.md` |
|
| 296 |
+
|
| 297 |
+
---
|
| 298 |
+
|
| 299 |
+
## 13. Training data and limitations
|
| 300 |
+
|
| 301 |
+
**Data**
|
| 302 |
+
- Browser telemetry of real Reddit scrolling: 4 consenting participants, 1,794 post exposures, 1,677 posts. Usernames were hashed. The data is not published.
|
| 303 |
+
- **Label:** engaged = click / vote / save / join / reply / opened post, or attention β₯ 3 s.
|
| 304 |
+
- **Split:** chronological per user (70 / 15 / 15).
|
| 305 |
+
- **No look-ahead:** history features only count interactions that ended before the ranked post was shown.
|
| 306 |
+
|
| 307 |
+
**Limitations**
|
| 308 |
+
- **Small data.** Differences below about 0.1 AUC are within noise. Treat the settings as a starting point and re-tune `w_max`, `n0_engaged_posts` and decay/push on your own logs.
|
| 309 |
+
- **Trained on Reddit.** Other platforms differ; retrain on your own data when you have it.
|
| 310 |
+
- **The topic-first rule can hide a user's new interests.** Keep a 15β20% exploration share in your serving layer.
|
| 311 |
+
- **It ranks; it doesn't retrieve or moderate.** Filter candidates for safety before ranking.
|
| 312 |
+
|
| 313 |
+
---
|
| 314 |
+
|
| 315 |
+
## 14. Archive (older versions)
|
| 316 |
+
|
| 317 |
+
Not for use. `archive/` holds superseded research models, kept only so the history in `REPORT.md` can be checked. Everything in this README, and everything `hybrid_engine/` loads, is v2.0. See [`archive/README.md`](archive/README.md).
|
| 318 |
+
|
| 319 |
+
---
|
| 320 |
+
|
| 321 |
+
```bibtex
|
| 322 |
+
@misc{unihive_recsys_2026,
|
| 323 |
+
title = {UniHive RecSys: a hybrid cold-to-warm feed-ranking engine},
|
| 324 |
+
author = {Singh, Tirthanker},
|
| 325 |
+
year = {2026},
|
| 326 |
+
url = {https://huggingface.co/Tirthanker/UniHive_RecSys}
|
| 327 |
+
}
|
| 328 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
archive/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Archive: earlier models (reference only)
|
| 2 |
+
|
| 3 |
+
**Do not use these files with `hybrid_engine/`.** The current model is v2.0 in `hybrid_engine/artifacts/` (see the main README). The models here were trained on different inputs (they use community name and flair, user/post IDs or feed position) and have their own vocabularies and standardisation. They are kept so the results in `REPORT.md` can be checked and compared.
|
| 4 |
+
|
| 5 |
+
| Folder | What it is | Status |
|
| 6 |
+
|---|---|---|
|
| 7 |
+
| `engine_v1_1/` | the previous hybrid engine (same design, but its models used community name + flair). ONNX, `meta.json`, reports, `pytorch_checkpoints/` (5 seeds per model) | replaced by v2.0 |
|
| 8 |
+
| `phase1_models/` | the first five models (LR, DeepFM, Wide&Deep, DCN V2, SASRec), trained with user/post IDs and feed position. ONNX, checkpoints, metadata, `Model_Explainer.docx`, `example_inference.py` | research baseline |
|
| 9 |
+
| `v1_two_stage_engine/` | Stage-2 models of the first two-stage engine (tag match, then model). ONNX, checkpoints, Stage-1 weights and results | research baseline, outperformed |
|
| 10 |
+
|
| 11 |
+
The engine v1.1 files can be loaded on their own with `HybridRecommender(artifacts_dir="archive/engine_v1_1")`, but that version needs content vectors built with its own text recipe ("title. community. flair. body"), not the v2.0 one.
|
{legacy_v1_1 β archive/engine_v1_1}/backend_modes_report.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/build_report.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/cold_stage2.onnx
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/meta.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed0.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed1.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed2.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed3.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/cold_widedeep_seed4.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed0.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed1.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed2.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed3.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/pytorch_checkpoints/warm_deepfm_seed4.pth
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/sensitivity_report.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/validation_v1_1.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/verification_report.json
RENAMED
|
File without changes
|
{legacy_v1_1 β archive/engine_v1_1}/warm_deepfm.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/README.md
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/docs/Model_Explainer.docx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/example_inference.py
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/metadata/ctr_vocab.json
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/metadata/export_report.json
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/metadata/feature_stats.json
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/metadata/pca.json
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/metadata/sasrec_vocab.json
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/onnx/DCNV2.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/onnx/DeepFM.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/onnx/LR.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/onnx/SASRec.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/onnx/WideDeep.onnx
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/pytorch_checkpoints/DCNV2.pth
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/pytorch_checkpoints/DeepFM.pth
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/pytorch_checkpoints/LR.pth
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/pytorch_checkpoints/SASRec.pth
RENAMED
|
File without changes
|
{phase1_models β archive/phase1_models}/pytorch_checkpoints/WideDeep.pth
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/engine_features.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_real_backtest.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_simulation.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/results_tag_quality.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage1.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_DeepFM_meta.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_LR_meta.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_WideDeep_meta.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/metadata/stage2_summary.json
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/DeepFM.onnx
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/LR.onnx
RENAMED
|
File without changes
|
{v1_two_stage_engine β archive/v1_two_stage_engine}/onnx/WideDeep.onnx
RENAMED
|
File without changes
|