Option to redraw negatives that coincide with the target in `CatalogUniformSampler`
まだ誰も着手していません。
評価
- 難易度
- 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 ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 25/100
MTSWebServices/RecTools#249 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
MTSWebServices/RecTools#243 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 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 日以内に返信