首页 > 解决方案 > 如何从 CNN 文本分类中获取预测标签?

问题描述

我是 CNN 文本分类的新手。我想将文本分类为两个标签之一。

0 = tidak mengidap

1 = 孟吉达普

我的模型只返回 0,不管是什么顺序。

lstm_out = 150

model = Sequential()
model.add(embedding_layer)
model.add(Conv1D(filters=64, kernel_size=5, activation='relu', padding='causal'))
model.add(MaxPooling1D(pool_size=2))
model.add(Dropout(0.7))
model.add(LSTM(units=lstm_out))
model.add(Dropout(0.7))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])


X_sample = tokenizer.texts_to_sequences(df['stemmed'])
X_sample = pad_sequences(X_sample, maxlen=maxlentweet)
y_sample = model.predict(X_sample).flatten().tolist()
result = np.argmax(y_sample)

print(result)

标签: pythonmachine-learningneural-networkconv-neural-networktext-classification

解决方案


推荐阅读