首页 > 解决方案 > 如何提高深度学习 LSTM 算法中模型的准确性?

问题描述

我正在尝试通过“LSTM 多对一”模型预测“新闻”数据。我用过keras。我应该在模型中进行哪些更改以提高准确性?

当前精度为:55%

标签数量为:68

数据维度:

  train_seq_x (16254, 499)
  encoded_train_y (16254, 68)
  test_seq_x (1807, 499)
  test_y (1807,)

型号定义:

def train_model(classifier, feature_vector_train, label, feature_vector_valid, is_neural_net):

     classifier.fit(feature_vector_train, label,epochs=10,batch_size=32,validation_split=0.05,shuffle=False)

     #predict the labels on validation dataset
     predictions = classifier.predict(feature_vector_valid)

     if is_neural_net:
        predictions = predictions.argmax(axis=-1)

     return metrics.accuracy_score(predictions, test_y)

def create_rnn_lstm():
    input_layer = layers.Input((train_seq_x.shape[1], ))

    embedding_layer = layers.Embedding(len(word_index) + 1, 300, weights=[embedding_matrix], trainable=False)(input_layer)

    lstm_layer1 = layers.LSTM(128)(embedding_layer)

    output_layer2 = layers.Dense(68, activation="softmax")(lstm_layer1)

    model = models.Model(inputs=input_layer, outputs=output_layer2)
    model.compile(optimizer=optimizers.Adam(), loss='categorical_crossentropy',metrics=['accuracy'])

    return model

classifier = create_rnn_lstm()
classifier.summary()
accuracy = train_model(classifier, train_seq_x, encoded_train_y, test_seq_x, is_neural_net=True)
print "LSTM, Word Embeddings",  accuracy

标签: machine-learningdeep-learningartificial-intelligencelstmdata-science

解决方案


推荐阅读