RuntimeError: для непакетного двумерного ввода hx также должен быть двумерным, но имеет трехмерный тензор.
I have defined a GRU model for a prediction task. But I am getting this error. here is the code of GRU model.
класс GRU_Model(nn.Module): определение инициализации(self, input_dim, hidden_dim, layer_dim, output_dim):super(GRU_Model, self).инициализация()
# Defining the number of layers and the nodes in each layer
self.layer_dim = layer_dim
self.hidden_dim = hidden_dim
# GRU layers
self.gru = nn.GRU(
input_dim, hidden_dim, layer_dim, batch_first=True)
# Fully connected layer
self.fc = nn.Linear(hidden_dim, output_dim)
def forward(self, x):
# Initializing hidden state for first input with zeros
h0 = torch.zeros(self.layer_dim, 1, self.hidden_dim).requires_grad_().cpu()
# Forward propagation by passing in the input and hidden state into the model
out, _ = self.gru(x, h0)
# Reshaping the outputs in the shape of (batch_size, seq_length, hidden_size)
# so that it can fit into the fully connected layer
out = out[:, -1, :]
# Convert the final state to our desired output shape (batch_size, output_dim)
out = self.fc(out)
return out`
Я попытался запустить модель ГРУ на некоторых обработанных данных. Если бы модель работала идеально, я бы увидел, как идут эпохи. ``