使用AttentionDecoder时发生错误

时间:2018-12-04 05:57:56

标签: python lstm sentiment-analysis text-classification attention-model

我正在使用AttentionDecoder中提供的AttentionDecoder对Sentiment140数据进行文本分类。我的训练数据的维度为(1280000, 50)。我首先按照传统的输入形状(12800, 50, 100)模式将数据集重塑为(batch_size, time_steps, input_dim)。我使用Keras构建的模型如下:

def get_bi_lstm_with_attention_model(pad_length, dim):
    input_shape = (pad_length, dim)
    input = Input(shape=input_shape, dtype='float32')
    enc = Bidirectional(LSTM(100, dropout=0.2, recurrent_dropout=0.2, return_sequences=True),
    merge_mode='concat', name='bidirectional_1')(input)
    y_hat = AttentionDecoder(units=32,output_dim=1, name='attention_decoder_1')(enc)
    bilstm_attention_model = Model(inputs=input, outputs=y_hat)
    bilstm_attention_model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    return bilstm_attention_model

设置pad_length=50dim=100之后,我想使用创建的模型来拟合数据:

bilstm_model_with_attention.fit(sentiment_sequence_for_train_attention, labels_for_train, validation_split=0.25, epochs=3, batch_size=128)

然后我遇到以下错误:

ValueError: Error when checking target: expected attention_decoder_1 to have 3 dimensions, but got array with shape (1280000, 1)

因此我很困惑!我知道输入尺寸一定有问题。有人可以提供一些提示吗?

0 个答案:

没有答案