多维数组作为Keras中嵌入层和LSTM的输入得到嵌入层中尺寸的误差

时间:2020-02-12 12:14:17

标签: python tensorflow multidimensional-array keras

我有一个形状为(1000,3,162)的多维数组 X_train

    [[[    0     0     0 ...     0     0     0]
      [    0     0     0 ...     0     0     0]
      [22175     0     0 ...     0     0     0]]

      [[    0     0     0 ...     0     0     0]
       [22175     0     0 ...     0     0     0]
       [37363 39010     0 ...     0     0     0]]

     [[22175     0     0 ...     0     0     0]
      [37363 39010     0 ...     0     0     0]
      [31559 42695     0 ...     0     0     0]]

       ...

    [[20651 31559 43650 ...     0     0     0]
     [20651 12733 40329 ...     0     0     0]
     [31559 15394 31559 ...     0     0     0]]]

我的模型如下:

      main_input = Input(shape=(162,)) # only pass in the indexes
      emb = Embedding(input_dim=3, output_dim = 162)(main_input)
      doc_output = Bidirectional(LSTM(64, return_sequences=False))(emb)
      doc_output = Dense(units=43, activation='softmax')(doc_output)
      model = Model(inputs=main_input, outputs=doc_output)
      model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
      print(model.summary())
      history=model.fit(X_train,y_train,epochs=1,batch_size=128,validation_data=(X_test, y_test))

我收到此错误

检查输入时出错:预期input_7具有2维,但数组的形状为(1000,3,162)

模型摘要在这里

enter image description here

当训练和测试数据为3维时,如何添加此输入数组以将其输入到嵌入层中?

0 个答案:

没有答案