如何重塑文本数据以适合keras中的LSTM模型
更新1:
Im所指的代码正是本书中的代码,您可以在这里找到。
唯一的事情是我不想embed_size
在解码器部分中拥有。这就是为什么我认为根本不需要嵌入层的原因,因为如果我放入嵌入层,则需要包含embed_size
在解码器部分中(如果Im错误,请更正我)。
总体而言,我试图在不使用嵌入层的情况下采用相同的代码,因为我需要vocab_size
在解码器部分中具有。
我认为评论中提供的建议可能是正确的(using one_hot_encoding
)我如何面对此错误:
当我做的时候one_hot_encoding
:
tf.keras.backend.one_hot(indices=sent_wids, classes=vocab_size)
我收到此错误:
in check_num_samples you should specify the + steps_name + argument
ValueError: If your data is in the form of symbolic tensors, you should
specify the steps_per_epoch argument (instead of the batch_size argument,
because symbolic tensors are expected to produce batches of input data)
我准备数据的方式是这样的:
sent_lens
is的 形状,(87716,
200)
我想以可以将其输入LSTM的方式重塑形状。这里200
代表sequence_lenght
,87716
是我拥有的样本数。
以下是代码LSTM Autoencoder
:
inputs = Input(shape=(SEQUENCE_LEN,VOCAB_SIZE), name="input")
encoded = Bidirectional(LSTM(LATENT_SIZE), merge_mode="sum", name="encoder_lstm")(inputs)
decoded = RepeatVector(SEQUENCE_LEN, name="repeater")(encoded)
decoded = LSTM(VOCAB_SIZE, return_sequences=True)(decoded)
autoencoder = Model(inputs, decoded)
autoencoder.compile(optimizer="sgd", loss='mse')
autoencoder.summary()
history = autoencoder.fit(Xtrain, Xtrain,batch_size=BATCH_SIZE,
epochs=NUM_EPOCHS)
我还需要做些额外的事情吗(如果没有),为什么我无法使它正常工作?
请让我知道我将解释的不清楚的部分。
谢谢你的帮助:)