在Keras嵌入层中传递batch_input_shape参数时出现值错误

问题描述 投票:0回答:1

我在 Jupyter Lab 和 VScode 中传递“batch_input_shape”时也遇到问题。

### Defining the RNN Model ###
def LSTM(rnn_units):
  return tf.keras.layers.LSTM(
    rnn_units,
    return_sequences=True,
    recurrent_initializer='glorot_uniform',
    recurrent_activation='sigmoid',
    stateful=True,
  )

def build_model(vocab_size, embedding_dim, rnn_units, batch_size):
  model = tf.keras.Sequential([
    tf.keras.layers.Embedding(vocab_size, embedding_dim, **batch_input_shape=[batch_size,None])**,
    LSTM(rnn_units),
    tf.keras.layers.Dense(vocab_size)
  ])
  return model


model = build_model(len(vocab), embedding_dim=256, rnn_units=1024, batch_size=32)
python tf.keras keras-layer
1个回答
0
投票

我目前也有同样的问题(并且也在做麻省理工学院的深度学习课程)。问题的原因(我认为)是因为 Keras API 发生了变化。我不确定替代关键字 arg 是什么,而且我还没有找到任何东西。

https://www.tensorflow.org/api_docs/python/tf/keras/layers/Embedding

嵌入层根本没有任何与batch_input_shape相关的东西。不幸的是,我对 Keras API 和深度学习的了解很少。如果找到解决方案,我会继续发布。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.