2018-summer-DL-training-program / Lab-2-Image-Captioning

Image Captioning
1 stars 1 forks source link

DLY_LSTM中hx的定義 #5

Open hsintinl opened 6 years ago

hsintinl commented 6 years ago

助教您好, 想請問DLY_LSTM中hx的定義和使用 請問hx是指上一 "t" 時LSTM cell計算完的 ht 和 Ct 嗎? 如果答案是Yes, 可是看model.py裡, 呼叫self.lstm, 只有傳packed過的embedding, 並沒有傳ht, Ct 如果答案是No, 那第一筆ht, Ct要怎麼處理? 第二筆以後的ht, Ct回傳是要設計在LSTM cell裡面嗎? 有點亂問, 請見諒.

a514514772 commented 6 years ago

@hsintinl ,

根據pytroch的LSTM document與source code,input的hx代表(hidden_state, cell state)。當有給值時,則以input的值為主,如果沒有的話h_0跟c_0則以zero vector initial即可(你也可嘗試其他方法)。

回到你的問題,hx確實是ht與ct的tuple。當沒給的時候你要自己initialize。第二個timestep以後的h_t, c_t既要留存在LSTM中(你還要算第三個timestep,第四個...等),也要output出去(h1, (h1, c1))。

順帶一提,在我們這個case裡,只有一層LSTM(縱向,同個timestep來看),output會等於hidden state,但在其他的case裡不一定。如果層數超過1,output只需回傳最後一層LSTM的hidden。

但在這次作業可以從簡就好(同架構圖),(h1, (h1, c1)),這個就是output size。更多細節請見LSTM document,也歡迎你再提出來討論。

TA