alex_bn_lee

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

【483】Keras 中 LSTM 与 BiLSTM 语法

参考:Keras-递归层Recurrent官方说明

参考:Keras-Bidirectional包装器官方说明

LSTM(units=32, input_shape=(10, 64))

  • units=32:输出神经元个数
  • input_shape=(10, 64):输入数据形状,10 代表时间序列的长度,64 代表每个时间序列数据的维度

LSTM(units=32, input_dim=64, input_length=10)

  • units=32:输出神经元个数
  • input_dim=64:每个时间序列数据的维度
  • input_length=10:时间序列的长度

☀☀☀<< 举例 >>☀☀☀

1
2
3
4
5
6
7
8
9
10
11
12
# as the first layer in a Sequential model
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
# now model.output_shape == (None, 10, 32)
# note: `None` is the batch dimension.
 
# the following is identical:
model = Sequential()
model.add(LSTM(32, input_dim=64, input_length=10))
 
# for subsequent layers, not need to specify the input size:
model.add(LSTM(16))

  

  • return_sequences:布尔值,默认False,控制返回类型。若为True则返回整个序列,否则仅返回输出序列的最后一个输出

keras.layers.wrappers.Bidirectional(layer, merge_mode='concat', weights=None)

  双向RNN包装器 

  参数

  • layer:Recurrent对象
  • merge_mode:前向和后向RNN输出的结合方式,为sum,mul,concat,ave和None之一,若设为None,则返回值不结合,而是以列表的形式返回

☀☀☀<< 举例 >>☀☀☀

1
2
3
4
5
6
model = Sequential()
model.add(Bidirectional(LSTM(10, return_sequences=True), input_shape=(5, 10)))
model.add(Bidirectional(LSTM(10)))
model.add(Dense(5))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')

  

posted on   McDelfino  阅读(2771)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2019-09-24 【439】Tweets processing by Python
点击右上角即可分享
微信分享提示