Option to redraw negatives that coincide with the target in `CatalogUniformSampler`
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
从rectools/models/nn/transformers/negative_sampler.py开始,阅读CatalogUniformSampler.get_negatives;将其碰撞处理方式与rectools/fast_transformers/unisrec/model.py中的_NegativeSampler进行比较。通过negative_sampler_kwargs添加可选行为,同时保持默认行为不变,并检查 sampler 的单元测试。启用该行为时,发生碰撞的负样本会重新抽取,且默认情况下保留现有行为,即为完成。
由索引模型根据 Issue 内容生成。
描述
Feature Description
Add an opt-in parameter to CatalogUniformSampler (for example avoid_positive_collisions: bool = False) that redraws sampled negatives equal to the target item at the same position. It would be enabled through the existing negative_sampler_kwargs:
SASRecModel(loss="gBCE", n_negatives=256, negative_sampler_kwargs={"avoid_positive_collisions": True})
The default would keep the current behaviour, so existing configs and seeded results do not change.
Why this feature?
CatalogUniformSampler.get_negatives (rectools/models/nn/transformers/negative_sampler.py) samples negatives uniformly from all catalog items (as its docstring says) using torch.randint, without excluding the target. With BCE, gBCE or sampled_softmax, the same item can then be scored as both the positive and a negative in one loss term.
The UniSRec model added in 0.19.0 already handles this: _NegativeSampler in rectools/fast_transformers/unisrec/model.py redraws colliding negatives once. The transformer models in rectools.models.nn (SASRec, BERT4Rec, HSTU) have no such option, although users can subclass TransformerNegativeSamplerBase to get it.
The collision probability per negative is 1 / n_items. With n_negatives=256:
| catalog size | share of negatives equal to the target | share of positions with at least one such negative |
|---|---|---|
| 3,416 (ML-1M as used in the SASRec/gSASRec papers) | 0.03% | 7.2% |
| 500 | 0.2% | 40% |
| 100 | 1.0% | 92% |
On a synthetic dataset with 100 items (2,000 users, 22 interactions each), SASRecModel with loss="sampled_softmax" and n_negatives=256 reached NDCG@10 of about 0.127 (RecTools NDCG(k=10), default settings). Redrawing colliding negatives until none were left changed this by -0.0009 on average over 3 seeds, which is within run-to-run noise. So I don't expect a measurable metric gain; the aim is consistency with UniSRec and sampling negatives the way the gBCE sampling rate alpha = n_negatives / (n_items - 1) already assumes.
Additional context
I have a small patch ready (one redraw pass, same as _NegativeSampler, plus unit tests and a changelog entry) and can open a PR if this is welcome.
- 主要语言
- Python
- 星标
- 457
- 派生
- 55
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MTSWebServices/RecTools 的其他 Issue
-
Is it not possible to `load` transformer model on cpu only可能已有人在做 @maxteneff 于 22 天前认领。 未关闭bug good first issue
难度 3/5 1-2 天 新手友好度 35/100
MTSWebServices/RecTools#286 · 3 条评论 ·
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 35/100
MTSWebServices/RecTools#269 · 4 条评论 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
MTSWebServices/RecTools#249 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
MTSWebServices/RecTools#243 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
MTSWebServices/RecTools#242 ·
查看 MTSWebServices/RecTools 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
-
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 7 天内回复
-
area: web priority: P1 story
难度 2/5 1-3 小时 新手友好度 76/100
nfiasco/Quant-Time-Machine#151 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
autowarefoundation/autoware_carla_scenario#2019 ·
维护者通常 1 天内回复
-
docs pydanty:is-working
难度 1/5 1-3 小时 新手友好度 85/100
pydantic/pydantic-ai#12892 ·
维护者通常 1 天内回复