Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tensorflow/recommenders
TensorFlow Recommenders is a library for building recommender system models using TensorFlow.
https://github.com/tensorflow/recommenders
recommender recommender-system tensorflow tensorflow-recommenders
Last synced: 5 days ago
JSON representation
TensorFlow Recommenders is a library for building recommender system models using TensorFlow.
- Host: GitHub
- URL: https://github.com/tensorflow/recommenders
- Owner: tensorflow
- License: apache-2.0
- Created: 2020-06-26T21:38:01.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-05T06:01:33.000Z (about 1 month ago)
- Last Synced: 2024-12-31T04:03:12.152Z (12 days ago)
- Topics: recommender, recommender-system, tensorflow, tensorflow-recommenders
- Language: Python
- Homepage:
- Size: 1.87 MB
- Stars: 1,872
- Watchers: 50
- Forks: 281
- Open Issues: 270
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Citation: CITATION.cff
Awesome Lists containing this project
- awesome-list - TensorFlow Recommenders - A library for building recommender system models using TensorFlow. (Deep Learning Framework / High-Level DL APIs)
- awesome-python-machine-learning-resources - GitHub - 49% open · ⏱️ 23.08.2022): (推荐系统)
- StarryDivineSky - tensorflow/recommenders
README
# TensorFlow Recommenders
![TensorFlow Recommenders logo](assets/full_logo.png)
![TensorFlow Recommenders build badge](https://github.com/tensorflow/recommenders/actions/workflows/test.yaml/badge.svg)
[![PyPI badge](https://img.shields.io/pypi/v/tensorflow-recommenders.svg)](https://pypi.python.org/pypi/tensorflow-recommenders/)TensorFlow Recommenders is a library for building recommender system models
using [TensorFlow](https://www.tensorflow.org).It helps with the full workflow of building a recommender system: data
preparation, model formulation, training, evaluation, and deployment.It's built on Keras and aims to have a gentle learning curve while still giving
you the flexibility to build complex models.## Installation
Make sure you have TensorFlow 2.x installed, and install from `pip`:
```shell
pip install tensorflow-recommenders
```## Documentation
Have a look at our
[tutorials](https://tensorflow.org/recommenders/examples/quickstart) and
[API reference](https://www.tensorflow.org/recommenders/api_docs/python/tfrs/).## Quick start
Building a factorization model for the Movielens 100K dataset is very simple
([Colab](https://tensorflow.org/recommenders/examples/quickstart)):```python
from typing import Dict, Textimport tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow_recommenders as tfrs# Ratings data.
ratings = tfds.load('movielens/100k-ratings', split="train")
# Features of all the available movies.
movies = tfds.load('movielens/100k-movies', split="train")# Select the basic features.
ratings = ratings.map(lambda x: {
"movie_id": tf.strings.to_number(x["movie_id"]),
"user_id": tf.strings.to_number(x["user_id"])
})
movies = movies.map(lambda x: tf.strings.to_number(x["movie_id"]))# Build a model.
class Model(tfrs.Model):def __init__(self):
super().__init__()# Set up user representation.
self.user_model = tf.keras.layers.Embedding(
input_dim=2000, output_dim=64)
# Set up movie representation.
self.item_model = tf.keras.layers.Embedding(
input_dim=2000, output_dim=64)
# Set up a retrieval task and evaluation metrics over the
# entire dataset of candidates.
self.task = tfrs.tasks.Retrieval(
metrics=tfrs.metrics.FactorizedTopK(
candidates=movies.batch(128).map(self.item_model)
)
)def compute_loss(self, features: Dict[Text, tf.Tensor], training=False) -> tf.Tensor:
user_embeddings = self.user_model(features["user_id"])
movie_embeddings = self.item_model(features["movie_id"])return self.task(user_embeddings, movie_embeddings)
model = Model()
model.compile(optimizer=tf.keras.optimizers.Adagrad(0.5))# Randomly shuffle data and split between train and test.
tf.random.set_seed(42)
shuffled = ratings.shuffle(100_000, seed=42, reshuffle_each_iteration=False)train = shuffled.take(80_000)
test = shuffled.skip(80_000).take(20_000)# Train.
model.fit(train.batch(4096), epochs=5)# Evaluate.
model.evaluate(test.batch(4096), return_dict=True)
```