Python 进行预测时,每行的输出相同。因此,我的预测是错误的

Python 进行预测时,每行的输出相同。因此,我的预测是错误的,python,pandas,dataframe,lstm,Python,Pandas,Dataframe,Lstm,我已经使用lstm方法实现了情绪分析,我已经在代码的第一部分训练了我的模型,现在我正在做预测部分。当我运行系统时,所有行的结果都是相同的,这是不正确的。有人能告诉我我的错误以及我需要做什么才能做出正确的预测吗?求你了 我已实施了以下措施: #Re-create the model to get attention vectors as well as label predictions model_with_attentions = keras.Model(inputs=model.inpu

我已经使用lstm方法实现了情绪分析,我已经在代码的第一部分训练了我的模型,现在我正在做预测部分。当我运行系统时,所有行的结果都是相同的,这是不正确的。有人能告诉我我的错误以及我需要做什么才能做出正确的预测吗?求你了

我已实施了以下措施:


#Re-create the model to get attention vectors as well as label predictions

model_with_attentions = keras.Model(inputs=model.input,
                                    output=[model.output,
                                              model.get_layer('attention_vec').output])


import json

with open(r"C:\Users\User\Desktop\Coding\parsehubjsonfileeg\22 results.json", encoding="utf8") as f:
    data = json.load(f)
df = pd.DataFrame(data['selection1'][0]['CommentID'])

a=df['comment']
print(a)
dtt = pd.DataFrame(a, columns=['comment'])
print(dtt)
import nltk
result=[]
for sentence in dtt["comment"]:

    # Encode samples
    tokenize = dtt.apply(lambda row: nltk.word_tokenize(row['comment']), axis=1)
    #encoded_samples =[[word2id[word] for sentence in dtt["comment"]]]
    encoded_samples = [[word2id[word] for sentence in tokenize]]

    # 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])}
    result.append(label_probs)

dtt["Result"] = result
print(dtt)

我得到了我的输出:

                                               comment                                             Result
0                                enjoy a lovely moment  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
1    I was there for my honeymoon. The hotel was si...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
2    Had an amazing stay for 2 nights.\nThe cleanli...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
3                       Had a good time. Food is good.  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
4    A highly recommendable hotel. Value for money ...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
..                                                 ...                                                ...
131  Wonderful experience, a quite different experi...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
132                               Was a paradise stay.  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
133  It was really a place to be for relaxing provi...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
134  It was just perfect with an excellent service!...  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...
135                                 It's was excellent  {'joy': 0.2003046, 'happy': 0.20040178, 'disap...

[136 rows x 2 columns]

Process finished with exit code 0

谁能帮帮我吗。请

代码太多了,你能把范围缩小到a吗?你好,我已经删除了经过训练的部分。现在好了吗?