《How to Reshape Input Data for Long Short-Term Memory Networks in Keras》学习笔记

跟随大神Jason Brownlee, Ph.D学习Deep Learning.《How to Reshape Input Data for Long Short-Term Memory Networks in Keras》原文地址点击打开链接


Tips for LSTM Input:

  • The LSTM input layer must be 3D.
  • The meaning of the 3 input dimensions are: samples, time steps, and features.
  • The LSTM input layer is defined by the input_shape argument on the first hidden layer.
  • The input_shape argument takes a tuple of two values that define the number of time steps and features.
  • The number of samples is assumed to be 1 or more.
  • The reshape() function on NumPy arrays can be used to reshape your 1D or 2D data to be 3D.
  • The reshape() function takes a tuple as an argument that defines the new shape.


问:训练和测试序列的不同样本的长度可能不同,怎么处理?

答:"A way I use often is to pad all sequences to the same length and use a masking layer on the front end to ignore masked time steps."Mask layer supports masking for input data with a variable number of time steps. To introduce masks to your data, use an Embedding layer with the mask_zero parameter set to True."

Mask示例:

model = Sequential()

model.add(Masking(mask_value=0., input_shape=(timesteps, features)))

model.add(LSTM(32))


问:Embedding layer怎么支持变长time steps?


You could also use a model that does not specify the input length, for example:
https://machinelearningmastery.com/develop-encoder-decoder-model-sequence-sequence-prediction-keras/



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值