# 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, Text
import 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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/tensorflow/recommenders",
"name": "tensorflow-recommenders",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "tensorflow recommenders recommendations",
"author": "Google Inc.",
"author_email": "packages@tensorflow.org",
"download_url": "https://files.pythonhosted.org/packages/c0/d0/50dbb1a2b9d775a580441c45269b71b60aea3b0358f8131ae3f5c8e4ccec/tensorflow-recommenders-0.7.3.tar.gz",
"platform": null,
"description": "# TensorFlow Recommenders\n\n![TensorFlow Recommenders logo](assets/full_logo.png)\n\n![TensorFlow Recommenders build badge](https://github.com/tensorflow/recommenders/actions/workflows/test.yaml/badge.svg)\n[![PyPI badge](https://img.shields.io/pypi/v/tensorflow-recommenders.svg)](https://pypi.python.org/pypi/tensorflow-recommenders/)\n\nTensorFlow Recommenders is a library for building recommender system models\nusing [TensorFlow](https://www.tensorflow.org).\n\nIt helps with the full workflow of building a recommender system: data\npreparation, model formulation, training, evaluation, and deployment.\n\nIt's built on Keras and aims to have a gentle learning curve while still giving\nyou the flexibility to build complex models.\n\n## Installation\n\nMake sure you have TensorFlow 2.x installed, and install from `pip`:\n\n```shell\npip install tensorflow-recommenders\n```\n\n## Documentation\n\nHave a look at our\n[tutorials](https://tensorflow.org/recommenders/examples/quickstart) and\n[API reference](https://www.tensorflow.org/recommenders/api_docs/python/tfrs/).\n\n## Quick start\n\nBuilding a factorization model for the Movielens 100K dataset is very simple\n([Colab](https://tensorflow.org/recommenders/examples/quickstart)):\n\n```python\nfrom typing import Dict, Text\n\nimport tensorflow as tf\nimport tensorflow_datasets as tfds\nimport tensorflow_recommenders as tfrs\n\n# Ratings data.\nratings = tfds.load('movielens/100k-ratings', split=\"train\")\n# Features of all the available movies.\nmovies = tfds.load('movielens/100k-movies', split=\"train\")\n\n# Select the basic features.\nratings = ratings.map(lambda x: {\n \"movie_id\": tf.strings.to_number(x[\"movie_id\"]),\n \"user_id\": tf.strings.to_number(x[\"user_id\"])\n})\nmovies = movies.map(lambda x: tf.strings.to_number(x[\"movie_id\"]))\n\n# Build a model.\nclass Model(tfrs.Model):\n\n def __init__(self):\n super().__init__()\n\n # Set up user representation.\n self.user_model = tf.keras.layers.Embedding(\n input_dim=2000, output_dim=64)\n # Set up movie representation.\n self.item_model = tf.keras.layers.Embedding(\n input_dim=2000, output_dim=64)\n # Set up a retrieval task and evaluation metrics over the\n # entire dataset of candidates.\n self.task = tfrs.tasks.Retrieval(\n metrics=tfrs.metrics.FactorizedTopK(\n candidates=movies.batch(128).map(self.item_model)\n )\n )\n\n def compute_loss(self, features: Dict[Text, tf.Tensor], training=False) -> tf.Tensor:\n\n user_embeddings = self.user_model(features[\"user_id\"])\n movie_embeddings = self.item_model(features[\"movie_id\"])\n\n return self.task(user_embeddings, movie_embeddings)\n\n\nmodel = Model()\nmodel.compile(optimizer=tf.keras.optimizers.Adagrad(0.5))\n\n# Randomly shuffle data and split between train and test.\ntf.random.set_seed(42)\nshuffled = ratings.shuffle(100_000, seed=42, reshuffle_each_iteration=False)\n\ntrain = shuffled.take(80_000)\ntest = shuffled.skip(80_000).take(20_000)\n\n# Train.\nmodel.fit(train.batch(4096), epochs=5)\n\n# Evaluate.\nmodel.evaluate(test.batch(4096), return_dict=True)\n```\n\n\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Tensorflow Recommenders, a TensorFlow library for recommender systems.",
"version": "0.7.3",
"split_keywords": [
"tensorflow",
"recommenders",
"recommendations"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d3917f9977f26bc0c94269d3f157710e9f1a112d1af23d4588285d846228ce3c",
"md5": "1998ea6ac1712a4dc9a8b0ec493fbd72",
"sha256": "aa1ec194a0259e4a0d6a06d913a2b33e018762b9b11ed4570764f522afe80193"
},
"downloads": -1,
"filename": "tensorflow_recommenders-0.7.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1998ea6ac1712a4dc9a8b0ec493fbd72",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 96183,
"upload_time": "2023-02-03T02:15:53",
"upload_time_iso_8601": "2023-02-03T02:15:53.611469Z",
"url": "https://files.pythonhosted.org/packages/d3/91/7f9977f26bc0c94269d3f157710e9f1a112d1af23d4588285d846228ce3c/tensorflow_recommenders-0.7.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c0d050dbb1a2b9d775a580441c45269b71b60aea3b0358f8131ae3f5c8e4ccec",
"md5": "1b4f0e1c3fd3e40347fbbec2b694605f",
"sha256": "e71fe52104865ed75794e1d609b2c0dcaa0c70cd0ee23abd9d092a246df86e53"
},
"downloads": -1,
"filename": "tensorflow-recommenders-0.7.3.tar.gz",
"has_sig": false,
"md5_digest": "1b4f0e1c3fd3e40347fbbec2b694605f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 61915,
"upload_time": "2023-02-03T02:15:55",
"upload_time_iso_8601": "2023-02-03T02:15:55.460987Z",
"url": "https://files.pythonhosted.org/packages/c0/d0/50dbb1a2b9d775a580441c45269b71b60aea3b0358f8131ae3f5c8e4ccec/tensorflow-recommenders-0.7.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-03 02:15:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "tensorflow",
"github_project": "recommenders",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "tensorflow-recommenders"
}