【问题标题】:using lstm to predict and have only one answer使用 lstm 预测并且只有一个答案
【发布时间】:2020-02-17 20:37:43
【问题描述】:

我已经使用 lstm 表单 https://www.kaggle.com/eray1yildiz/using-lstms-with-attention-for-emotion-recognition/comments 实现了情感分析

我的预测有误,结果列表如下所示:

['enjoy', 'lovely', 'moment']
{'joy': 0.18797465, 'satisfied': 0.19864388, 'happy': 0.18680806, 'sad': 0.20265724, 'disappointment': 0.22391614}

以下是我用于预测的部分代码:


      # Padding
      encoded_samples = keras.preprocessing.sequence.pad_sequences(encoded_samples, maxlen=max_words)

      # Make predictions
      label_probs, attentions = model_with_attentions.predict(encoded_samples)
      label_probs = {id2label[_id]: prob for (label, _id), prob in zip(label2id.items(), label_probs[0])}

我希望我的输出是这样的:

Input: ['enjoy', 'lovely', 'moment']
Output: 'joy'

可以这样做吗?请帮帮我..

【问题讨论】:

    标签: python pandas lstm probability


    【解决方案1】:

    错误的预测与模型训练相关联,但是您可以通过使用argmax() 方法对您的predict 结果(如此处https://github.com/keras-team/keras/issues/5910 所述)使用独特的结果。在不知道encoded_sample 的形状的情况下,我猜你需要这样的东西:

    label_probs = model_with_attentions.predict(encoded_samples)
    label_pred= label_probs.argmax(axis=-1)
    

    请注意,在这里它会预测您的示例会让人失望。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 2018-09-24
      相关资源
      最近更新 更多