Ire*_* Li 6 deep-learning lstm tensorflow
我正在使用TensorFlow对时间序列数据进行预测.所以就像我有50个标签,我想找出下一个可能的5个标签.
我参加了教程演示:回归神经网络
但我发现它可以像上面图片中的第5张一样提供,这是不同的.
我想知道我可以使用哪种型号?我在考虑seq2seq模型,但不确定它是否是正确的方法.
你是对的,你可以使用seq2seq模型.为简洁起见,我写了一个例子,说明如何在Keras中实现它,它还有一个Tensorflow后端.我没有运行这个例子所以它可能需要调整.如果你的标签是一热的,你需要使用交叉熵损失.
from keras.models import Model
from keras.layers import Input, LSTM, RepeatVector
# The input shape is your sequence length and your token embedding size
inputs = Input(shape=(seq_len, embedding_size))
# Build a RNN encoder
encoder = LSTM(128, return_sequences=False)(inputs)
# Repeat the encoding for every input to the decoder
encoding_repeat = RepeatVector(5)(encoder)
# Pass your (5, 128) encoding to the decoder
decoder = LSTM(128, return_sequences=True)(encoding_repeat)
# Output each timestep into a fully connected layer
sequence_prediction = TimeDistributed(Dense(1, activation='linear'))(decoder)
model = Model(inputs, sequence_prediction)
model.compile('adam', 'mse') # Or categorical_crossentropy
model.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3942 次 |
| 最近记录: |