通过 json 文件输入 LSTM 形状

LSTM input shape through json file

我正在研究 LSTM,在对数据进行预处理之后,我得到了列表形式的数据 X,其中包含 3 个特征列表,每个列表包含 50 个点的列表形式的序列.

X = [list:100 [list:3 [list:50]]]
Y = [list:100]

由于它是一个多变量 LSTM,我不确定如何将所有 3 个序列作为 Keras-Lstm 的输入。我需要在 Pandas 数据框中转换它吗?

model = models.Sequential()    
model.add(layers.Bidirectional(layers.LSTM(units=32,
                                               input_shape=(?,?,?)))

LSTM 调用参数 Doc:

inputs: A 3D tensor with shape [batch, timesteps, feature].

您必须将该列表转换为 numpy 数组才能与 Keras 一起使用。

根据您提供的 X 形状,理论上它应该可以工作。但是,您必须弄清楚数组的 3 个维度实际包含什么。

  • 第一个维度应该是您的batch_size,即您有多少批数据。

  • 第 2 个维度是您的时间步长数据。

Ex: words in a sentence, "cat sat on dog" -> 'cat' is timestep 1, 'sat' is timestep 2 and 'on' is timestep 3 and so on.

  • 第 3 维表示每个时间步的数据特征。对于我们前面的句子,我们可以向量化每个单词

您可以执行以下操作将列表转换为 NumPy 数组:

X = np.array(X)
Y = np.array(Y)

在此转换后调用以下内容:

print(X.shape)
print(Y.shape)

应该分别输出:(100, 3, 50) 和 (100,)。最后LSTM层的input_shape可以是(None, 50).