我正在研究只有0(负)和1(正)两个类别的评论分类模型。我正在使用来自LSTM的Google训练有素的word2vec。问题是我得到了大约50%的精度,而根据本文,它应该在83%左右。我尝试了许多不同的超参数组合,但仍然获得了惊人的准确性。我还尝试过更改数据预处理技术并尝试阻止,但并不能解决问题
这是我的代码
X,y = read_data()
X = np.array(clean_text(X)) #apply data preprocessing
tokenizer = Tokenizer()
tokenizer.fit_on_texts(X)
#converts text to sequence and add padding zeros
sequence = tokenizer.texts_to_sequences(X)
X_data = pad_sequences(sequence,maxlen = length,padding = 'post')
X_train,X_val,y_train,y_val = train_test_split(X_data,y,test_size = 0.2)
#Load the word2vec model
word2vec = KeyedVectors.load_word2vec_format(EMBEDDING_FILE,binary=True)
word_index = tokenizer.word_index
nb_words = min(MAX_NB_WORDS,len(word_index))+1
embedding_matrix = np.zeros((nb_words,EMBEDDING_DIM))
null_words = []
for word,i in word_index.items():
if word in word2vec.wv.vocab:
embedding_matrix[i] = word2vec.word_vec(word)
else:
null_words.append(word)
embedding_layer = Embedding(embedding_matrix.shape[0],# or len(word_index) + 1
embedding_matrix.shape[1],# or EMBEDDING_DIM,weights=[embedding_matrix],input_length=701,trainable=False)
model = Sequential()
model.add(embedding_layer)
model.add(LSTM(100))
model.add(Dropout(0.4))
model.add(Dense(2,activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
model.fit(X_train,batch_size=32,epochs=2,validation_data=(X_val,y_val),workers = -1,verbose=1)
score,acc = model.evaluate(X_val,y_val,batch_size=64)
我还尝试了其他优化器,例如AdaMax和MSLE损失函数,无论我增加多少时间或更改批处理大小,准确性都永远不会提高。如果问题不在于模型和预处理,我会很困惑。谢谢