【发布时间】:2021-06-14 12:48:32
【问题描述】:
我正在使用编码器/解码器模式编写德语->英语翻译器,其中编码器通过传递其最后一个 LSTM 层的状态输出连接到解码器 作为解码器的 LSTM 的输入状态。
不过,我被困住了,因为我不知道如何解释编码器 LSTM 的输出。一个小例子:
tensor = tf.random.normal( shape = [ 2, 2, 2 ])
lstm = tf.keras.layers.LSTM(units=4, return_sequences=True, return_state=True )
result = lstm( ( tensor )
print( "result:\n", result )
在 TensorFlow 2.0.0 中执行此操作会产生:
result:
[
<tf.Tensor: id=6423, shape=(2, 2, 3), dtype=float32, numpy=
array([[[ 0.05060377, -0.00500009, -0.10052835],
[ 0.01804499, 0.0022153 , 0.01820258]],
[[ 0.00813384, -0.08705016, 0.06510869],
[-0.00241707, -0.05084776, 0.08321179]]], dtype=float32)>,
<tf.Tensor: id=6410, shape=(2, 3), dtype=float32, numpy=
array([[ 0.01804499, 0.0022153 , 0.01820258],
[-0.00241707, -0.05084776, 0.08321179]], dtype=float32)>,
<tf.Tensor: id=6407, shape=(2, 3), dtype=float32, numpy=
array([[ 0.04316794, 0.00382055, 0.04829971],
[-0.00499733, -0.10105743, 0.1755833 ]], dtype=float32)>
]
结果是三个张量的列表。第一个似乎是所有的输出
return_sequences=True 选择的隐藏状态。我的问题是:第二个和第三个张量在result的解释是什么?
【问题讨论】:
标签: python tensorflow lstm