Skip to content
프로젝트

소개

[Pytorch] 「Recommender Systems with Generative Retrieval」의 시맨틱 ID를 사용하는 생성형 검색 모델입니다.

AI 및 머신러닝

이 수치를 측정하는 방법

What you can do

  • Residual quantization with K-means initialization and Euclidean or cosine assignment.
  • Gumbel-Softmax, straight-through, and rotation-trick gradient estimators.
  • Semantic-ID collision disambiguation and corpus-prefix-constrained generation.
  • A T5 encoder-decoder retrieval model with hit-rate and NDCG evaluation.

측정된 스타 증가

in 24h
0
in 7 days
+1
in 15 days
+3
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

DOI

RQ-VAE Recommender

Tests DOI License: MIT

The DOI badge identifies all versions and resolves to the latest archived release. This release is v1.0.3, archived at its version DOI. The release page provides the release notes.

RQ-VAE Recommender is a PyTorch implementation of semantic-ID tokenization and generative retrieval for recommender-system research. It implements the two-stage workflow introduced by Recommender Systems with Generative Retrieval:

  1. A residual-quantized variational autoencoder (RQ-VAE) maps each catalog item to a short tuple of discrete semantic IDs.
  2. A Transformer consumes a user's semantic-ID history and generates the IDs of likely next items.

RQ-VAE semantic-ID tokenization followed by generative retrieval

Statement of need

Generative recommendation represents catalog items as tokens and retrieves an item by generating its identifier. Research on this approach requires more than an RQ-VAE layer: researchers must prepare sequential datasets, learn stable hierarchical identifiers, handle identifier collisions, train a constrained sequence model, and evaluate ranked outputs. RQ-VAE Recommender provides these parts in one inspectable PyTorch workflow. It is intended for recommender-system researchers and practitioners studying semantic tokenization, vector quantization, cold-item representations, and generative retrieval.

The project prioritizes a compact implementation of the complete experimental pipeline. General-purpose vector-quantization libraries provide reusable neural layers, while broader recommendation frameworks cover many unrelated model families. This repository focuses on the interface between residual semantic-ID learning and next-item generation, with automatic preprocessing for established recommendation datasets and gin-based experiment configurations.

Capabilities

  • Residual quantization with K-means initialization and Euclidean or cosine assignment.
  • Gumbel-Softmax, straight-through, and rotation-trick gradient estimators.
  • Semantic-ID collision disambiguation and corpus-prefix-constrained generation.
  • A T5 encoder-decoder retrieval model with hit-rate and NDCG evaluation.
  • Automatic preprocessing for Amazon Reviews and MovieLens datasets.
  • Optional multi-device/mixed-precision training through Accelerate and optional Weights & Biases logging.
  • A published Amazon Beauty RQ-VAE checkpoint on Hugging Face.

Dataset support differs by stage:

Dataset RQ-VAE tokenization Retrieval-model training
Amazon Reviews: Beauty, Sports, Toys Yes Yes
MovieLens 1M Yes Not currently exposed
MovieLens 32M Yes Not currently exposed

Installation

Python 3.10 or newer is required. A CUDA or MPS accelerator is recommended for full training runs but is not needed for the unit tests.

git clone https://github.com/EdoardoBotta/RQ-VAE-Recommender.git
cd RQ-VAE-Recommender
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e .

On Windows PowerShell, activate the environment with .venv\Scripts\Activate.ps1 instead of source .venv/bin/activate; in Command Prompt use .venv\Scripts\activate.bat.

The requirements.txt file remains available for environments that use a requirements-based workflow. To install development and test tools, use:

python -m pip install -e ".[test]"
pytest

The unit tests run on CPU without downloading datasets or model weights. The training data are downloaded automatically on first use and cached under the configured dataset directory.

Hardware requirements

Recommended system-RAM budgets for one process (estimates, not tested minima):

Setup RAM
MiniLM + RQ-VAE tokenizer, Beauty or ML1M 8 GB
MiniLM + RQ-VAE tokenizer, full ML32M 32 GB
Default sentence-T5-XXL + tokenizer, Beauty or ML1M 32 GB
Default sentence-T5-XXL + tokenizer, full ML32M 64 GB
Small Beauty retriever: 1 layer, width 64, batch 32, 2 beams 8 GB
Standard Beauty retriever: 4 layers, width 384, batch 64, 10 beams 8 GB
Standard Beauty retriever: batch 640, otherwise as above 32 GB

Tokenizer budgets include preprocessing; retrievers assume cached features. Stages run separately, so budget for the largest stage. These estimates assume FP32 model storage; GPU VRAM needs separate assessment. The XXL budgets have not been validated by a complete fresh-preprocessing run, and the default XXL setup failed on the reviewer's 8 GB machine. Its model download alone is 9.7 GB. MiniLM is a newly added optional encoder for smaller verification runs; it requires retraining the tokenizer and has not been shown to preserve XXL's recommendation quality.

Small-model CPU check

For a small-model CPU check on the actual Beauty dataset, run these commands from your activated environment in a macOS/Linux shell:

ACCELERATE_USE_CPU=true TORCHDYNAMO_DISABLE=1 rqvae-train configs/rqvae_amazon_cpu_check.gin
ACCELERATE_USE_CPU=true TORCHDYNAMO_DISABLE=1 rqvae-train-decoder configs/decoder_amazon_cpu_check.gin

These two-step configurations train a new tokenizer and a small retriever, save checkpoints, and evaluate rankings. They download the actual dataset on first use and need no W&B account. They are functionality checks, not reproduction of the research configuration's benchmark scores. For PowerShell, set $env:ACCELERATE_USE_CPU="true" and $env:TORCHDYNAMO_DISABLE="1", then run the commands without the variable prefixes.

Quick API example

The following example verifies semantic-ID generation with a small untrained model:

import torch

from modules.quantize import QuantizeForwardMode
from modules.rqvae import RqVae

model = RqVae(
    input_dim=8,
    embed_dim=4,
    hidden_dims=[16, 8],
    codebook_size=16,
    codebook_kmeans_init=False,
    codebook_mode=QuantizeForwardMode.STE,
    n_layers=3,
    n_cat_features=0,
)
model.eval()

items = torch.randn(5, 8)
semantic_ids = model.get_semantic_ids(items).sem_ids
assert semantic_ids.shape == (5, 3)

See the API overview for the model, tokenizer, data, and tensor interfaces.

Training

Training arguments are managed with gin-config. The train functions in train_rqvae.py and train_decoder.py are configurable, so model dimensions, datasets, optimization settings, evaluation intervals, logging, and output paths can be recorded in a .gin file.

Amazon Reviews

Train the tokenizer, then train the retrieval model from the resulting checkpoint:

rqvae-train configs/rqvae_amazon.gin
rqvae-train-decoder configs/decoder_amazon.gin

The equivalent source-tree commands are:

python train_rqvae.py configs/rqvae_amazon.gin
python train_decoder.py configs/decoder_amazon.gin

configs/decoder_amazon.gin currently points to the example Beauty checkpoint in trained_models/rqvae_amazon_beauty/. Change train.dataset_split and train.pretrained_rqvae_path together when using another Amazon split.

MovieLens 32M tokenizer

The checked-in MovieLens configuration trains the semantic-ID tokenizer only:

rqvae-train configs/rqvae_ml32m.gin

MovieLens 1M also has a tokenizer configuration:

rqvae-train configs/rqvae_ml1m.gin

MovieLens retrieval training is not supported. The obsolete configs/decoder_ml32m.gin has been removed.

All shipped configurations disable Weights & Biases logging. To enable this optional service, set train.wandb_logging=True in your gin file and authenticate with W&B when prompted. The verification workflow needs no W&B account.

Both training functions accept train.item_text_encoder, train.item_text_encoder_revision, train.item_text_batch_size, and train.item_text_device. Set train.vae_input_dim to the selected encoder's output width. Use the same encoder/revision and tokenizer checkpoint in both stages; equal dimensions alone do not make different encoders compatible. Processed caches are separated by encoder/revision. Existing unlabelled data_*.pt caches are regenerated on first use of this revision. New checkpoints record the encoder/revision/feature width and reject incompatible reuse; changing the encoder requires a newly trained tokenizer.

The Amazon backend downloads the third-party P5 archive (1.26 GB) and verifies its SHA-256 before extraction: 511eba3f76facff1829339c0ef10a273207a25fd8bb97181331505d3cbea7238. The source download is hosted by a third party; no project-controlled mirror is provided.

Full configurations are research-scale workloads. Runtime and memory needs vary with the dataset, batch size, text-embedding model, and accelerator. See Reproducibility and verification for what to record and how reviewers can perform a fast objective check.

Documentation and community

Bug reports and feature proposals belong in the issue tracker.

Research use

The repository has been used as the open-source RQ-VAE recommender framework for the public-dataset experiments in Stop Treating Collisions Equally: Qualification-Aware Semantic ID Learning for Recommendation at Industrial Scale. The source release is preserved on Zenodo for v1.0.3.

Citation

If this software supports your research, cite the archived release:

@software{botta2026rqvae,
  author  = {Edoardo Botta},
  title   = {RQ-VAE Recommender},
  version = {1.0.3},
  year    = {2026},
  doi     = {10.5281/zenodo.24664037},
  url     = {https://doi.org/10.5281/zenodo.24664037}
}

Machine-readable citation metadata are available in CITATION.cff.

References

License

RQ-VAE Recommender is distributed under the MIT License.

관련 프로젝트 살펴보기

불러오는 중…