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
py 3.12
✕ build_error
✓ 29.3s
py 3.13
✕ build_error
✓ 28.6s
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.')
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.