スケーラブルなニューラル ラーニング トゥ ランク (LTR) モデル,スケーラブルなニューラル ラーニング トゥ ランク (LTR) モデル

import tensorflow as tf
import tensorflow_datasets as tfds
import tensorflow_ranking as tfr

# Prep data
ds = tfds.load("mslr_web/10k_fold1", split="train")
ds = ds.map(lambda feature_map: {
    "_mask": tf.ones_like(feature_map["label"], dtype=tf.bool),
    **feature_map
})
ds = ds.shuffle(buffer_size=1000).padded_batch(batch_size=32)
ds = ds.map(lambda feature_map: (
    feature_map, tf.where(feature_map["_mask"], feature_map.pop("label"), -1.)))

# Create a model
inputs = {
    "float_features": tf.keras.Input(shape=(None, 136), dtype=tf.float32)
}
norm_inputs = [tf.keras.layers.BatchNormalization()(x) for x in inputs.values()]
x = tf.concat(norm_inputs, axis=-1)
for layer_width in [128, 64, 32]:
  x = tf.keras.layers.Dense(units=layer_width)(x)
  x = tf.keras.layers.Activation(activation=tf.nn.relu)(x)
scores = tf.squeeze(tf.keras.layers.Dense(units=1)(x), axis=-1)

# Compile and train
model = tf.keras.Model(inputs=inputs, outputs=scores)
model.compile(
    optimizer=tf.keras.optimizers.Adam(learning_rate=0.01),
    loss=tfr.keras.losses.SoftmaxLoss(),
    metrics=tfr.keras.metrics.get("ndcg", topn=5, name="NDCG@5"))
model.fit(ds, epochs=3)
ノートブックで実行

TensorFlow Ranking は、スケーラブルなニューラル学習によるランク付け(LTR) モデルを開発するためのオープンソース ライブラリです。ランキング モデルは通常、検索およびレコメンデーション システムで使用されますが、機械翻訳対話システムの電子商取引SAT ソルバースマート シティ プランニング、さらには計算生物学など、さまざまな分野での適用にも成功しています。

ランキング モデルは、アイテム (Web ページ、ドキュメント、製品、映画など) のリストを取得し、最適化された順序でリストを生成します。たとえば、最も関連性の高いアイテムを一番上に、最も関連性の低いアイテムを一番下に配置します。ユーザークエリ:

このライブラリは、LTR モデルの標準的なポイント単位、ペア単位、およびリスト単位の損失関数をサポートしています。また、 Mean Reciprocal Rank (MRR) やNormalized Discounted Cumulative Gain (NDCG) などの幅広いランキング メトリクスもサポートしているため、ランキング タスクでこれらのアプローチを評価および比較できます。ランキング ライブラリは、Google の機械学習エンジニアによって調査、テスト、構築された、強化されたランキング アプローチの機能も提供します。

チュートリアルをチェックして、TensorFlow Ranking ライブラリを使い始めましょう。概要を読んで、ライブラリの機能の詳細を確認してください。GitHubで TensorFlow Ranking のソース コードを確認してください。