Hi @ptrblck thank you for answering, after looking at the docs its possible thats the problem but it also specifies “If the LSTM is bidirectional, num_directions should be 2, else it should be 1.”. My end goal is to make it bidirectional but right now i am trying without it being bidirectional so num_directions should be 1 i don’t really get where this variable comes from or where it is being defined. Also i’m sorry about the code format i thought it would be easier with the picture so i’ll just put it all down so you can get the hole picture.
/////////////////////////////////////////////
import torch
from torch import nn
from torch.autograd import Variable
import pandas as pd
from sklearn.preprocessing import StandardScaler, MinMaxScaler
#loading data
training_data = pd.read_excel(r’rawDATA_2outputs.xlsx’)
test_data = pd.read_excel(r’test_2outputs.xlsx’)
#shuffle data
training = training_data.sample(frac=1)
test = test_data.sample(frac=1)
#data preprocessing
X = training_data.iloc[:, :-1]   #training data sem labels
y = training_data.iloc[:, 42:43] #labels da training_data
X_test = test_data.iloc[:, :-1]       #test_data sem labels
y_test = test_data.iloc[:, 42:43]     #labels da test_data
#scaling the data
mm = MinMaxScaler()
ss = StandardScaler()
X_ss = ss.fit_transform(X)
y_mm = mm.fit_transform(y)
X_test_ss = ss.fit_transform(X_test)
y_test_mm = ss.fit_transform(y_test)
#data as tensors
X_train_tensors = Variable(torch.Tensor(X_ss))
y_train_tensors = Variable(torch.Tensor(y_mm))
X_test_tensors = Variable(torch.Tensor(X_test_ss))
y_test_tensors = Variable(torch.Tensor(y_test_mm))
#reshape
X_train_tensors_final = torch.reshape(X_train_tensors,   (X_train_tensors.shape[0], 1, X_train_tensors.shape[1]))
X_test_tensors_final = torch.reshape(X_test_tensors,  (X_test_tensors.shape[0], 1, X_test_tensors.shape[1]))
#build the network
class LSTM1(nn.Module):
def init(self, num_classes, input_size, hidden_size, num_layers, seq_length):
super(LSTM1, self).init()
self.num_classes = num_classes  # number of classes
self.num_layers = num_layers  # number of layers
self.input_size = input_size  # input size
self.hidden_size = hidden_size  # hidden state
self.seq_length = seq_length  # sequence length
    self.lstm = nn.LSTM(input_size=input_size, hidden_size=hidden_size,
                        num_layers=num_layers, batch_first=True)  # lstm
    self.fc_1 = nn.Linear(hidden_size, 128)  # fully connected 1
    self.fc = nn.Linear(128, num_classes)  # fully connected last layer

    self.relu = nn.ReLU()

def forward(self, x):
    h_0 = Variable(torch.zeros(self.num_layers, x.size(0), self.hidden_size))  # hidden state
    c_0 = Variable(torch.zeros(self.num_layers, x.size(0), self.hidden_size))  # internal state
    # Propagate input through LSTM
    output, (hn, cn) = self.lstm(x, (h_0, c_0))  # lstm with input, hidden, and internal state
    hn = hn.view(-1, self.hidden_size)  # reshaping the data for Dense layer next
    out = self.relu(hn)
    out = self.fc_1(out)  # first Dense
    out = self.relu(out)  # relu
    out = self.fc(out)  # Final Output
    return out

#hyperparameters
num_epochs = 1
learning_rate = 0.001
input_size = 42      #number of features
hidden_size = 128 #number of features in hidden state
num_layers = 2     #number of stacked lstm layers
num_classes = 2  #number of output classes
#aplicar a network e definir criterio de erro e optimizador
lstm1 = LSTM1(num_classes, input_size, hidden_size, num_layers, X_train_tensors_final.shape[1])
criterion = torch.nn.MSELoss()
optimizer = torch.optim.Adam(lstm1.parameters(), lr=learning_rate)
#train
for epoch in range(num_epochs):
outputs = lstm1.forward(X_train_tensors_final)  # forward pass
optimizer.zero_grad()  # caluclate the gradient, manually setting to 0
# obtain the loss function
loss = criterion(outputs, y_train_tensors)

loss.backward()  # calculates the loss of the loss function

optimizer.step()  # improve from loss, i.e backprop
if epoch % 1 == 0:
    print("Epoch: %d, loss: %1.5f" % (epoch, loss.item())) 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I’ll also try to debug and see what happens, but anyway thank you for your time and help!