Option to redraw negatives that coincide with the target in `CatalogUniformSampler`
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 78/100
- Tipo de issue
- Funcionalidade
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Domínio
- machine-learning
Direção de pesquisa
Comece por rectools/models/nn/transformers/negative_sampler.py e leia CatalogUniformSampler.get_negatives; compare o tratamento de colisões com _NegativeSampler em rectools/fast_transformers/unisrec/model.py. Adicione o comportamento opcional por meio de negative_sampler_kwargs, mantendo inalterado o comportamento padrão, e confira os testes unitários do sampler. O trabalho estará concluído quando os negativos que colidem forem sorteados novamente quando a opção estiver habilitada e o comportamento existente for preservado por padrão.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 457
- Forks
- 55
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de MTSWebServices/RecTools
-
Is it not possible to `load` transformer model on cpu onlyTalvez já em andamento @maxteneff assumiu há 22 dias. Abertabug good first issue
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
MTSWebServices/RecTools#286 · 3 comentários ·
-
bug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
MTSWebServices/RecTools#269 · 4 comentários ·
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
MTSWebServices/RecTools#249 ·
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
MTSWebServices/RecTools#243 ·
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
MTSWebServices/RecTools#242 ·
Todas as issues de MTSWebServices/RecTools
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 87/100
Mantenedores costumam responder em até 7 dias
-
S9.7: Methodology pageAbertaarea: web priority: P1 story
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
nfiasco/Quant-Time-Machine#151 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
autowarefoundation/autoware_carla_scenario#2019 ·
Mantenedores costumam responder em até 1 dia
-
Broken links found in docsAbertadocs pydanty:is-working
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
pydantic/pydantic-ai#12892 ·
Mantenedores costumam responder em até 1 dia