zoukankan      html  css  js  c++  java
  • LSTM层的return_sequences和return_state的理解


    return_sequences:默认 False。在输出序列中,返回单个 hidden state值还是返回全部time step 的 hidden state值。 False 返回单个, true 返回全部。
    return_state:默认 False。是否返回除输出之外的最后一个状态。

    区别 cell state 和 hidden state

    LSTM 的网络结构中,直接根据当前 input 数据,得到的输出称为 hidden state。
    还有一种数据是不仅仅依赖于当前输入数据,而是一种伴随整个网络过程中用来记忆,遗忘,选择并最终影响 hidden state 结果的东西,称为 cell state。

    cell state 就是实现 long short memory 的关键

    cell state 是不输出的,它仅对输出 hidden state 产生影响。

    通常情况,我们不需要访问 cell state,除非想设计复杂的网络结构时。例如在设计 encoder-decoder 模型时,我们可能需要对 cell state 的初始值进行设定。

    第一层必须加上“return_sequences=True”

    1.return_sequences=False && return_state=False

    h = LSTM(6)
    此时返回的对输入数据进行计算得到的a,如果X有多个timestep,则返回最后一个timestep的a

    2.return_sequences=True && return_state=False 

    LSTM(6, return_sequences=True)
    此时返回的是全部timestep的a

    3.return_sequences=False && return_state=True

    lstm1, state_h, state_c = LSTM(6, return_state=True)
    lstm1, state_h是最后一个timestep的a,state_c是最后一个timestep的c 

    4.return_sequences=True && return_state=True

    lstm1, state_h, state_c = LSTM(6, return_sequences=True, return_state=True)
    lstm1是全部timestep的a,

    state_h是最后一个timestep的a,

    state_c是最后一个timestep的c 

    对于GRU基本也是这样的思路

    总结:

    • 第一层必须加上“return_sequences=True”
    • 默认 False
    • cell state 是不输出的,它仅对输出 hidden state 产生影响。
    • hidden state直接根据当前 input 数据得到的输出
  • 相关阅读:
    在springboot程序中自定义注解和反序列化实现
    文章相似度算法调研
    HTTP协议详解
    prototype.js 让你更深入的了解javascript的面向对象特性(转)
    ajax框架汇总
    prototype源码分析(转)
    c#中静态成员和实例成员(转)
    .NET中IDisposable接口的基本使用 (转)
    sql server 数据库优化(转)
    ADO.NET事物
  • 原文地址:https://www.cnblogs.com/xingnie/p/12420820.html
Copyright © 2011-2022 走看看