简体   繁体   English

LSTM 模型中未定义 Dropout_U 和 Dropout_W

[英]Dropout_U and Dropout_W is not defined in LSTM model

I am facing this error我正面临这个错误

NameError: name 'Dropout_U' is not defined

by creating an LSTM model通过创建 LSTM 模型

embed_dim = 128
lstm_out = 200
batch_size = 32

model = Sequential()
model.add(Embedding(2500, embed_dim,input_length = X.shape[1]))
model.add(Dropout(0.2))
model.add(LSTM(lstm_out))
model.add(Dropout_U(0.2))
model.add(Dropout_W(0.2))
model.add(Dense(2,activation='sigmoid'))
model.compile(loss = 'categorical_crossentropy', optimizer='adam',metrics = ['accuracy'])
print(model.summary())

Can you help me overcome this problem?你能帮我克服这个问题吗?

The syntax used is outdated, Dropout_U has been changed to recurrent_dropout .使用的语法已经过时, Dropout_U已更改为recurrent_dropout Dropout_W is simply Dropout . Dropout_W就是Dropout

If you replace Dropout_U with recurrent_dropout and make it part of your LSTM layer it should work.如果您要更换Dropout_Urecurrent_dropout ,使你LSTM层的一部分它应该工作。 Simply change the Dropout_W layer to Dropout .只需将Dropout_W层更改为Dropout

embed_dim = 128
lstm_out = 200
batch_size = 32

model = Sequential()
model.add(Embedding(2500, embed_dim,input_length = X.shape[1]))
model.add(Dropout(0.2))
model.add(LSTM(lstm_out, recurrent_dropout=0.2))
model.add(Dropout(0.2))
model.add(Dense(2,activation='sigmoid'))
model.compile(loss = 'categorical_crossentropy', optimizer='adam',metrics = ['accuracy'])
print(model.summary())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM