I’m trying to perform convolution on the output of LSTM in pytorch for text classification, while implementing, I discovered I needed to clone the output of the lstm to perform convolution on it as shown below:
# lstm representation
output, (final_hidden_state, final_cell_state) = self.lstm(embedded, (h_0, c_0))
#clone the output gotten from lstm
conInput=output.clone()
#unsqueeze the output in dim = 1
conInput = conInput.transpose_(0, 1).unsqueeze(1)
#peform convolution on the processed output of lstm
conved_0 = F.relu(self.conv_0(conInput).squeeze(3))
conved_1 = F.relu(self.conv_1(conInput).squeeze(3))
conved_2 = F.relu(self.conv_2(conInput).squeeze(3))
Am I doing the right thing? Is there a better approach?