zydarChen / zydarChen.github.io

0 stars 0 forks source link

深入理解Keras LSTM的stateful | 沐雨浥尘 #6

Open zydarChen opened 5 years ago

zydarChen commented 5 years ago

https://www.zydarchen.top/20180925/21_stateful_LSTM/

Keras LSTM的stateful非常容易用错,前段时间研究了一下,记记笔记~如有错误,欢迎评论指出~

btwewek commented 5 years ago

Hi 您好 , 一點小疑惑, stateful為什麼訊息是在batch之間傳遞? 感覺將床前明月光&疑似地上霜擺在Batch[0]比較直觀, 比較像將訊息直接傳遞到下一句話的感覺, 不清楚為何要先將詩句打亂並依照要傳遞的方式排成多個batch

zydarChen commented 5 years ago

@btwewek Hi 您好 , 一點小疑惑, stateful為什麼訊息是在batch之間傳遞? 感覺將床前明月光&疑似地上霜擺在Batch[0]比較直觀, 比較像將訊息直接傳遞到下一句話的感覺, 不清楚為何要先將詩句打亂並依照要傳遞的方式排成多個batch

这是Keras规定的,具体实现可能得去阅读源码。

When using stateful RNNs, it is therefore assumed that:

  • all batches have the same number of samples
  • If x1 and x2 are successive batches of samples, then x2[i] is the follow-up sequence to x1[i], for every i.

个人理解是,我们需要将的state传递至,那必然有个先后计算的关系,如果这两句在一个Batch内,同一个Batch内的不同sample是同时计算的,这样就没办法进行state的传递了。(个人理解,欢迎讨论)

btwewek commented 5 years ago

@zydarChen

@btwewek Hi 您好 , 一點小疑惑, stateful為什麼訊息是在batch之間傳遞? 感覺將床前明月光&疑似地上霜擺在Batch[0]比較直觀, 比較像將訊息直接傳遞到下一句話的感覺, 不清楚為何要先將詩句打亂並依照要傳遞的方式排成多個batch

这是Keras规定的,具体实现可能得去阅读源码。

When using stateful RNNs, it is therefore assumed that:

  • all batches have the same number of samples
  • If x1 and x2 are successive batches of samples, then x2[i] is the follow-up sequence to x1[i], for every i.

个人理解是,我们需要将的state传递至,那必然有个先后计算的关系,如果这两句在一个Batch内,同一个Batch内的不同sample是同时计算的,这样就没办法进行state的传递了。(个人理解,欢迎讨论)

了解,我還只是初學,可能沒法給出太多理解,不過還是感謝這篇文章圖文解釋至少讓我學到不少!