Skip to content

Instantly share code, notes, and snippets.

@soumith
Created May 14, 2014 17:48
Show Gist options
  • Save soumith/faae75338c7d91a7fff2 to your computer and use it in GitHub Desktop.
Save soumith/faae75338c7d91a7fff2 to your computer and use it in GitHub Desktop.
require 'torch'
require 'nn'
torch.setdefaulttensortype('torch.FloatTensor')
-------------- Model -------------------------
branch = nn.Sequential()
branch:add(nn.Linear(4,5))
branch:add(nn.Linear(5,1))
parallel=nn.Parallel(1,1);
parallel:add(branch); -- apply to first slice
parallel:add(branch:clone('weight', 'bias')) -- apply to second slice
mlp = nn.Sequential()
mlp:add(parallel)
mlp:add(nn.Sum(1))
-------------- End of Model -------------------------
input = torch.rand(2,4)
print(mlp:forward(input))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment