This article here: https://machinelearningmastery.com/time-series-prediction-lstm-recurrent-neural-networks-python-keras/ 40 has a more automatic way of doing this using scikit-learn’s scalers (I haven’t tested the following code as is though):
from sklearn.preprocessing import MinMaxScaler

# build a transformation to have the transformation result in the range 0..1
scaler = MinMaxScaler(feature_range=(0, 1)) 

# apply the transformation to the target values (note that fit_transform() 
# expects a 2D tensor)
transformedTarget = scaler.fit_transform(target)

# perform training
...

# apply inverse transform
origOutput = network.forward(...)
output = scaler.inverse_transform(origOutput.data.numpy())

By the way, according to http://pytorch.org/docs/master/nn.html#torch.nn.LSTM 35 , h(t) (which is taken as the cell’s output) is a product of a sigmoid and a tanh, so in the range -1…1 .