Registry / ai-ml / tensorflow-ranking

tensorflow-ranking

JSON →
library0.5.5pypypiunverified

TensorFlow Ranking is a library for Learning to Rank (LTR) with TensorFlow. It provides ranking losses, metrics, layers, and pipelines for building and training ranking models. The current version is 0.5.5. It is actively maintained by TensorFlow, with releases approximately every few months.

pip install tensorflow-ranking
INSTALL
IMPORT
SIG · TENSORFLOW-RANKING
T
tensorflow-ranking
ai-mlpythonv0.5.5
Install
31.7s avg
Import
10543ms
Disk
1226MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 32s
py 3.11
✓ —
✓ 31.9s
py 3.12
✕ build_error
✓ 29.3s
py 3.13
✕ build_error
✓ 28.6s
py 3.9
✓ —
✓ 36.5s
1226MB installed
● package 1226MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tfr
import tensorflow_ranking as tfr
import tensorflow_ranking as tf_ranking
tfr is the standard alias in all official examples.
tfr.keras.losses
from tensorflow_ranking.python.keras import losses
from tfr.keras import losses
Full path required; 'tfr' is an alias, not a module.
tfr.keras.metrics
from tensorflow_ranking.python.keras import metrics
Use the full module path for consistency.

Minimal example of building and compiling a ranking model using TensorFlow Ranking with a DNN and approxNDCG loss.

import tensorflow as tf import tensorflow_ranking as tfr # Create a simple ranking model using Keras inputs inputs = { 'example_feature': tf.keras.Input(shape=(10,), dtype=tf.float32), 'list_size': tf.keras.Input(shape=(), dtype=tf.int32) } # Build a simple two-layer DNN ranking model hidden = tf.keras.layers.Dense(16, activation='relu')(inputs['example_feature']) scores = tf.keras.layers.Dense(1)(hidden) # Flatten scores per list for ranking loss list_size = tf.squeeze(inputs['list_size']) scores = tf.reshape(scores, [-1, list_size]) model = tf.keras.Model(inputs=inputs, outputs=scores) # Use a ranking loss (e.g., approxNDCG loss) loss = tfr.keras.losses.ApproxNDCGLoss() model.compile(optimizer='adam', loss=loss) print('Model compiled successfully.')
Debug
Known issues
breakingTensorFlow Ranking 0.5.0 removed the old RankingNetwork-based API. Code using 'tfr.estimator' or 'tfr.feature' may break.
fix
Migrate to the Keras-based API using 'tfr.keras.losses', 'tfr.keras.metrics', and 'tfr.keras.model'.
affects: >=0.5.0
breakingTensorFlow Ranking 0.4.0 introduced a new Keras API that is not backward compatible with the Estimator API. Old scripts using 'tfr.estimator.make_groupwise_ranking_estimator' require updates.
fix
Use the new Keras layers and losses. See migration guide at https://github.com/tensorflow/ranking/blob/master/README.md.
affects: >=0.4.0
deprecatedThe 'tfr.estimator' module is deprecated as of 0.5.0 and will be removed in a future release.
fix
Use 'tfr.keras.model' or 'tfr.keras.task' for training.
affects: >=0.5.0
gotchaTensorFlow Ranking requires TensorFlow 2.x. Installing with TensorFlow 1.x may lead to import errors.
fix
Ensure TensorFlow 2.x is installed: pip install 'tensorflow>=2.0'.
affects: all
gotchaImporting 'tfr' directly without the full path can cause ambiguity. Always use 'import tensorflow_ranking as tfr'.
fix
Use the correct import statement as shown in quickstart.
affects: all
Upgrade
Version history
0.5.5latest on PyPI · released Mar 18, 2024
Audit
Dependencies
tensorflowrequiredRequired core library for all operations.
tensorflow-serving-apirequiredRequired for serving models.
Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
tensorflow-ranking — pip install tensorflow-ranking · libregistry