多输出双向ISTM的问题

时间:2019-07-16 17:19:26

标签: python keras lstm

我是编程多输出分类以进行文本分类的新手,但是当我尝试编译模型时,出现了一些错误:

  

检查模型目标时出错:传递给模型的Numpy数组列表不是模型期望的大小。预计会看到4个数组,但得到了以下1个数组的列表:

我应该如何解决这个问题,我的模型有错误吗?

我试图修复标签和数据预处理,但错误仍然发生。

我有4个标签(LA,LB,LC,LD)

x_train张量的形状:(201, 525)

标签示例: [array([[1.],[4.],[4.],[4.],[4.],[2.]]), array([[2.],[3.]......)....]

def LSTMmodel(hiddenlayer = 64, drop = 0.5):
    #Input
    sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')

    ########################################################################
    embedded_sequences = embedding_layer(sequence_input)
    print (embedded_sequences)
    dropout = Dropout(drop)(embedded_sequences)

    #########################################################################


    y1 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(dropout)
    y1 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y1)
    y1 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y1)
    y1 = Bidirectional(LSTM(hiddenlayer))(y1)
    y1 = Dropout(drop)(y1)

    y2 =  Bidirectional(LSTM(hiddenlayer, return_sequences=True))(dropout)
    y2 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y2)
    y2 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y2)
    y2 = Bidirectional(LSTM(hiddenlayer))(y2)
    y2 = Dropout(drop)(y2)

    y3 =  Bidirectional(LSTM(hiddenlayer, return_sequences=True))(dropout)
    y3 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y3)
    y3 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y3)
    y3 = Bidirectional(LSTM(hiddenlayer))(y3)
    y3 = Dropout(drop)(y3)

    y4 =  Bidirectional(LSTM(hiddenlayer, return_sequences=True))(dropout)
    y4 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y4)
    y4 = Bidirectional(LSTM(hiddenlayer, return_sequences=True))(y4)
    y4 = Bidirectional(LSTM(hiddenlayer))(y4)
    y4 = Dropout(drop)(y4)

    y1 = Dense(LA_nodes, activation='softmax',name= 'LA')(y1)
    y2 = Dense(LB_nodes, activation='softmax',name= 'LB')(y2)
    y3 = Dense(LC_nodes, activation='softmax',name= 'LC')(y3)
    y4 = Dense(LD_nodes, activation='softmax',name= 'LD')(y4)




    model = Model(sequence_input,outputs =[y1,y2,y3,y4])
    model.summary()


    model.compile(loss='categorical_crossentropy',
                  optimizer=SGD(lr=0.01,momentum=0.9),
                  metrics=['accuracy'])


    checkloss = create_checkpoint('LSTM') 
    checkacc = create_checkpoint2('LSTM')


    print('Training...')
    history = model.fit(x_train, y_trainn_new,
              batch_size=batch_size,
              epochs=max_epochs,
              validation_data=x_test,
              shuffle=True,
              #callbacks=[checkloss, checkacc, early_stopping])
    return model, history

我希望没有值错误,但仍然存在

0 个答案:

没有答案