train_window = 24
def create_sequences(input_data, length_of_sequence):
sequence = []
L = len(input_data)
for i in range(L-length_of_sequence):
train_seq = input_data[i:i+length_of_sequence]
train_label = input_data[i+length_of_sequence:i+length_of_sequence+1]
sequence.append((train_seq, train_label))
return sequence
class LSTM(nn.Module):
def init(self, input_size=1, hidden_layer_size=40, output_size=1):
super().init()
self.hidden_layer_size = hidden_layer_size
self.lstm = nn.LSTM(input_size, hidden_layer_size)
self.relu = nn.ReLU()     

self.hidden_cell = (torch.zeros(1, 1, self.hidden_layer_size),    
                    torch.zeros(1, 1, self.hidden_layer_size))

def forward(self, input_seq):
lstm_out, self.hidden_cell = self.lstm(input_seq.view(len(input_seq), 1, -1), self.hidden_cell)
predictions = self.relu(lstm_out.view(len(input_seq), -1))
return predictions[-1]
model = LSTM()
loss_function = nn.MSELoss()
optimizer = torch.optim.Adam(model.parameters(), lr = 0.01)
epochs = 500
for i in range(epochs):
for seq, labels in train_inout_seq:
optimizer.zero_grad()
model.hidden_cell = (torch.zeros(1, 1, model.hidden_layer_size),
torch.zeros(1, 1, model.hidden_layer_size))
y_pred = model(seq)
single_loss = loss_function(y_pred, labels)
single_loss.backward()
optimizer.step()

if i%25 == 1:
print(f’epoch: {i:3} loss: {single_loss.item():10.8f}’)
print(f’epoch: {i:3} loss: {single_loss.item():10.10f}’)
and the result is coming loss is not decreasing any guidline?:
epoch:   1 loss: 0.72129285
epoch:  26 loss: 0.72129285