关于lstm输出维度
Created by: fengchun1213
init_h1 = fluid.layers.fill_constant([num_layers*2, batch_size, hidden_size], 'float32', 0.0)
init_c1 = fluid.layers.fill_constant([num_layers*2, batch_size, hidden_size], 'float32', 0.0)
print("bi-lstm1 input shape", input.shape)
output1, last_h1, last_c1 = fluid.layers.lstm(input=input, init_h=init_h1, init_c=init_c1,
max_len=max_len, hidden_size=hidden_size, num_layers=num_layers,
is_bidirec=True)
print("bi-lstm1 output shape", output1.shape)
output1 = fluid.layers.transpose(output1, [1, 0, 2]) # B T C
output1 = fluid.layers.fc(output1, self.hidden_size, num_flatten_dims=2)
output1 = fluid.layers.transpose(output1, [1, 0, 2]) # T B C
init_h2 = fluid.layers.fill_constant([num_layers*2, batch_size, hidden_size], 'float32', 0.0)
init_c2 = fluid.layers.fill_constant([num_layers*2, batch_size, hidden_size], 'float32', 0.0)
print("bi-lstm2 input shape", output1.shape)
output2, last_h2, last_c2 = fluid.layers.lstm(input=output1, init_h=init_h2, init_c=init_c2,
max_len=max_len, hidden_size=hidden_size, num_layers=num_layers,
is_bidirec=True)
print("bi-lstm2 output shape", output2.shape)
输出: bi-lstm1 input shape (26, -1, 512) bi-lstm1 output shape (26, -1, 512) bi-lstm2 input shape (26, -1, 444) bi-lstm2 output shape (26, -1, 444) 我发现lstm的输出是和输入维度一样的,hidden_size没有影响,是我代码写的有问题吗?