Download engine_3_0/training_scripts/sync_learned_interests_patch.py from Tirthanker/UniHive_RecSys: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/Tirthanker/UniHive_RecSys/resolve/main/engine_3_0/training_scripts/sync_learned_interests_patch.py
- Command line
-
hf download hf://Tirthanker/UniHive_RecSys/engine_3_0/training_scripts/sync_learned_interests_patch.py
-
curl -L -o sync_learned_interests_patch.py https://huggingface.co/Tirthanker/UniHive_RecSys/resolve/main/engine_3_0/training_scripts/sync_learned_interests_patch.py
1.73 kB
| """Add the learned-interests switch to an already patched `main` checkout (python sync_learned_interests_patch.py <repo root>): | |
| hybrid/__init__.py : learn_interests() reads PERSONALIZATION_ENGINE_LEARNED_INTERESTS (default on) | |
| service.py : create_slate passes it to score_posts_for_slate | |
| Every replacement must match exactly once.""" | |
| import sys | |
| root = sys.argv[1] | |
| def edit(rel, pairs): | |
| p = root + "/" + rel | |
| s = open(p, encoding="utf8", newline="").read(); crlf = "\r\n" in s; s = s.replace("\r\n", "\n") | |
| for a, b in pairs: | |
| assert s.count(a) == 1, (rel, a[:80], s.count(a)) | |
| s = s.replace(a, b) | |
| open(p, "w", encoding="utf8", newline="").write(s.replace("\n", "\r\n") if crlf else s) | |
| print("edited", rel) | |
| edit("backend/personalization/hybrid/__init__.py", [ | |
| ("PERSONALIZATION_ENGINE_ORDER=engine|score chooses how the engine's order reaches `create_slate` (see main_adapter.rank_posts).\n", | |
| "PERSONALIZATION_ENGINE_ORDER=engine|score chooses how the engine's order reaches `create_slate` (see main_adapter.rank_posts).\n" | |
| "PERSONALIZATION_ENGINE_LEARNED_INTERESTS=1|0 (default 1) adds the tags a user keeps engaging with to their declared interests (see main_adapter.learned_interests).\n"), | |
| ("@lru_cache(maxsize=1)\ndef get_engine():", | |
| "def learn_interests() -> bool:\n return os.getenv(\"PERSONALIZATION_ENGINE_LEARNED_INTERESTS\", \"1\").strip().lower() not in (\"0\", \"false\", \"no\", \"off\")\n\n\n" | |
| "@lru_cache(maxsize=1)\ndef get_engine():"), | |
| ]) | |
| edit("backend/personalization/service.py", [ | |
| ("order_mode=hybrid_engine.order_mode())\n", "order_mode=hybrid_engine.order_mode(),learn_interests=hybrid_engine.learn_interests())\n"), | |
| ]) | |