【问题标题】:Map series of vectors to single vector using LSTM in Keras在 Keras 中使用 LSTM 将一系列向量映射到单个向量
【发布时间】:2017-10-04 04:12:59
【问题描述】:

假设我有一个随时间变化的特征向量,并希望将其映射到单个向量以用作分类中的一个层。这将如何在 Keras 中实现?示例:

Input:  <1.0, 2.0, 3.0>  ->  <1.1, 1.9, 3.2>  ->  ...
Output: <1.0, 0.0, 0.0, 2.0>

Keras 文档说 LSTM 对象具有 3 个维度,但我不确定在这种情况下如何表达。

【问题讨论】:

    标签: machine-learning neural-network deep-learning keras lstm


    【解决方案1】:

    LSTM 在[batch_size, time_steps, input_dim] 中接受输入。在您的情况下,您可以将每个向量视为一个时间步长。因此,输入两个时间步长将是:

    [<1.0, 2.0, 3,0>, <1.1, 1.0, 3.2>] which maps to <1.0, 0.0, 0.0, 2.0>
    

    举个例子:

    input_dim = 3
    num_steps = 2
    
    model = Sequential()
    model.add(LSTM(16, input_shape=(num_steps, input_dim)) # output 2d [batch_size, 16]
    model.add(Dense(4)) # output [batch, 4]
    
    # ... more layers
    

    不要害怕阅读他们做得很好的文档。 https://keras.io/layers/recurrent/#lstm

    【讨论】:

    • 我很难理解 LSTM 的......在这个例子中 LSTM 层的输出形状是什么?
    • input_shape=(num_stems, input_dim),它总是期望num_steps 时间步长,对吧?我知道这是必要的,因为我们为了训练目的将 RNN/LSTM “展开”为固定大小。但是,当您想要输入更多(或更少)时间步长,但仍期望输出形状相同时,训练后会发生什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    相关资源
    最近更新 更多