簡體   English   中英

我想用 LSTM 為我自己創建的數據集實現 GRU。 由於我是 python 的新手,我不確定如何添加 GRU 層。 如何添加GRU?

[英]I would like to implement GRU with LSTM for my own created dataset. Since i am new to python, i am not sure how to add GRU layer. How to add GRU?

當 model 使用 LSTM 執行時,我得到 model_wrapper。 但是 GRU 不起作用。

GRU和LSTM如何執行?

    #BUILD THE MODEL
        
        top_words = 10000
        embedding_vecor_length = 32
        model = Sequential()
        model.add(Embedding(top_words, embedding_vecor_length, input_length=X.shape[1]))
        model.add(Dropout(0.2))
        model.add(LSTM(100,dropout=0.2, recurrent_dropout=0.2, go_backwards=False))
        #model.add(Dropout(0.2))
        model.add(Dense(1, activation='sigmoid'))
        model.add(Dense(1, activation='sigmoid'))
        model.compile(loss='binary_crossentropy', optimizer='Adam', metrics=['accuracy'])
        print(model.summary())
        model.summary()

如何在上面的代碼中添加 GRU 和 LSTM?

這是添加 GRU 的正確參數嗎?

在此處輸入圖像描述

在此處輸入圖像描述

在此處輸入圖像描述

根據我的閱讀,您似乎想添加 GRU 而不是 LSTM。 您可以像使用 LSTM 一樣添加 GRU 層

from tensorflow.keras.layers import GRU
model.add(GRU(100,dropout=0.2, recurrent_dropout=0.2))

如果你想要 LSTM 和 GRU 在一起(這實際上取決於你在做什么以及為什么要這樣做),你需要先從 GRU 返回序列

from tensorflow.keras.layers import GRU
model.add(GRU(100,dropout=0.2, recurrent_dropout=0.2, return_sequences=True))
model.add(LSTM(100,dropout=0.2, recurrent_dropout=0.2))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM