简体   繁体   English

Keras中具有批量归一化的双向LSTM

[英]Bidirectional LSTM with Batch Normalization in Keras

I was wondering how to implement biLSTM with Batch Normalization (BN) in Keras. 我想知道如何在Keras中实现具有批量标准化(BN)的biLSTM。 I know that BN layer should be between linearity and nonlinearity, ie, activation. 我知道BN层应该在线性和非线性之间,即激活。 This is easy to implement with CNN or Dense layers. 使用CNN或Dense图层很容易实现。 But, how to do this with biLSTM? 但是,如何用biLSTM做到这一点?

Thanks in advance. 提前致谢。

If you want to apply BatchNormalization over the linear outputs of an LSTM you can do it as 如果要在LSTM的线性输出上应用BatchNormalization,可以将其作为

from keras.models import Sequential
from keras.layers.recurrent import LSTM
from keras.layers.wrappers import Bidirectional
from keras.layers.normalization import BatchNormalization

model = Sequential()
model.add(Bidirectional(LSTM(128, activation=None), input_shape=(256,10)))
model.add(BatchNormalization())

Essentially, you are removing the non-linear activations of the LSTM (but not the gate activations), and then applying BatchNormalization to the outpus. 基本上,您正在删除LSTM的非线性激活(但不是门激活),然后将BatchNormalization应用于outpus。

If what you want is to apply BatchNormalization into one of the inside flows of the LSTM, such as recurrent flows, I'm afraid that feature has not been implemented in Keras. 如果你想要的是将BatchNormalization应用到LSTM的一个内部流程中,例如循环流,我担心该功能尚未在Keras中实现。

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

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