2017-04-01 38 views
0

我試圖建立以下結構: 曲面嵌入 - >前LSTM - >向後LSTM - >的毗連決賽美國 - >的毗連外部嵌入 - > LSTMCNTK提供最終LSTM狀態輸入到另一個LSTM

我的代碼如下所示:

i = Input(features) 
e = Embedding(25)(i) 

# Forward and backward LSTM 
h_f = Recurrence(LSTM(25), go_backwards=False)(e) 
h_b = Recurrence(LSTM(25), go_backwards=True)(e) 

# Get the final states and splice 
f = sequence.last(h_f) 
b = sequence.first(h_b) 
e1 = splice(f, b) 

# Get the other embedding and concat 
i2 = Input(100) 
e2 = Embedding(100)(i2) 
e2 = sequence.first(word_embedding) 
e3 = splice(e1, e2) 

# Input concatenated embedding to new LSTM 
r = Recurrence(LSTM(50))(e3) 

當我這樣做,我得到以下錯誤: 輸入操作數 '輸出(' Block1994_Output_0' ,[#],[50])」與#dynamic軸= 2( 1個順序軸和1個批處理軸)不受支持。

如果我沒有得到我的第一個雙向LSTM的最終狀態,那麼它工作正常,但那不是我想要的。

我也可以用這個簡單的例子重現該錯誤:

i = Input(features) 
e = Embedding(25)(i) 
h_f = Fold(LSTM(25), go_backwards=False)(e) 
s = Recurrence(LSTM(25))(h_f) 
+0

你能否確認你的目標是創建一個序列到序列模型?我問,因爲那些通常把他們自己的輸出作爲延遲輸入。如果這是你想要的,那麼請查看UnfoldFrom()。 –

+0

應該你的第一個e2 = ...是word_embedding = ...? –

+0

我不是在訓練一個seq2seq模型。我正在嘗試使用LSTM從角色學習矢量表示。將其與預先訓練的詞嵌入連接,然後將該連接的向量輸入到另一個LSTM,然後輸入密集層。是的,你對第一個e2是正確的,但這不是問題的原因。正如你可以從我的第二個例子看到的,我試圖弄清楚的是爲什麼我不能將一個LSTM的最終狀態作爲另一個LSTM的輸入。 – KyleW

回答

0

檢查this link有關返回的LSTM的輸出序列和狀態。然後,您可以將輸出綁定到另一個圖層的輸入。