Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ The table below lists the recommendation models/algorithms featured in Cornac. E

| Year | Model and Paper | Type | Environment | Example |
| :--: | --------------- | :--: | :---------: | :-----: |
| 2026 | [Differentiable Semantic ID for Generative Recommendation (DIGER)](cornac/models/diger), [docs](https://cornac.readthedocs.io/en/stable/api_ref/models.html#module-cornac.models.diger.recom_diger), [paper](https://arxiv.org/abs/2601.19711) | Next-Item / Content-Based | [requirements](cornac/models/diger/requirements.txt), CPU / GPU | [quick-start](examples/diger_example.py) |
| 2025 | [Generating Long Semantic IDs in Parallel for Recommendation (RPG)](cornac/models/rpg), [docs](https://cornac.readthedocs.io/en/stable/api_ref/models.html#module-cornac.models.rpg.recom_rpg), [paper](https://arxiv.org/abs/2506.05781) | Next-Item / Content-Based | [requirements](cornac/models/rpg/requirements.txt), CPU / GPU | [quick-start](examples/rpg_example.py)
| | [Diffusion-based Generative Recommendation Model (DiffGRM)](cornac/models/diffgrm), [docs](https://cornac.readthedocs.io/en/stable/api_ref/models.html#module-cornac.models.diffgrm.recom_diffgrm), [paper](https://arxiv.org/abs/2510.21805) | Next-Item / Content-Based | [requirements](cornac/models/diffgrm/requirements.txt), CPU / GPU | [quick-start](examples/diffgrm_example.py)
| 2024 | [Comparative Aspects and Opinions Ranking for Recommendation Explanations (Companion)](cornac/models/companion), [docs](https://cornac.readthedocs.io/en/stable/api_ref/models.html#module-cornac.models.companion.recom_companion), [paper](https://lthoang.com/assets/publications/mlj24.pdf) | Hybrid / Sentiment / Explainable | CPU | [quick-start](examples/companion_example.py)
Expand Down
1 change: 1 addition & 0 deletions cornac/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from .cvae import CVAE
from .cvaecf import CVAECF
from .dmrl import DMRL
from .diger import DIGER
from .diffgrm import DiffGRM
from .dnntsp import DNNTSP
from .ease import EASE
Expand Down
116 changes: 116 additions & 0 deletions cornac/models/diger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# DIGER

Cornac implementation of **DIGER** (Differentiable Semantic ID for Generative
Recommendation, Fu et al., SIGIR 2026,
[arXiv:2601.19711](https://arxiv.org/abs/2601.19711)). A residual quantizer turns
item content embeddings into semantic IDs; a T5 generator predicts the next
item's ID. Frequency-gated Gumbel assignments let recommendation gradients
update the codebooks alongside the generator.

## Requirements

```bash
pip install -r cornac/models/diger/requirements.txt
```

## Usage

Run the [Amazon Beauty example](../../../examples/diger_example.py) with
precomputed Sentence-T5 embeddings:

```bash
python examples/diger_example.py --features beauty-st5.npz
```

The NPZ archive must contain `features` (a finite float32 matrix) and `ids`
(raw item IDs aligned with its rows), covering every item in the evaluation
splits. Add `--embedding openai` for precomputed OpenAI embeddings; no API key is
needed. Without `--features`, the example generates Sentence-T5 embeddings from
Cornac's item texts (requires `sentence-transformers`). These regenerated
features may differ from those used for the results below.

Supply embeddings through `FeatureModality` in the Python API:

```python
from cornac.data import FeatureModality
from cornac.eval_methods import NextItemEvaluation
from cornac.models import DIGER
from cornac.models.diger import BEAUTY_ST5_CONFIG

eval_method = NextItemEvaluation.from_splits(
train_data=train,
val_data=val,
test_data=test,
mode="last",
item_feature=FeatureModality(features=item_embeddings, ids=item_ids),
)
model = DIGER(**{**BEAUTY_ST5_CONFIG, "device": "auto", "seed": 2025})
```

`BEAUTY_ST5_CONFIG` and `BEAUTY_OPENAI_CONFIG` provide the selected Beauty
training recipe. Validation NDCG@10 is evaluated every epoch; training stops
after 15 non-improving epochs and restores the paired generator, tokenizer and
catalog.

## Implementation notes

- Training uses every history/next-item prefix; validation uses each session's
final target.
- A fresh fit pretrains a feature-width-matched RQ autoencoder (20 warmup epochs,
residual Lloyd initialization, 100 reconstruction/VQ epochs), then freezes its
encoder. This initialization adapts the released recipe. A bundle from
`training.pretrain_tokenizer` can be reused through `initializer` with the same
ordered features and tokenizer options.
- Joint training updates the codebooks and generator together; full-catalog
Sinkhorn assignments refresh each epoch. A deterministic suffix resolves
semantic-ID collisions. Unconstrained beam search scores valid full addresses;
set `n_beams` at least as large as the largest evaluation cutoff and no larger
than the codebook vocabulary.

## Results

The DIGER rows report CPU inference through the Cornac wrapper using six retained
checkpoints on Amazon Reviews 2014 Beauty: 12,068 items, 22,363 test queries,
beam 20 and history limit 210. Training was not rerun through this wrapper.
ST5 uses 768-dimensional Sentence-T5 features; OpenAI uses 3072-dimensional
`text-embedding-3-large` features. Values are mean ± sample SD across joint-training
seeds 2025/2026/2027 with a fixed seed-2024 initializer; metrics are fractions.

For reference, the table also includes Beauty results from the
[TIGER](../tiger/README.md#best-tiger-configs-vs-tuned-sasrec-beauty) and
[RPG](../rpg/README.md#graph-versus-exact-scoring) documentation. DIGER rows
report three-seed mean ± sample SD; reference rows report a single run (seed 123).

| Model / recipe | Features | Recall@5 | NDCG@5 | Recall@10 | NDCG@10 | Recall@20 | NDCG@20 |
| --- | --- | --- | --- | --- | --- | --- | --- |
| DIGER | ST5 | 0.041378 ± 0.001322 | 0.027401 ± 0.000342 | 0.063021 ± 0.001201 | 0.034355 ± 0.000252 | 0.093294 ± 0.003556 | 0.042015 ± 0.000854 |
| [TIGER / `PAISCHER_CONFIG`, RQVAE](../tiger/README.md#best-tiger-configs-vs-tuned-sasrec-beauty) | ST5-base | 0.0419 | 0.0270 | 0.0634 | 0.0338 | 0.0953 | 0.0419 |
| DIGER | OpenAI | 0.044135 ± 0.001538 | 0.028961 ± 0.000630 | 0.069236 ± 0.001704 | 0.037026 ± 0.000674 | 0.105338 ± 0.001701 | 0.046100 ± 0.000367 |
| [TIGER / `PAISCHER_CONFIG`, rkmeans](../tiger/README.md#best-tiger-configs-vs-tuned-sasrec-beauty) | OpenAI | 0.0405 | 0.0265 | 0.0678 | 0.0353 | 0.1045 | 0.0445 |
| [RPG / `RPG_BEAUTY_CONFIG`, graph](../rpg/README.md#graph-versus-exact-scoring) | OpenAI | 0.0533 | 0.0372 | 0.0789 | 0.0454 | 0.1113 | 0.0536 |

TIGER uses history length 20 and constrained beam 50; RPG uses history length
50 and graph beam 20, versus DIGER's history limit 210 and unconstrained beam
20. All use Amazon Reviews 2014 Beauty, but identical filtering, feature arrays
and evaluation populations have not been established. These are reference
results rather than a controlled comparison.

For each DIGER feature setting, all six learning-rate candidates were evaluated,
and the configuration with the highest validation NDCG@10 was selected. This
limited search did not exhaustively explore model, tokenizer or decoding
settings.

The retained DIGER features, initializers and checkpoints are not distributed
with the package; the presets alone do not reproduce this evaluation.

## Semantic ID evaluation

Set `semantic_id_metrics=True` on `NextItemEvaluation`, or add
`--semantic-id-evaluation` to the example, to report SID and CCE Recall/NDCG
alongside ordinary item metrics from one inference. DIGER's complete semantic
IDs include a deterministic collision suffix, so each collision class contains
one item and all three metric views coincide in the reported runs.

Invalid and repeated generated IDs are compacted for semantic-ID metrics. The
evaluator warns about short beams without expanding them. See the
[Semantic ID guide](../../../docs/source/api_ref/eval_methods.rst).
21 changes: 21 additions & 0 deletions cornac/models/diger/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2026 The Cornac Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================

"""DIGER next-item recommendation."""

from .recom_diger import DIGER
from .diger_config import BEAUTY_ST5_CONFIG, BEAUTY_OPENAI_CONFIG

__all__ = ["DIGER", "BEAUTY_ST5_CONFIG", "BEAUTY_OPENAI_CONFIG"]
Loading
Loading