1

こんにちは、テンソルフローとニューラル ネットワークは初めてです。tensorflow の公式モデル リポジトリでncf 推奨モデルを理解しようとしています。

私の理解では、入力レイヤーと学習レイヤーを使用してモデルを構築します。次に、データのバッチを作成してモデルをトレーニングし、テスト データを使用してモデルを評価します。これは、このファイルで行われます。

ただし、入力レイヤーを理解するのに苦労しています。

コードに表示されます

user_input = tf.keras.layers.Input(
      shape=(1,), name=movielens.USER_COLUMN, dtype=tf.int32)

私の理解では、一度に 1 つのパラメーターを入力できます。

ただし、次のダミーデータを使用して predict_on_batch を呼び出すことしかできません

user_input = np.full(shape=(256,),fill_value=1, dtype=np.int32)
item_input = np.full(shape=(256,),fill_value=1, dtype=np.int32)
valid_pt_mask_input = np.full(shape=(256,),fill_value=True, dtype=np.bool)
dup_mask_input = np.full(shape=(256,),fill_value=1, dtype=np.int32)
label_input = np.full(shape=(256,),fill_value=True, dtype=np.bool)
test_input_list = [user_input,item_input,valid_pt_mask_input,dup_mask_input,label_input]

tf.print(keras_model.predict_on_batch(test_input_list))

次のコードを実行すると:

    user_input = np.full(shape=(1,),fill_value=1, dtype=np.int32)
    item_input = np.full(shape=(1,),fill_value=1, dtype=np.int32)
    valid_pt_mask_input = np.full(shape=(1,),fill_value=True, dtype=np.bool)
    dup_mask_input = np.full(shape=(1,),fill_value=1, dtype=np.int32)
    label_input = np.full(shape=(1,),fill_value=True, dtype=np.bool)
    test_input_list = [user_input,item_input,valid_pt_mask_input,dup_mask_input,label_input]

    classes = _model.predict(test_input_list)
    tf.print(classes)

このエラーが発生しました:

tensorflow.python.framework.errors_impl.InvalidArgumentError:  Input to reshape is a tensor with 1 values, but the requested shape requires a multiple of 256
     [[{{node model_1/metric_layer/StatefulPartitionedCall/StatefulPartitionedCall/Reshape_1}}]] [Op:__inference_predict_function_2828]

このモデルを使用して単一の入力で予測する方法を教えてもらえますか? また、予測を行うときに item_id と user_id が必要なのはなぜですか? モデルがアイテムのリストを返すユーザーのリストを提供するべきではありませんか?

4

2 に答える 2