Keras之LSTM源码阅读笔记

本文是博主阅读Keras中LSTM源码的笔记,探讨了Recurrent接口的`implementation`和`weights`,LSTM接口的`recurrent_activation`,以及`kernel`与`recurrent_kernel`的区别。还分析了激活函数的使用,并猜测了代码执行顺序,重点在于理解LSTM在GPU上的优化实现。
摘要由CSDN通过智能技术生成

这里目前为止只是博主阅读Keras中LSTM源码的草稿笔记,内容不全,没有清晰的逻辑,只是堆砌个人想法。


参考文献:
1. keras的官方相关文档
2. LSTM原论文
3. keras的RNN源码

1. 接口研究

1.1. Recurrent接口

Recurrent是LSTM的父类(实际是通过SimpleRNN间接继承),定义所有RNNs的统一接口。

1.1.1. implementation:

implementation: one of {0, 1, or 2}.
If set to 0, the RNN will use an implementation that uses fewer, larger matrix products, thus running faster on CPU but consuming more memory. If set to 1, the RNN will use more matrix products, but smaller ones, thus running slower (may actually be faster on GPU) while consuming less memory. If set to 2 (LSTM/GRU only), the RNN will combine the input gate, the forget gate and the output gate into a single matrix, enabling more time-efficient parallelization on the GPU. Note: RNN dropout must be shared for all gates, resulting in a slightly reduced regularization.
博主主要使用GPU加速且不在意内存的代码,所以通常设置implementation=2,源码阅读也主要集中在implementation=2的部分。

1.1.2. weights:

weights: list of Numpy arrays to set as initial weights.
The list should have 3 elements, of shapes: [(input_dim, output_dim), (output_dim, output_dim), (output_dim,)]`.

1.2. LSTM接口

1.2.1. recurrent_activation

Activation function to use for the recurrent step.
注意: 默认值是’hard_sigmoid’,而原论文中用的’sigmoid’(关于hard_sigmoid 和sigmiod的比较请参考

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值