Python 使用计数矢量器时,神经网络无法正确预测

Python 使用计数矢量器时,神经网络无法正确预测,python,tensorflow,machine-learning,tflearn,countvectorizer,Python,Tensorflow,Machine Learning,Tflearn,Countvectorizer,我试图利用文本和IMDB随机评论的分数进行情绪分析预测。我把所有的单词都变成了一袋单词,然后全部放进了一个神经网络。然而,这个预测似乎并不正确,它总是显示出50%的正面预测和50%的负面预测 reviews = pd.read_csv('reviews.txt', header=None) labels = pd.read_csv('labels.txt', header=None) Y = (labels=='positive').astype(np.int_) print(type(rev

我试图利用文本和IMDB随机评论的分数进行情绪分析预测。我把所有的单词都变成了一袋单词,然后全部放进了一个神经网络。然而,这个预测似乎并不正确,它总是显示出50%的正面预测和50%的负面预测

reviews = pd.read_csv('reviews.txt', header=None)
labels = pd.read_csv('labels.txt', header=None)
Y = (labels=='positive').astype(np.int_)

print(type(reviews))
print(reviews.head())
print(labels.head())

无论我如何调整超参数,训练、验证和测试的准确度始终最大为~0.65

my_review = "This movie sucks"
my_review_enc = fitter.transform([my_review])
my_review_enc_pad = pad_sequences(my_review_enc.toarray(), maxlen=100, value=0.)
prediction = model.predict(my_review_enc_pad)
prediction

正如你所看到的,积极和消极的预测总是在50%

我做错了什么

X_train = pad_sequences(X_train.toarray(), maxlen=100, value=0.)
X_test = pad_sequences(X_test.toarray(), maxlen=100, value=0.)
X_val = pad_sequences(X_val.toarray(), maxlen=100, value=0.)
Y_train = to_categorical(y_train, 2)
Y_test = to_categorical(y_test, 2)
Y_val = to_categorical(y_val, 2)


tensorflow.reset_default_graph()

input_layer = tflearn.input_data(shape=[None, 100])
net = tflearn.embedding(input_layer, input_dim=10000, output_dim=128)
hid = tflearn.fully_connected(input_layer, 10, activation='tanh') # a hidden layer with 10 neurons
output_layer = tflearn.fully_connected(hid, 2, activation='softmax')

sgd = tflearn.SGD(learning_rate=0.04, lr_decay=0.96, decay_step=1000)
net = tflearn.regression(output_layer, optimizer=sgd, loss='categorical_crossentropy')


model = tflearn.DNN(net, tensorboard_verbose=3, tensorboard_dir='tfdir')
try:
    model.fit(X_train, Y_train, n_epoch=5, validation_set=(X_val, Y_val), batch_size=100, show_metric=True, run_id="Imdb")
except KeyboardInterrupt as e:
    print("Stopped by user")
my_review = "This movie sucks"
my_review_enc = fitter.transform([my_review])
my_review_enc_pad = pad_sequences(my_review_enc.toarray(), maxlen=100, value=0.)
prediction = model.predict(my_review_enc_pad)
prediction