RNN Lstmgru
RNN Lstmgru
In [ ]: # check out the source code for more detailed info about this class
??nn.LSTM
# run some data through the model and show the output sizes
y,h = lstm(X,hiddeninputs)
print(f' Input shape: {list(X.shape)}')
print(f'Hidden shape: {list(h[0].shape)}')
print(f' Cell shape: {list(h[1].shape)}')
print(f'Output shape: {list(y.shape)}')
In [ ]:
# store parameters
self.input_size = input_size
self.num_hidden = num_hidden
localhost:8888/nbconvert/html/DUDL_RNN_LSTMGRU.ipynb?download=false 1/3
10/25/23, 11:34 AM DUDL_RNN_LSTMGRU
self.num_layers = num_layers
def forward(self,x):
print(f'Input: {list(x.shape)}')
return o,hidden
lossfun = nn.MSELoss()
lossfun(yHat,y)
In [ ]:
GRU
In [ ]: # create a GRU instance
gru = nn.GRU(input_size,hidden_size,num_layers)
gru
In [ ]: ??nn.GRU
# run some data through the model and show the output sizes
y,h = gru(X,H) # No cell states in GRU!
print(f' Input shape: {list(X.shape)}')
localhost:8888/nbconvert/html/DUDL_RNN_LSTMGRU.ipynb?download=false 2/3
10/25/23, 11:34 AM DUDL_RNN_LSTMGRU
print(f'Hidden shape: {list(h.shape)}')
print(f'Output shape: {list(y.shape)}')
localhost:8888/nbconvert/html/DUDL_RNN_LSTMGRU.ipynb?download=false 3/3