Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.


GitHub License PyPI - Version Documentation PyPI - Downloads
GitHub Workflow Status (with event) Ruff Python Versions Join the community on GitHub Discussions

RePlay is an advanced framework designed to facilitate the development and evaluation of recommendation systems. It provides a robust set of tools covering the entire lifecycle of a recommendation system pipeline:

🚀 Features:

  • Data Preprocessing and Splitting: Streamlines the data preparation process for recommendation systems, ensuring optimal data structure and format for efficient processing.
  • Wide Range of Recommendation Models: Enables building of recommendation models from State-of-the-Art to commonly-used baselines and evaluate their performance and quality.
  • Hyperparameter Optimization: Offers tools for fine-tuning model parameters to achieve the best possible performance, reducing the complexity of the optimization process.
  • Comprehensive Evaluation Metrics: Incorporates a wide range of evaluation metrics to assess the accuracy and effectiveness of recommendation models.
  • Model Ensemble and Hybridization: Supports combining predictions from multiple models and creating two-level (ensemble) models to enhance the quality of recommendations.
  • Seamless Mode Transition: Facilitates easy transition from offline experimentation to online production environments, ensuring scalability and flexibility.

💻 Hardware and Environment Compatibility:

  1. Diverse Hardware Support: Compatible with various hardware configurations including CPU, GPU, Multi-GPU.
  2. Cluster Computing Integration: Integrating with PySpark for distributed computing, enabling scalability for large-scale recommendation systems.

Table of Contents

📈 Quickstart

pip install replay-rec[all]

Pyspark-based model and fast polars-based data preprocessing:

from polars import from_pandas
from rs_datasets import MovieLens

from replay.data import Dataset, FeatureHint, FeatureInfo, FeatureSchema, FeatureType
from replay.data.dataset_utils import DatasetLabelEncoder
from replay.metrics import HitRate, NDCG, Experiment
from replay.models import ItemKNN
from replay.utils.spark_utils import convert2spark
from replay.utils.session_handler import State
from replay.splitters import RatioSplitter

spark = State().session

ml_1m = MovieLens("1m")
K = 10

# convert data to polars
interactions = from_pandas(ml_1m.ratings)

# data splitting
splitter = RatioSplitter(
    test_size=0.3,
    divide_column="user_id",
    query_column="user_id",
    item_column="item_id",
    timestamp_column="timestamp",
    drop_cold_items=True,
    drop_cold_users=True,
)
train, test = splitter.split(interactions)

# datasets creation
feature_schema = FeatureSchema(
    [
        FeatureInfo(
            column="user_id",
            feature_type=FeatureType.CATEGORICAL,
            feature_hint=FeatureHint.QUERY_ID,
        ),
        FeatureInfo(
            column="item_id",
            feature_type=FeatureType.CATEGORICAL,
            feature_hint=FeatureHint.ITEM_ID,
        ),
        FeatureInfo(
            column="rating",
            feature_type=FeatureType.NUMERICAL,
            feature_hint=FeatureHint.RATING,
        ),
        FeatureInfo(
            column="timestamp",
            feature_type=FeatureType.NUMERICAL,
            feature_hint=FeatureHint.TIMESTAMP,
        ),
    ]
)

train_dataset = Dataset(feature_schema=feature_schema, interactions=train)
test_dataset = Dataset(feature_schema=feature_schema, interactions=test)

# data encoding
encoder = DatasetLabelEncoder()
train_dataset = encoder.fit_transform(train_dataset)
test_dataset = encoder.transform(test_dataset)

# convert datasets to spark
train_dataset.to_spark()
test_dataset.to_spark()

# model training
model = ItemKNN()
model.fit(train_dataset)

# model inference
encoded_recs = model.predict(
    dataset=train_dataset,
    k=K,
    queries=test_dataset.query_ids,
    filter_seen_items=True,
)

recs = encoder.query_and_item_id_encoder.inverse_transform(encoded_recs)

# model evaluation
metrics = Experiment(
    [NDCG(K), HitRate(K)],
    test,
    query_column="user_id",
    item_column="item_id",
    rating_column="rating",
)
metrics.add_result("ItemKNN", recs)
print(metrics.results)

🔧 Installation

Installation via pip package manager is recommended by default:

pip install replay-rec

In this case it will be installed the core package without PySpark and PyTorch dependencies. Also experimental submodule will not be installed.

To install experimental submodule please specify the version with rc0 suffix. For example:

pip install replay-rec==XX.YY.ZZrc0

Extras

In addition to the core package, several extras are also provided, including:

  • [spark]: Install PySpark functionality
  • [torch]: Install PyTorch and Lightning functionality

Example:

# Install core package with PySpark dependency
pip install replay-rec[spark]

# Install package with experimental submodule and PySpark dependency
pip install replay-rec[spark]==XX.YY.ZZrc0

Additionally, replay-rec[torch] may be installed with CPU-only version of torch by providing its respective index URL during installation:

# Install package with the CPU version of torch
pip install replay-rec[torch] --extra-index-url https://download.pytorch.org/whl/cpu

To build RePlay from sources please use the instruction.

Optional features

RePlay includes a set of optional features which require users to install optional dependencies manually. These features include:

  1. Hyperpearameter search via Optuna:
pip install optuna
  1. Model compilation via OpenVINO:
pip install openvino onnx onnxscript
  1. Vector database and hierarchical search support:
pip install hnswlib fixed-install-nmslib
  1. (Experimental) LightFM model support:
pip install ligfhtfm

NOTE : LightFM is not officially supported for Python 3.12 due to discontinued maintenance of the library. If you wish to install it locally, you'll have to use a patched fork of LightFM, such as the one used internally.

📑 Resources

Usage examples

  1. 01_replay_basics.ipynb - get started with RePlay.
  2. 02_models_comparison.ipynb - reproducible models comparison on MovieLens-1M dataset.
  3. 03_features_preprocessing_and_lightFM.ipynb - LightFM example with pyspark for feature preprocessing.
  4. 04_splitters.ipynb - An example of using RePlay data splitters.
  5. 05_feature_generators.ipynb - Feature generation with RePlay.
  6. 06_item2item_recommendations.ipynb - Item to Item recommendations example.
  7. 07_filters.ipynb - An example of using filters.
  8. 08_recommending_for_categories.ipynb - An example of recommendation for product categories.
  9. 09_sasrec_example.ipynb - An example of using transformer-based SASRec model to generate recommendations.
  10. 10_bert4rec_example.ipynb - An example of using transformer-based BERT4Rec model to generate recommendations.
  11. 11_sasrec_dataframes_comparison.ipynb - speed comparison of using different frameworks (pandas, polars, pyspark) for data processing during SASRec training.
  12. 12_neural_ts_exp.ipynb - An example of using Neural Thompson Sampling bandit model (based on Wide&Deep architecture).
  13. 13_personalized_bandit_comparison.ipynb - A comparison of context-free and contextual bandit models.
  14. 14_hierarchical_recommender.ipynb - An example of using HierarchicalRecommender with user-disjoint LinUCB.
  15. 15_twotower_example.ipynb - An example of using transformer-based TwoTower model with batch-wise reading and preprocessing via ParquetModule.

Videos and papers

💡 Contributing to RePlay

We welcome community contributions. For details please check our contributing guidelines.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

replay_rec-0.22.0rc0.tar.gz (356.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

replay_rec-0.22.0rc0-py3-none-any.whl (506.0 kB view details)

Uploaded Python 3

File details

Details for the file replay_rec-0.22.0rc0.tar.gz.

File metadata

  • Download URL: replay_rec-0.22.0rc0.tar.gz
  • Upload date:
  • Size: 356.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for replay_rec-0.22.0rc0.tar.gz
Algorithm Hash digest
SHA256 489a9344a3b3a3d7c3234fcc27c44a6570e5a4ea72e1db51c453850f0994f424
MD5 064b61c642b410aec1c614cdf1b2742b
BLAKE2b-256 a0f6d0a4cdf4771b1971d912b0a4e4a92edb1f588b93fba4987133b5ec909a01

See more details on using hashes here.

Provenance

The following attestation bundles were made for replay_rec-0.22.0rc0.tar.gz:

Publisher: publish.yml on sb-ai-lab/RePlay

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file replay_rec-0.22.0rc0-py3-none-any.whl.

File metadata

  • Download URL: replay_rec-0.22.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 506.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for replay_rec-0.22.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c3ebd8d15cb83355ac56f7e6e4a1aa92707d7245b4355229c302a47694ea39b
MD5 a327637e87df3e8deebec638d8017ad0
BLAKE2b-256 87dac171f624ff82e68c128906aa155a40d3fa5a4b7d7aecac2b020b946c282e

See more details on using hashes here.

Provenance

The following attestation bundles were made for replay_rec-0.22.0rc0-py3-none-any.whl:

Publisher: publish.yml on sb-ai-lab/RePlay

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.22.0

2 files

This release

0.22.0rc0 This release

2 files

0.21.8

2 files

0.21.7

2 files

0.21.6

2 files

0.21.5

2 files

0.21.4

2 files

0.21.3

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.20.3

2 files

0.20.2

2 files

0.20.1

2 files

0.20.0

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page