【发布时间】:2021-07-12 16:05:12
【问题描述】:
如何在具有形状 [5,30] 的每个标签的数据集上进行训练。例如:
[
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 55, 21, 56, 57, 3,
22, 19, 58, 6, 59, 4, 60, 1, 61, 62, 23, 63, 23, 64],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 65, 7, 66, 2, 67, 68, 3, 69, 70],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 11, 12, 5, 13, 14, 9, 10, 5, 15, 16, 17, 2, 8],
[ 0, 0, 0, 0, 0, 2, 71, 1, 72, 73, 74, 7, 75, 76, 77, 3,
20, 78, 18, 79, 1, 21, 80, 81, 3, 82, 83, 84, 6, 85],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2,
86, 87, 3, 88, 89, 1, 90, 91, 22, 92, 93, 4, 6, 94]
]
一种方法是将标签重塑为 [150],但这会使 标记化的句子失去意义。请建议我如何安排 keras 层 以及哪些层能够制作模型?我希望以后能够生成句子。
我现在的模型代码是这样的。
model = tf.keras.Sequential([ feature_layer,
layers.Dense(128, activation='relu'),
layers.Dense(128, activation='relu'),
layers.Dropout(.1),
layers.Dense(5),
layers.Dense(30, activation='softmax'), ])
opt = Adam(learning_rate=0.01)
model.compile(optimizer=opt, loss='mean_absolute_percentage_error', metrics=['accuracy'])
实际数据。
| state | district | month | rainfall | max_temp | min_temp | max_rh | min_rh | wind_speed | advice |
|---|---|---|---|---|---|---|---|---|---|
| Orissa | Kendrapada | february | 0.0 | 34.6 | 19.4 | 88.2 | 29.6 | 12.0 | chances of foot rot disease in paddy crop; apply urea at 3 weeks after transplanting at active tillering stage for paddy;...... |
| Jharkhand | Saraikela Kharsawan | february | 0 | 35.2 | 16.6 | 29.4 | 11.2 | 3.6 | provide straw mulch and go for intercultural operations to avoid moisture losses from soil; chance of leaf blight disease in potato crop; ....... |
我需要能够生成建议。
【问题讨论】:
-
我觉得还是加一些代码方便调试比较好,有没有准备好代码?
-
但是根据您对目标输出的评论,您可以为目标输出创建一个简单的密集层,如 tf.keras.layers.Dense(30, activation='softmax')
-
返回此错误。不兼容的形状:[10,5,30] 与 [10,30]
-
我现在已经在我的问题中添加了代码。
-
你能指定一些信息,比如你的输入是什么样的吗?使用原始格式的示例输入和目标
标签: tensorflow machine-learning keras nlp keras-layer