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 数据得到的输出
  • 相关阅读:
    Linux:PS命令详解与使用
    linux日志守护进程 syslog
    Linux shell 判断字符串为空等常用命令
    Java 中zookeeper操作
    mysql数据库读写分离,主从同步实现方法
    【转】几种Java序列化方式的实现
    如何为SUSE配置IP地址,网关和DNS
    linux中export的作用
    91家纺网,多线程版本待处理
    91家纺网爬虫,不包含多线程登录处理,第三张表格数据没有对接
  • 原文地址:https://www.cnblogs.com/xingnie/p/12420820.html
Copyright © 2011-2022 走看看