我正在嘗試使用預訓練的嵌入作為神經網路中的一個層,但無法讓它發揮作用。我得到的錯誤是在重塑層:
Tried to convert 'shape' to a tensor and failed. Error: None values not supported.
我在這里做錯了什么?
epochs = 50
n_units = 512
embedding_size = 200
text_in = Input(shape = ())
embedding_layer = hub.KerasLayer("https://tfhub.dev/google/elmo/3")(text_in)
reshape = tf.keras.layers.Reshape(target_shape=(None, 1024, 1))(embedding_layer)
x = LSTM(n_units)(reshape)
x = Dropout(0.2)(x)
text_out = Dense(total_words, activation = 'softmax')(x)
model = Model(inputs=[input_layer], outputs=output_layer, name="LSTM with ELMo Embeddings")
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
uj5u.com熱心網友回復:
“無”不應該在那里。Keras 有點奇怪,它經常將第一維視為特殊的東西。在這種情況下,第一個(批量大小)維度被省略并且層不能改變它。
否則,您的代碼可能會有更多問題。input_layer并且output_layer沒有定義。形狀 (?, 1024, 1) 很奇怪。您有長度為 1024 的序列并且只有一維嵌入?整個代碼看起來是錯誤的。
uj5u.com熱心網友回復:
根據檔案https://keras.io/api/layers/reshaping_layers/reshape/ None不支持keras.layers.Reshape. 但是,您可以改用-1它,它應該可以按您的意愿作業
PS:不要忘記更改input_layer/ output_layer(中keras.Model)由text_in/ text_out(你不需要把input_layer串列中的BTW)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370278.html
下一篇:替換超出一定范圍的張量元素
