始める無料で始める

チーム用モデルを定義する

チームの強さを参照するルックアップは、入力、埋め込み(embedding)レイヤー、そして出力を作るフラッテン(flatten)レイヤーの3つの要素から成ります。

これら3つのレイヤーを、入力と出力を持つモデルで包むと、その3レイヤーのスタックを複数箇所で再利用できます。

なお、これら「3つすべて」のレイヤーの重みは、使用するあらゆる場所で共有されることに改めて注意してください。

この演習はコースの一部です

Keras で学ぶ高度な Deep Learning

コースを見る

演習の手順

  • チームID(整数)用に1次元の入力レイヤーを作成します。入力形状を正しく設定してください。
  • この入力を、前の演習で作成したチーム強さのルックアップレイヤーに渡します。
  • チーム強さルックアップの出力をフラッテンします。
  • 1次元入力をインプットに、フラット化したチーム強さをアウトプットに持つモデルを作成します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Imports
from tensorflow.keras.layers import Input, Embedding, Flatten
from tensorflow.keras.models import Model

# Create an input layer for the team ID
teamid_in = ____(shape=(____,))

# Lookup the input in the team strength embedding layer
strength_lookup = team_lookup(____)

# Flatten the output
strength_lookup_flat = Flatten()(____)

# Combine the operations into a single, re-usable model
team_strength_model = ____(____, ____, name='Team-Strength-Model')
コードを編集して実行