前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >tensorflow lstm原理与代码从头构建

tensorflow lstm原理与代码从头构建

作者头像
羽翰尘
修改2019-11-26 16:50:53
4800
修改2019-11-26 16:50:53
举报
文章被收录于专栏:技术向技术向

本文由腾讯云+社区自动同步,原文地址 https://stackoverflow.club/article/construct_lstm_from_nothing/

tensorflow lstm原理与代码从头构建

简单的一层lstm

代码语言:txt
复制
# 使用 basic LSTM Cell.
lstm_cell = tf.contrib.rnn.BasicLSTMCell(n_hidden_units, forget_bias=1.0, state_is_tuple=True)
init_state = lstm_cell.zero_state(batch_size, dtype=tf.float32) # 初始化全零 state
# 如果使用tf.nn.dynamic_rnn(cell, inputs), 我们要确定 inputs 的格式. tf.nn.dynamic_rnn 中的 time_major 参数会针对不同 inputs 格式有不同的值.
# 如果 inputs 为 (batches, steps, inputs) ==> time_major=False;
# 如果 inputs 为 (steps, batches, inputs) ==> time_major=True;
outputs, final_state = tf.nn.dynamic_rnn(lstm_cell, X_in, initial_state=init_state, time_major=False)
outputs size: [batch_size, max_time, cell_state_size]
final_state[1] size: [batch_size, cell_state_size]

Reference

  1. 各种LSTM代码比较全 地址
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-06-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简单的一层lstm
  • Reference
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档