python - 如何为句子级嵌入设置 LSTM 的输入形状
问题描述
我正在使用带有句子级嵌入的 LSTM。我有评论文本,我将评论的最大长度句子设置为 58,并将评论中的每个句子转换为 1024 维度的嵌入。转换评论中的所有句子后,我得到每个评论的 58*1024=59392 维数组。我的数据包括 1430 条评论。
数据的形状是 X.shape (1430,59392) Y.shape (1430,)
这是我的 LSTM 模型
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.2,random_state=42)
x_train=x_train.reshape(x_train.shape[0],58,1024)
x_test=x_test.reshape(x_test.shape[0],58,1024)
model = Sequential()
model.add(LSTM(32, input_shape=(58, 1024)))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5, batch_size=32)
y_pred= model.predict_classes(x_test)
f1= f1_score(y_test, y_pred)
但是,计算 f1_score ValueError 时出现错误:分类指标无法处理二进制和未知目标的混合
当我检查我的 y_pred.shape 它是 (286,58,1) 和我的 y_test.shape (268,1)
有人可以帮忙吗?
解决方案
推荐阅读
- reactjs - 从反应选择下拉列表中删除或隐藏选项
- c++ - 如何使用cmake编译用dpdk用C和C++编写的项目
- sql - 如何安全地删除/删除表?
- jquery - 是否可以通过样式表或 JavaScript 明确设置元素的高度?
- javascript - VueJs 如何从 api 调用或 html 文件加载 html?
- r - 如何使用 cat 函数输出符合约束的元素?
- time-complexity - 如何计算这些排列组合算法的时间复杂度?
- c# - 更新模型排序顺序
- visual-studio-code - 自动保存,但仅适用于 vscode 中的特定文件
- c# - 立即发送通过 SerialPort (USB VCP) 接收到的以下字节