将循环转换为双向循环

converting recurrent to bi recurrent

我想将下面的 RNN 转换为双向 RNN,我该怎么做?

#调用函数编译模型

模型 = RNN() model.summary() model.compile(loss='categorical_crossentropy',optimizer=RMSprop(),metrics=['accuracy']) model.fit(X_train,Y_train,batch_size=10,epochs=20, validation_split=0.1)


您可以使用 Bidirectional layer:

def RNN():
    inputs = Input(name='inputs',shape=[max_len])
    layer = Embedding(max_words, 100, input_length=max_len, 
                      weights=[embedding_matrix_vocab])(inputs)
    layer = Bidirectional(LSTM(64))(layer)
    layer = Dense(356,name='FC1')(layer)
    layer = Activation('relu')(layer)
    layer = Dense(356,name='FC2')(layer)
    layer = Activation('relu')(layer)
    layer = Dropout(0.5)(layer)
    layer = Dense(6,name='out_layer')(layer)
    layer = Activation('softmax')(layer)
    model = Model(inputs=inputs,outputs=layer)
    return model