如何选择LSTM中的隐藏层数和存储单元数?我想建立关于分类的LSTM模型。
from tensorflow.keras import Sequential
model = Sequential()
model.add(Embedding(44000,32))
model.add(LSTM(32))
model.add(Dense(1, activation='sigmoid'))发布于 2022-09-01 17:34:31
可以通过向嵌入层传递input_length参数来设置内存单元的数量,因为它是由输入序列的长度定义的。这是可选的,在提供培训数据时可以推断。
只需添加更多的LSTM层,就可以增加隐藏的LSTM层数。但是,您需要设置return_sequences=True来维护中间层的时间维度,即,
model = Sequential()
model.add(Embedding(44000,32)) # 32-dim encoding is pretty small
model.add(LSTM(32), return_sequences=True)
model.add(LSTM(32))
model.add(Dense(1, activation='sigmoid'))给出两个LSTM层。
在Tensorflow 文档中使用RNN进行文本分类有一个相当全面的指南。
https://stackoverflow.com/questions/73572812
复制相似问题