定义团队模型
球队实力查询由三个组件组成:一个输入层、一个嵌入层,以及一个将输出展开的 flatten 层。
如果将这三层封装到一个具有输入和输出的模型中,您就可以在多个位置重复使用这组三层的堆叠。
请再次注意,我们在所有使用它们的地方,以上这三层的权重都会被共享。
本练习是课程的一部分
使用 Keras 的高级深度学习
练习说明
- 为球队 ID(整数)创建一个 1D 输入层。务必设置正确的输入形状!
- 将该输入传入您之前创建的球队实力查询层。
- 将球队实力查询的输出进行展平。
- 创建一个模型,使用该 1D 输入作为输入,展平后的球队实力作为输出。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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')