我正在建立一个神经网络模型来将情感分配给短语。我的问题是,无论我对模型进行什么更改,准确性得分始终相同。
我尝试添加或删除图层,更改批处理大小,更改时期数,更改激活器等。
tokenizer = Tokenizer()
total_phrases = phrases_train.append([phrases_valid, phrases_test],
ignore_index = True)
tokenizer.fit_on_texts(total_phrases)
maxlen = max([len(s.split()) for s in total_phrases])
vocab_size = len(tokenizer.word_index) + 1
phrases_train_tokens = tokenizer.texts_to_sequences(phrases_train)
phrases_valid_tokens = tokenizer.texts_to_sequences(phrases_valid)
phrases_test_tokens = tokenizer.texts_to_sequences(phrases_test)
pad_phrases_train = pad_sequences(phrases_train_tokens, maxlen=maxlen,
padding='post')
pad_phrases_valid = pad_sequences(phrases_valid_tokens, maxlen=maxlen,
padding='post')
pad_phrases_test = pad_sequences(phrases_valid_tokens, maxlen=maxlen,
padding='post')
model = Sequential()
model.add(Embedding(vocab_size, 100, input_length=maxlen))
model.add(Dense(50, kernel_initializer='truncated_normal',
activation='relu'))
model.add(GRU(units=32, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(1, activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=
['accuracy'])
model.fit(pad_phrases_train, sents_train, batch_size=250, epochs=50,
validation_data=(pad_phrases_valid, sents_valid), verbose=2)
model.evaluate(pad_phrases_test, sents_test)
评估始终准确显示0.2057分。我想达到50%左右的精度