我已经使用lstm form 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'
有可能做到这一点吗?请帮帮我..。
发布于 2020-02-17 22:46:12
错误的预测与模型训练相关,但是您可以通过对predict
结果使用argmax()
方法来获得唯一的结果(如此处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)
请注意,在这里它将预测您的示例中的失望。
https://stackoverflow.com/questions/60270057
复制相似问题