python - 如何从 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)
解决方案
推荐阅读
- android - 无法使用分页刷新 recyclerView
- elasticsearch - 更改任何 NON-INDEXED 字段的映射时,是否需要强制重新索引所有旧文档?
- java - 为什么要覆盖父接口中的现有方法?
- linux - 如何指定“无端口”
- python-3.x - 如何在 dict 中传递 ForeignKey 以创建 Model 对象。姜戈
- c++ - 为什么我必须在 C++ 中添加一个赋值符号来声明一个数组?
- python - 使用 word2vec 列出所有包含特定单词和相似单词的句子
- javascript - React Material UI Range Slider 值句柄
- javascript - 如何在 reactjs 中将 paddingTop 添加到我的输入框中?
- latex - 如何将词汇表与语法结合起来?