Created
August 19, 2018 02:59
-
-
Save omarsar/6b9ffee2c600caf20106d08fb974136c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rnn = nn.RNNCell(3, 5) # n_input X n_neurons | |
X_batch = torch.tensor([[[0,1,2], [3,4,5], | |
[6,7,8], [9,0,1]], | |
[[9,8,7], [0,0,0], | |
[6,5,4], [3,2,1]] | |
], dtype = torch.float) # X0 and X1 | |
hx = torch.randn(4, 5) # m X n_neurons | |
output = [] | |
# for each time step | |
for i in range(2): | |
hx = rnn(X_batch[i], hx) | |
output.append(hx) | |
print(output) | |
### output | |
''' | |
[tensor([[-0.4872, 0.4388, -0.3683, -0.2402, -0.7824], | |
[-0.9869, -0.9002, -0.9990, -0.5977, -0.9543], | |
[-0.9989, -0.9978, -0.9999, -0.3553, -0.9991], | |
[-0.9998, -0.9889, -0.9749, -0.9821, -0.5408]], | |
grad_fn=<TanhBackward>), tensor([[-0.9998, -0.9983, -0.9999, -0.3426, -0.9987], | |
[ 0.2678, 0.8609, -0.3364, -0.0767, 0.4827], | |
[-0.9897, -0.9457, -0.9979, -0.2552, -0.9282], | |
[-0.6595, -0.2529, -0.8555, -0.1959, -0.2725]], | |
grad_fn=<TanhBackward>)] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment