问题描述
我已经检查了两个函数的源代码,似乎LSTM()总体上构成了LSTM网络,而LSTMCell()仅返回一个单元格.
I've checked the source code for both functions, and it seems that LSTM() makes the LSTM network in general, while LSTMCell() only returns one cell.
但是,在大多数情况下,人们在程序中仅使用一个LSTM单元.这是否意味着当您只有一个LSTM Cell(例如简单的Seq2Seq)时,调用LSTMCell()和LSTM()不会有什么区别?
However, in most cases people only use one LSTM Cell in their program. Does this mean when you have only one LSTM Cell (ex. in simple Seq2Seq), calling LSTMCell() and LSTM() would make no difference?
推荐答案
-
LSTM
是循环图层 -
LSTMCell
是LSTM层使用的对象(也恰好也是一个层),其中包含一个步骤的计算逻辑. LSTM
is a recurrent layerLSTMCell
is an object (which happens to be a layer too) used by the LSTM layer that contains the calculation logic for one step.
循环图层包含一个单元格对象.该单元包含用于每个步骤的计算的核心代码,而循环层命令该单元并执行实际的循环计算.
A recurrent layer contains a cell object. The cell contains the core code for the calculations of each step, while the recurrent layer commands the cell and performs the actual recurrent calculations.
通常,人们在代码中使用LSTM
层.
或者他们使用包含LSTMCell
的RNN
层.
Usually, people use LSTM
layers in their code.
Or they use RNN
layers containing LSTMCell
.
两者几乎相同. LSTM
层是使用LSTMCell
的RNN
层,您可以在源代码.
Both things are almost the same. An LSTM
layer is a RNN
layer using an LSTMCell
, as you can check out in the source code.
关于单元格的数量:
Alghout,由于其名称,看来LSTMCell
是单个单元格,实际上它是一个对象,它可以管理我们可能认为的所有单元/单元格.在提到的同一代码中,您可以看到在创建LSTMCell
的实例时使用了units
参数.
Alghout it seems, because of its name, that LSTMCell
is a single cell, it is actually an object that manages all the units/cells as we may think. In the same code mentioned, you can see that the units
argument is used when creating an instance of LSTMCell
.
这篇关于LSTM()和LSTMCell()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!