Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Multi-backend recommender systems with Keras 3

License

NotificationsYou must be signed in to change notification settings

keras-team/keras-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KerasRS

Keras Recommenders is a library for building recommender systems on top ofKeras 3. Keras Recommenders works natively with TensorFlow, JAX, or PyTorch. Itprovides a collection of building blocks which help with the full workflow ofcreating a recommender system. As it's built on Keras 3, models can be trainedand serialized in any framework and re-used in another without costlymigrations.

This library is an extension of the core Keras API; all high-level modulesreceive that same level of polish as core Keras. If you are familiar with Keras,congratulations! You already understand most of Keras Recommenders.

Quick Links

Quickstart

Train your own cross network

Choose a backend:

importosos.environ["KERAS_BACKEND"]="jax"# Or "tensorflow" or "torch"!

Import KerasRS and other libraries:

importkerasimportkeras_rsimportnumpyasnp

Define a simple model using theFeatureCross layer:

vocabulary_size=32embedding_dim=6inputs=keras.Input(shape=(),name='indices',dtype="int32")x0=keras.layers.Embedding(input_dim=vocabulary_size,output_dim=embedding_dim)(inputs)x1=keras_rs.layers.FeatureCross()(x0,x0)x2=keras_rs.layers.FeatureCross()(x0,x1)output=keras.layers.Dense(units=10)(x2)model=keras.Model(inputs,output)

Compile the model:

model.compile(loss=keras.losses.MeanSquaredError(),optimizer=keras.optimizers.Adam(learning_rate=3e-4))

Callmodel.fit() on dummy data:

batch_size=2x=np.random.randint(0,vocabulary_size,size=(batch_size,))y=np.random.random(size=(batch_size,))model.fit(x,y=y)

Use ranking losses and metrics

If your task is to rank items in a list, you can make use of the ranking lossesand metrics which KerasRS provides. Below, we use the pairwise hinge loss andtrack the nDCG metric:

model.compile(loss=keras_rs.losses.PairwiseHingeLoss(),metrics=[keras_rs.metrics.NDCG()],optimizer=keras.optimizers.Adam(learning_rate=3e-4),)

Installation

Keras Recommenders is available on PyPI askeras-rs:

pip install keras-rs

To try out the latest version of Keras Recommenders, you can use our nightlypackage:

pip install keras-rs-nightly

ReadGetting started with Keras for moreinformation on installing Keras 3 and compatibility with different frameworks.

Important

We recommend using Keras Recommenders with TensorFlow 2.16 or later, asTF 2.16 packages Keras 3 by default.

Configuring your backend

If you have Keras 3 installed in your environment (see installation above), youcan use Keras Recommenders with any of JAX, TensorFlow and PyTorch. To do so,set theKERAS_BACKEND environment variable. For example:

export KERAS_BACKEND=jax

Or in Colab, with:

importosos.environ["KERAS_BACKEND"]="jax"importkeras_rs

Important

Make sure to set theKERAS_BACKENDbefore importing any Keras libraries;it will be used to set up Keras when it is first imported.

Compatibility

We followSemantic Versioning, and plan to providebackwards compatibility guarantees both for code and saved models built with ourcomponents. While we continue with pre-release0.y.z development, we may breakcompatibility at any time and APIs should not be considered stable.

Citing Keras Recommenders

If Keras Recommenders helps your research, we appreciate your citations.Here is the BibTeX entry:

@misc{kerasrecommenders2024,title={KerasRecommenders},author={Hertschuh, Fabien and  Chollet, Fran\c{c}ois and Sharma, Abheesht and others},year={2024},howpublished={\url{https://github.com/keras-team/keras-rs}},}

Acknowledgements

Thank you to all of our wonderful contributors!

About

Multi-backend recommender systems with Keras 3

Resources

License

Security policy

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp