【问题标题】:Unable to understand the output shapes in LSTM network below无法理解下面 LSTM 网络中的输出形状
【发布时间】:2020-09-14 01:26:54
【问题描述】:

我一直在尝试使用 TensorFlow v2 keras 训练双向 LSTM 进行文本分类。下面是架构:

  model1 = Sequential()
  model1.add(Embedding(vocab, 128,input_length=maxlength))

  model1.add(Bidirectional(LSTM(32,dropout=0.2,recurrent_dropout=0.2,return_sequences=True)))
  model1.add(Bidirectional(LSTM(16,dropout=0.2,recurrent_dropout=0.2,return_sequences=True)))
  model1.add(GlobalAveragePooling1D())
  model1.add(Dense(5, activation='softmax'))
  model1.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

  model1.summary()

现在,我感到困惑的是摘要细节

我的疑惑与 BiLSTM 层的输出形状有关。尽管 2 层使用的单元数分别为 32 和 16,但它们是 (283,64) 和 (283,32)。这里,maxlength=283,vocab=19479

【问题讨论】:

    标签: python tensorflow keras neural-network nlp


    【解决方案1】:

    这是因为Bidirectional。如果删除它,您会看到输出形状为 (283,32) & (283,16)Bidirectional 创建了某种额外的层

    【讨论】:

      【解决方案2】:

      我相信这个结果的解释是您添加到神经网络的 LSTM 层的双向性质:您添加的层的大小加倍,以便该层也向后学习序列。希望大家能理解,有什么问题可以在cmets问我。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-10-15
        • 1970-01-01
        • 2021-12-28
        • 2021-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多