乐趣区

关于人工智能:MindSpore易点通精讲系列网络构建之LSTM算子下篇

Dive Into MindSpore–Lstm Operator For Network Construction
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子

MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–上篇
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–中篇
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–下篇

本文开发环境

MindSpore 1.7.0
本文内容提要

原理介绍
文档阐明
案例讲解
本文总结
本文参考

  1. 案例讲解
    3.3 双层双向 LSTM
    本示例中随机生成了 [4, 8, 4] 数据,该数据 batch_size 为 4,固定 seq_length 为 8,输出维度为 4。

本示例采纳双层双向 LSTM,隐层大小为 8。

本示例中 LSTM 调用时进行比照测试,一个 seq_length 为默认值 None,一个为无效长度 input_seq_length。

示例代码如下:

import numpy as np

from mindspore import dtype
from mindspore import Tensor
from mindspore.nn import LSTM

def double_layer_bi_lstm():

random_data = np.random.rand(4, 8, 4)
seq_length = [3, 8, 5, 1]
input_seq_data = Tensor(random_data, dtype=dtype.float32)
input_seq_length = Tensor(seq_length, dtype=dtype.int32)

batch_size = 4
input_size = 4
hidden_size = 8
num_layers = 2
bidirectional = True
num_bi = 2 if bidirectional else 1

lstm = LSTM(
    input_size=input_size, hidden_size=hidden_size, num_layers=num_layers,
    has_bias=True, batch_first=True, dropout=0.0, bidirectional=bidirectional)

h0 = Tensor(np.ones([num_bi * num_layers, batch_size, hidden_size]).astype(np.float32))
c0 = Tensor(np.ones([num_bi * num_layers, batch_size, hidden_size]).astype(np.float32))

output_0, (hn_0, cn_0) = lstm(input_seq_data, (h0, c0))
output_1, (hn_1, cn_1) = lstm(input_seq_data, (h0, c0), input_seq_length)

print("====== double layer bi lstm output 0 shape: {} ======\n{}".format(output_0.shape, output_0), flush=True)
print("====== double layer bi lstm hn0 shape: {} ======\n{}".format(hn_0.shape, hn_0), flush=True)
print("====== double layer bi lstm cn0 shape: {} ======\n{}".format(cn_0.shape, cn_0), flush=True)

print("====== double layer bi lstm output 1 shape: {} ======\n{}".format(output_1.shape, output_1), flush=True)
print("====== double layer bi lstm hn1 shape: {} ======\n{}".format(hn_1.shape, hn_1), flush=True)
print("====== double layer bi lstm cn1 shape: {} ======\n{}".format(cn_1.shape, cn_1), flush=True)

示例代码输入内容如下:

对输入内容进行剖析:

output_0 和 output_1 维度都是 [4, 8, 16],即 batch_size, seq_length 和 hidden_size * 2,这里乘 2 是因为是双向输入。
output_0 和 output_1 皆是第二层(最初一层)的输入,中间层(本例为第一层)输入没有显示给出。
output_0 对应的是调用时 seq_length 为 None 的状况,即默认无效 seq_length 为 8,能够看到 output_0 各个长度输入数值皆非全零。
output_1 对应的是调用时 seq_length 为设定值[3, 8, 5, 1],能够看到 output_1 超过无效长度的输入局部皆为全零。
hn 和 cn 别离为隐层状态和细胞状态输入。上面以 hn_1 和 cn_1 为例进行解说。
hn_1 维度为[4, 4, 8],4 代表双向双层(2*2),4 代表 batch_size,8 代表 hidden_size。
6 中阐明 4 代表双向双层(2*2),hn_1 蕴含各层的最终无效隐层状态输入,这里同 output_1 只蕴含最初一层的输入不同。
仔细观察能够看出,hn_1 中第一维度第 2 索引地位(即最初一层)的正向输入局部与 output_1 最初一维输入前 hidden_size 数值统一,即与无效长度内最初一个的输入的前 hidden_size 数值保持一致。
仔细观察能够看出,hn_1 中第一维度第 3 索引地位(即最初一层)的反向输入局部与 output_1 开始一维输入后 hidden_size 数值统一。
cn_1 为无效最初一步的细胞状态。
====== double layer bi lstm output 0 shape: (4, 8, 16) ======
[[[3.70550364e-01 2.17652053e-01 3.79816592e-01 5.39002419e-01

2.28588611e-01  3.83301824e-02  2.20795229e-01  2.44438455e-01
2.06572518e-01 -3.78293954e-02  2.60271341e-01 -4.60247397e-02

-3.78369205e-02 -1.90976545e-01 -1.01466656e-01 1.76680252e-01]






[-8.48584175e-02 -4.15292941e-02 4.26153004e-01 -1.12198450e-01

2.93441713e-01  4.73045520e-02  7.22456872e-02 -1.52661309e-01
6.08003795e-01  1.02589525e-01  2.28410736e-01  3.57809156e-01
2.30974391e-01  7.29562640e-02  1.54908523e-01  1.37615114e-01]]

[[3.73128176e-01 2.24487275e-01 3.83654892e-01 5.39644539e-01

2.24863932e-01  3.69703583e-02  2.22563371e-01  2.47377262e-01
2.09958509e-01 -3.67934220e-02  2.55294740e-01 -5.44558465e-02

-3.49954516e-02 -1.88630879e-01 -9.97974724e-02 1.72440261e-01]






[-9.71160829e-02 -4.43801992e-02 4.20233607e-01 -1.02356419e-01

3.03063601e-01  3.99401113e-02  8.28935355e-02 -1.43912748e-01
6.09543681e-01  1.04935512e-01  2.27933496e-01  3.57850134e-01
2.31336534e-01  7.57181123e-02  1.55172557e-01  1.39436752e-01]]

[[3.74232024e-01 2.23312378e-01 3.80826175e-01 5.25748074e-01

2.30494052e-01  3.75359394e-02  2.19325155e-01  2.45338157e-01
1.90327644e-01 -9.49237868e-03  2.51282185e-01 -4.07305919e-02

-7.68693071e-03 -1.96041882e-01 -9.43402052e-02 1.52500823e-01]






[-1.07369550e-01 -7.64680207e-02 4.24612671e-01 -8.88631567e-02

3.25147092e-01  5.22605665e-02  7.02133700e-02 -1.30118832e-01
6.03053808e-01  1.08490229e-01  2.35621274e-01  3.42306137e-01
2.33348757e-01  7.23976195e-02  1.51835442e-01  1.38724014e-01]]

[[3.68833274e-01 2.19720796e-01 3.75712991e-01 5.39344609e-01

2.32777387e-01  3.75517495e-02  2.15990663e-01  2.38119900e-01
2.03846872e-01 -3.31601547e-03  2.63746709e-01 -5.33154309e-02

-1.53900171e-02 -1.96350247e-01 -9.86721516e-02 1.51238605e-01]






[-9.11041871e-02 -4.77942340e-02 4.29545075e-01 -1.14117011e-01

3.04611683e-01  5.14086746e-02  7.33837485e-02 -1.44734517e-01
6.06585741e-01  9.89784896e-02  2.24559098e-01  3.55441421e-01
2.28052005e-01  7.30600879e-02  1.55306384e-01  1.37683451e-01]]]

====== double layer bi lstm hn0 shape: (4, 4, 8) ======
[[[0.25934413 -0.07461581 0.19370164 0.11095355 0.02041678

0.29797387  0.03047622  0.19640712]

[0.2874061 -0.08844143 0.22119689 0.1251989 -0.01900517

0.29294112  0.05027778  0.2071664 ]

[0.2596095 0.03271259 0.26155 0.10348854 0.08536521

0.28197888 -0.08929807  0.18018515]

[0.2509837 -0.07010224 0.20813467 0.10349585 0.04007874

0.27277622  0.01278557  0.18474495]]



[[0.20657252 -0.0378294 0.26027134 -0.04602474 -0.03783692
-0.19097655 -0.10146666 0.17668025]
[0.20995851 -0.03679342 0.25529474 -0.05445585 -0.03499545
-0.18863088 -0.09979747 0.17244026]
[0.19032764 -0.00949238 0.2512822 -0.04073059 -0.00768693
-0.19604188 -0.09434021 0.15250082]
[0.20384687 -0.00331602 0.2637467 -0.05331543 -0.01539002
-0.19635025 -0.09867215 0.1512386 ]]]
====== double layer bi lstm cn0 shape: (4, 4, 8) ======
[[[0.5770398 -0.16899881 0.40028483 0.25001454 0.04046626

0.57915956  0.05266067  0.52447474]

[0.66343445 -0.19959925 0.49729916 0.27566156 -0.03596141

0.5509572   0.0853648   0.5394346 ]

[0.5707181 0.07038814 0.5712474 0.2565448 0.1530705

0.57276523 -0.15605333  0.46282846]

[0.55990976 -0.16366895 0.4313923 0.23668876 0.08243398

0.53433377  0.02196771  0.4817235 ]]



[[0.32853472 -0.05710489 0.7447654 -0.0758819 -0.09938034
-0.47783113 -0.28168824 0.36019933]
[0.33408064 -0.05591211 0.7391405 -0.08961775 -0.0917803
-0.47115833 -0.278066 0.35383248]
[0.30187273 -0.01431822 0.7146605 -0.06792408 -0.02012375
-0.48834586 -0.26035625 0.3151392 ]
[0.32118577 -0.00497683 0.7502155 -0.08775105 -0.04013083
-0.4903597 -0.27541417 0.30617815]]]
====== double layer bi lstm output 1 shape: (4, 8, 16) ======
[[[3.5416836e-01 2.0936093e-01 3.8317284e-01 5.3357160e-01

2.4053907e-01  4.1459590e-02  2.0509864e-01  2.5311515e-01
3.7313861e-01  2.2726113e-02  2.4815443e-01  1.6349553e-01
1.1913014e-02 -1.0416587e-01 -4.6682160e-02  1.2466244e-01]

[1.6695338e-01 8.1573747e-02 5.0642765e-01 2.2585270e-01

3.1199178e-01  7.0200888e-03  1.0298288e-01  7.1754217e-02
4.2964008e-01  2.7423983e-02  2.2389892e-01  2.8188041e-01
9.3678713e-02 -1.6824452e-02  4.4604652e-02  1.2561245e-01]

[6.0777575e-02 3.0208385e-02 5.1636058e-01 8.0109224e-02

3.0168548e-01  1.5010678e-02  5.8312915e-02 -2.7518146e-02
6.2040079e-01  1.1676422e-01  2.4167898e-01  3.6679846e-01
2.2570200e-01  6.9053181e-02  1.5332413e-01  1.3909420e-01]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]]

[[3.7312818e-01 2.2448727e-01 3.8365489e-01 5.3964454e-01

2.2486390e-01  3.6970358e-02  2.2256340e-01  2.4737728e-01
2.0995849e-01 -3.6793407e-02  2.5529474e-01 -5.4455854e-02

-3.4995444e-02 -1.8863088e-01 -9.9797480e-02 1.7244026e-01]
[1.6344458e-01 7.4762136e-02 4.9512634e-01 2.4983825e-01

2.9844120e-01 -2.2964491e-02  1.3046446e-01  4.6507578e-02
1.8774964e-01 -5.6968573e-02  2.3092678e-01 -1.8975141e-02

-6.5767197e-03 -1.6430146e-01 -7.7841796e-02 1.7092024e-01]
[2.6236186e-02 -2.0902762e-02 4.8132658e-01 1.5410189e-01

2.9595733e-01 -3.7644185e-02  1.1366512e-01 -5.5398405e-02
1.9633688e-01 -6.9955371e-02  2.1327947e-01  2.0917373e-02

-6.9075003e-03 -1.4227399e-01 -7.3977120e-02 1.7023006e-01]
[-4.5504406e-02 -8.8195749e-02 4.4950521e-01 8.3784960e-02

3.1254938e-01 -3.0976830e-02  9.6947111e-02 -9.9365219e-02
2.0704943e-01 -6.6500187e-02  1.9992988e-01  4.6051688e-02
9.1559850e-03 -1.2333421e-01 -6.3600369e-02  1.5821570e-01]

[-8.5413747e-02 -9.5996402e-02 4.2882851e-01 2.8101865e-02

3.1274763e-01 -1.9659458e-02  1.0424862e-01 -1.2168537e-01
2.4435315e-01 -6.9591425e-02  1.8749590e-01  1.2333996e-01
1.2001552e-02 -9.1948770e-02 -5.3056102e-02  1.5285012e-01]

[-1.0321245e-01 -9.7408667e-02 4.1026697e-01 -2.0338718e-02

3.2013306e-01  5.4713513e-04  1.0752757e-01 -1.2621583e-01
3.0542794e-01 -5.2220318e-02  1.8903156e-01  2.1638034e-01
4.2735931e-02 -5.3110521e-02 -2.5012573e-02  1.4485820e-01]

[-1.0691784e-01 -7.1392961e-02 4.1062483e-01 -5.5148609e-02

3.0711043e-01  1.9290760e-02  1.0387863e-01 -1.3866244e-01
4.0088418e-01 -1.4360026e-02  1.8252462e-01  2.9758602e-01
9.5214583e-02  9.5995963e-03  5.3094927e-02  1.3763560e-01]

[-9.7116083e-02 -4.4380195e-02 4.2023361e-01 -1.0235640e-01

3.0306363e-01  3.9940134e-02  8.2893521e-02 -1.4391276e-01
6.0954368e-01  1.0493548e-01  2.2793353e-01  3.5785013e-01
2.3133652e-01  7.5718097e-02  1.5517256e-01  1.3943677e-01]]

[[3.6901441e-01 2.1822800e-01 3.7994039e-01 5.2547783e-01

2.3396042e-01  3.9366722e-02  2.1538821e-01  2.4702020e-01
2.4914475e-01 -6.9778422e-03  2.4806115e-01  2.1838229e-02

-1.3991867e-02 -1.6620368e-01 -8.7110944e-02 1.4123847e-01]
[1.6616049e-01 8.4187903e-02 4.9948204e-01 2.2646046e-01

3.0369779e-01 -1.7643329e-02  1.2668489e-01  4.9117617e-02
2.6261702e-01 -2.7619595e-02  2.2540939e-01  1.1914852e-01
2.3004401e-02 -1.2194993e-01 -5.5561494e-02  1.3998528e-01]

[4.2908981e-02 -2.5578242e-02 4.8486653e-01 1.1890158e-01

3.1149039e-01 -1.4618633e-02  9.1249026e-02 -3.3213440e-02
3.1701097e-01 -1.8276740e-02  2.2031868e-01  2.0087981e-01
5.8553118e-02 -7.3650509e-02 -1.7827954e-02  1.3095699e-01]

[-2.2401063e-02 -6.7246288e-02 4.6379456e-01 4.6429519e-02

3.1024706e-01  1.2560772e-02  7.6885723e-02 -7.1739145e-02
4.0658230e-01  1.3608186e-02  2.1248461e-01  2.7639762e-01
1.0969905e-01 -1.7181308e-03  5.7507429e-02  1.2614906e-01]

[-4.9086079e-02 -6.1570432e-02 4.6209678e-01 -3.5342608e-02

3.1426692e-01  4.2432975e-02  5.4815758e-02 -9.5721334e-02
6.0554379e-01  1.1493160e-01  2.4293001e-01  3.4404746e-01
2.3283333e-01  6.8980336e-02  1.5239350e-01  1.3767722e-01]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]]

[[3.3036014e-01 2.2069807e-01 4.0932164e-01 5.0686938e-01

2.5304586e-01  4.5349576e-02  1.6947377e-01  2.6356062e-01
6.4686131e-01  1.8447271e-01  2.6571944e-01  3.6628011e-01
2.0576611e-01  5.9034787e-02  1.3657802e-01  1.4004102e-01]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]

[0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00

0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00
0.0000000e+00  0.0000000e+00  0.0000000e+00  0.0000000e+00]]]

====== double layer bi lstm hn1 shape: (4, 4, 8) ======
[[[0.30786592 -0.05702875 0.2098356 0.1831936 0.1446731

0.35495615  0.10906219  0.2584008 ]

[0.28740606 -0.08844142 0.2211969 0.12519889 -0.01900517

0.29294112  0.05027781  0.2071664 ]

[0.25389883 0.05431987 0.24731106 0.1163514 0.12489295

0.31806058 -0.07178076  0.20686159]

[0.47720045 0.11175225 0.22376464 0.36412558 0.46750376

0.28765967  0.38535532  0.33306697]]

[[0.0012262 0.3199089 -0.02733669 0.17044675 -0.04726706
-0.02164171 0.28464028 0.3348536 ]
[0.05813042 0.14894389 0.05397653 0.15691833 -0.16107246
-0.06869183 0.27977887 0.26698047]
[-0.04329334 0.12033389 0.03753637 0.15189895 -0.11344916
-0.04964198 0.27086687 0.28215134]
[0.05921583 0.543903 0.00194274 0.27610534 0.16461822

0.25555757  0.18277422  0.3662175 ]]

[[0.06077757 0.03020838 0.5163606 0.08010922 0.30168548

0.01501068  0.05831292 -0.02751815]

[-0.09711608 -0.0443802 0.4202336 -0.1023564 0.30306363

0.03994013  0.08289352 -0.14391276]

[-0.04908608 -0.06157043 0.46209678 -0.03534261 0.31426692

0.04243298  0.05481576 -0.09572133]

[0.33036014 0.22069807 0.40932164 0.5068694 0.25304586

0.04534958  0.16947377  0.26356062]]

[[0.3731386 0.02272611 0.24815443 0.16349553 0.01191301
-0.10416587 -0.04668216 0.12466244]
[0.2099585 -0.03679341 0.25529474 -0.05445585 -0.03499544
-0.18863088 -0.09979748 0.17244026]
[0.24914475 -0.00697784 0.24806115 0.02183823 -0.01399187
-0.16620368 -0.08711094 0.14123847]
[0.6468613 0.18447271 0.26571944 0.3662801 0.20576611

0.05903479  0.13657802  0.14004102]]]

====== double layer bi lstm cn1 shape: (4, 4, 8) ======
[[[0.7061355 -0.13162777 0.46092123 0.4033497 0.2930356

0.76054144  0.18314546  0.70929015]

[0.6634344 -0.19959924 0.4972992 0.27566153 -0.0359614

0.5509572   0.08536483  0.5394347 ]

[0.5526391 0.1161246 0.5316373 0.28497726 0.22511882

0.67451394 -0.12430747  0.5528798 ]

[1.0954192 0.29093137 0.8067771 0.8504353 0.7032547

0.97427243  0.5589305   0.8662672 ]]

[[0.00324558 0.6688721 -0.05317001 0.32999027 -0.07784042
-0.05728557 0.58330244 0.8111321 ]
[0.16052541 0.31375027 0.1059354 0.28533533 -0.26115924
-0.20904504 0.5899867 0.56931025]
[-0.11802054 0.26023 0.07224996 0.31177503 -0.19568688
-0.12562011 0.6177163 0.6840635 ]
[0.16791074 1.2188046 0.00349617 0.670789 0.2591958

0.46886685  0.5807996   0.86447406]]

[[0.16193499 0.06143508 1.1399425 0.13840833 0.69956493

0.04888431  0.1235408  -0.0485969 ]

[-0.28950468 -0.0866928 0.7886544 -0.17458248 0.6081316

0.12001929  0.17698729 -0.27595744]

[-0.13397661 -0.12149224 0.9074148 -0.06176313 0.6541451

0.12807912  0.1181712  -0.17463374]

[0.8489872 0.6016479 1.3853014 0.8196937 1.020999

0.24127276  0.45320526  0.4759813 ]]

[[0.6076499 0.03351691 0.812855 0.27901018 0.02922555
-0.26106828 -0.12472634 0.24901994]
[0.3340806 -0.05591209 0.7391405 -0.08961776 -0.09178029
-0.47115833 -0.27806604 0.35383248]
[0.3964765 -0.01050393 0.7366462 0.03638346 -0.03574796
-0.41335842 -0.23882627 0.28892466]
[1.0575086 0.23200202 0.8150203 0.7750988 0.42505968

0.24064866  0.46888143  0.26767123]]]

本文总结
本文简略介绍了 LSTM 的基本原理,而后联合 MindSpore 中文档阐明,通过案例讲解具体介绍参数设定和输入输出状况,让读者更好的了解 MindSpore 中的 LSTM 算子。

本文参考
LSTM 基本原理
simplified-deeplearning/LSTM
LSTM API
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–上篇
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–中篇
MindSpore 易点通·精讲系列–网络构建之 LSTM 算子–下篇

本文为原创文章,版权归作者所有,未经受权不得转载!

退出移动版